
自己实际添加节点过程:
1. 先在slave上配置好环境,包括ssh,jdk,相关config,lib,bin等的拷贝;
2. 将新的datanode的host加到集群namenode及其他datanode中去;
3. 将新的datanode的ip加到master的conf/slaves中;
4. 重启cluster,在cluster中看到新的datanode节点;
5. 运行bin/start-balancer.sh,这个会很耗时间
备注:
1. 如果不balance,那么cluster会把新的数据都存放在新的node上,这样会降低mr的工作效率;
2. 也可调用bin/start-balancer.sh 命令执行,也可加参数 -threshold 5
threshold 是平衡阈值,默认是10%,值越低各节点越平衡,但消耗时间也更长。
3. balancer也可以在有mr job的cluster上运行,默认dfs.balance.bandwidthPerSec很低,为1M/s。在没有mr job时,可以提高该设置加快负载均衡时间。
其他备注:
1. 必须确保slave的firewall已关闭
2. 确保新的slave的ip已经添加到master及其他slaves的/etc/hosts中,反之也要将master及其他slave的ip添加到新的slave的/etc/hosts中
mapper及reducer个数
url地址: http://wiki.apache.org/hadoop/HowManyMapsAndReduces
HowManyMapsAndReduces
Partitioning your job into maps and reduces
Picking the appropriate size for the tasks for your job can radically change the performance of Hadoop. Increasing the number of tasks increases the framework overhead, but increases load balancing and lowers the cost of failures. At one extreme is the 1 map/1 reduce case where nothing is distributed. The other extreme is to have 1,000,000 maps/ 1,000,000 reduces where the framework runs out of resources for the overhead.
Number of Maps
The number of maps is usually driven by the number of DFS blocks in the input files. Although that causes people to adjust their DFS block size to adjust the number of maps. The right level of parallelism for maps seems to be around 10-100 maps/node, although we have taken it up to 300 or so for very cpu-light map tasks. Task setup takes awhile, so it is best if the maps take at least a minute to execute.
Actually controlling the number of maps is subtle. The mapred.map.tasks parameter is just a hint to the InputFormat for the number of maps. The default InputFormat behavior is to split the total number of bytes into the right number of fragments. However, in the default case the DFS block size of the input files is treated as an upper bound for input splits. A lower bound on the split size can be set via mapred.min.split.size. Thus, if you expect 10TB of input data and have 128MB DFS blocks, you'll end up with 82k maps, unless your mapred.map.tasks is even larger. Ultimately the [WWW] InputFormat determines the number of maps.
The number of map tasks can also be increased manually using the JobConf's conf.setNumMapTasks(int num). This can be used to increase the number of map tasks, but will not set the number below that which Hadoop determines via splitting the input data.
Number of Reduces
The right number of reduces seems to be 0.95 or 1.75 * (nodes * mapred.tasktracker.tasks.maximum). At 0.95 all of the reduces can launch immediately and start transfering map outputs as the maps finish. At 1.75 the faster nodes will finish their first round of reduces and launch a second round of reduces doing a much better job of load balancing.
Currently the number of reduces is limited to roughly 1000 by the buffer size for the output files (io.buffer.size * 2 * numReduces <<heapSize). This will be fixed at some point, but until it is it provides a pretty firm upper bound.
The number of reduces also controls the number of output files in the output directory, but usually that is not important because the next map/reduce step will split them into even smaller splits for the maps.
The number of reduce tasks can also be increased in the same way as the map tasks, via JobConf's conf.setNumReduceTasks(int num).
自己的理解:
mapper个数的设置:跟input file 有关系,也跟filesplits有关系,filesplits的上线为dfs.block.size,下线可以通过mapred.min.split.size设置,最后还是由InputFormat决定。
较好的建议:
The right number of reduces seems to be 0.95 or 1.75 multiplied by (<no. of nodes>* mapred.tasktracker.reduce.tasks.maximum).increasing the number of reduces increases the framework overhead, but increases load balancing and lowers the cost of failures.
<property>
<name>mapred.tasktracker.reduce.tasks.maximum</name>
<value>2</value>
<description>The maximum number of reduce tasks that will be run
simultaneously by a task tracker.
</description>
</property>
单个node新加硬盘
1.修改需要新加硬盘的node的dfs.data.dir,用逗号分隔新、旧文件目录
2.重启dfs
同步hadoop 代码
hadoop-env.sh
# host:path where hadoop code should be rsync'd from. Unset by default.
# export HADOOP_MASTER=master:/home/$USER/src/hadoop
用命令合并HDFS小文件
hadoop fs -getmerge <src><dest>
重启reduce job方法
Introduced recovery of jobs when JobTracker restarts. This facility is off by default.
Introduced config parameters "mapred.jobtracker.restart.recover", "mapred.jobtracker.job.history.block.size", and "mapred.jobtracker.job.history.buffer.size".
还未验证过。
IO写 *** 作出现问题
0-1246359584298, infoPort=50075, ipcPort=50020):Got exception while serving blk_-5911099437886836280_1292 to /172.16.100.165:
java.net.SocketTimeoutException: 480000 millis timeout while waiting for channel to be ready for write. ch : java.nio.channels.SocketChannel[connected local=/
172.16.100.165:50010 remote=/172.16.100.165:50930]
at org.apache.hadoop.net.SocketIOWithTimeout.waitForIO(SocketIOWithTimeout.java:185)
at org.apache.hadoop.net.SocketOutputStream.waitForWritable(SocketOutputStream.java:159)
at org.apache.hadoop.net.SocketOutputStream.transferToFully(SocketOutputStream.java:198)
at org.apache.hadoop.hdfs.server.datanode.BlockSender.sendChunks(BlockSender.java:293)
at org.apache.hadoop.hdfs.server.datanode.BlockSender.sendBlock(BlockSender.java:387)
at org.apache.hadoop.hdfs.server.datanode.DataXceiver.readBlock(DataXceiver.java:179)
at org.apache.hadoop.hdfs.server.datanode.DataXceiver.run(DataXceiver.java:94)
at java.lang.Thread.run(Thread.java:619)
It seems there are many reasons that it can timeout, the example given in
HADOOP-3831 is a slow reading client.
解决办法:在hadoop-site.xml中设置dfs.datanode.socket.write.timeout=0试试;
My understanding is that this issue should be fixed in Hadoop 0.19.1 so that
we should leave the standard timeout. However until then this can help
resolve issues like the one you're seeing.
HDFS退服节点的方法
目前版本的dfsadmin的帮助信息是没写清楚的,已经file了一个bug了,正确的方法如下:
1. 将 dfs.hosts 置为当前的 slaves,文件名用完整路径,注意,列表中的节点主机名要用大名,即 uname -n 可以得到的那个。
2. 将 slaves 中要被退服的节点的全名列表放在另一个文件里,如 slaves.ex,使用 dfs.host.exclude 参数指向这个文件的完整路径
3. 运行命令 bin/hadoop dfsadmin -refreshNodes
4. web界面或 bin/hadoop dfsadmin -report 可以看到退服节点的状态是 Decomission in progress,直到需要复制的数据复制完成为止
5. 完成之后,从 slaves 里(指 dfs.hosts 指向的文件)去掉已经退服的节点
附带说一下 -refreshNodes 命令的另外三种用途:
2. 添加允许的节点到列表中(添加主机名到 dfs.hosts 里来)
3. 直接去掉节点,不做数据副本备份(在 dfs.hosts 里去掉主机名)
4. 退服的逆 *** 作——停止 exclude 里面和 dfs.hosts 里面都有的,正在进行 decomission 的节点的退服,也就是把 Decomission in progress 的节点重新变为 Normal (在 web 界面叫 in service)
Hadoop添加节点的方法
自己实际添加节点过程:
1. 先在slave上配置好环境,包括ssh,jdk,相关config,lib,bin等的拷贝;
2. 将新的datanode的host加到集群namenode及其他datanode中去;
3. 将新的datanode的ip加到master的conf/slaves中;
4. 重启cluster,在cluster中看到新的datanode节点;
5. 运行bin/start-balancer.sh,这个会很耗时间
备注:
1. 如果不balance,那么cluster会把新的数据都存放在新的node上,这样会降低mr的工作效率;
2. 也可调用bin/start-balancer.sh 命令执行,也可加参数 -threshold 5
threshold 是平衡阈值,默认是10%,值越低各节点越平衡,但消耗时间也更长。
3. balancer也可以在有mr job的cluster上运行,默认dfs.balance.bandwidthPerSec很低,为1M/s。在没有mr job时,可以提高该设置加快负载均衡时间。
其他备注:
1. 必须确保slave的firewall已关闭
2. 确保新的slave的ip已经添加到master及其他slaves的/etc/hosts中,反之也要将master及其他slave的ip添加到新的slave的/etc/hosts中
客户要求要回收一批hadoop集群的一批服务器,万幸namenode和resourcemanager服务没有安装在这批服务器上,但不巧的是3个journalnode节点都在这批服务器上,所以暂时先增加3个journalnode节点,等到回收服务器的时候,再把原来的journalnode节点下线,记录一下 *** 作
1.修改hdfs-site.xml配置文件
原配置为:
修改为:
2.分发hdfs-site.xml文件到各节点
3.将原journalnode上的edits文件scp到新的journalnode节点
从hdfs-site.xml文件中的dfs.journalnode.edits.dir配置项得到edits文件存储路径,scp到新节点的相同路径,注意权限和属主要相同,可以用scp -rp来复制
4.新journalnode节点启动journalnode进程
jps检查是否启动成功,如果失败就去看$HADOOP_HOME/logs下的journalnode相关的日志,讲道理应该没什么问题
5.把standby(nn2)节点的namenode重启一下
6.切换standby节点为active
7.重启standby(nn1)节点的namenode
*** 作同5,完成后web界面应该可以看到NameNode Journal Status的journalnode已扩展完成
1、启动hadoop所有进程start-all.sh等价于start-dfs.sh + start-yarn.sh
但是一般不推荐使用start-all.sh(因为开源框架中内部命令启动有很多问题)。
2、单进程启动。
sbin/start-dfs.sh
---------------
sbin/hadoop-daemons.sh --config .. --hostname .. start namenode ...
sbin/hadoop-daemons.sh --config .. --hostname .. start datanode ...
sbin/hadoop-daemons.sh --config .. --hostname .. start sescondarynamenode ...
sbin/hadoop-daemons.sh --config .. --hostname .. start zkfc ... //
sbin/start-yarn.sh
--------------
libexec/yarn-config.sh
sbin/yarn-daemon.sh --config $YARN_CONF_DIR start resourcemanager
sbin/yarn-daemons.sh --config $YARN_CONF_DIR start nodemanager
3、常用命令
1、查看指定目录下内容
hdfs dfs –ls [文件目录]
hdfs dfs -ls -R / //显式目录结构
eg: hdfs dfs –ls /user/wangkai.pt
2、打开某个已存在文件
hdfs dfs –cat [file_path]
eg:hdfs dfs -cat /user/wangkai.pt/data.txt
3、将本地文件存储至hadoop
hdfs dfs –put [本地地址] [hadoop目录]
hdfs dfs –put /home/t/file.txt /user/t
4、将本地文件夹存储至hadoop
hdfs dfs –put [本地目录] [hadoop目录]
hdfs dfs –put /home/t/dir_name /user/t
(dir_name是文件夹名)
5、将hadoop上某个文件down至本地已有目录下
hadoop dfs -get [文件目录] [本地目录]
hadoop dfs –get /user/t/ok.txt /home/t
6、删除hadoop上指定文件
hdfs dfs –rm [文件地址]
hdfs dfs –rm /user/t/ok.txt
7、删除hadoop上指定文件夹(包含子目录等)
hdfs dfs –rm [目录地址]
hdfs dfs –rmr /user/t
8、在hadoop指定目录内创建新目录
hdfs dfs –mkdir /user/t
hdfs dfs -mkdir - p /user/centos/hadoop
9、在hadoop指定目录下新建一个空文件
使用touchz命令:
hdfs dfs -touchz /user/new.txt
10、将hadoop上某个文件重命名
使用mv命令:
hdfs dfs –mv /user/test.txt /user/ok.txt (将test.txt重命名为ok.txt)
11、将hadoop指定目录下所有内容保存为一个文件,同时down至本地
hdfs dfs –getmerge /user /home/t
12、将正在运行的hadoop作业kill掉
hadoop job –kill [job-id]
13.查看帮助
hdfs dfs -help
4、安全模式
(1)退出安全模式
NameNode在启动时会自动进入安全模式。安全模式是NameNode的一种状态,在这个阶段,文件系统不允许有任何修改。
系统显示Name node in safe mode,说明系统正处于安全模式,这时只需要等待十几秒即可,也可通过下面的命令退出安全模式:/usr/local/hadoop$bin/hadoop dfsadmin -safemode leave
(2) 进入安全模式
在必要情况下,可以通过以下命令把HDFS置于安全模式:/usr/local/hadoop$bin/hadoop dfsadmin -safemode enter
5、节点添加
添加一个新的DataNode节点,先在新加节点上安装好Hadoop,要和NameNode使用相同的配置(可以直接从NameNode复制),修改HADOOPHOME/conf/master文件,加入NameNode主机名。然后在NameNode节点上修改HADOOPHOME/conf/master文件,加入NameNode主机名。然后在NameNode节点上修改HADOOP_HOME/conf/slaves文件,加入新节点名,再建立新加节点无密码的SSH连接,运行启动命令为:/usr/local/hadoop$bin/start-all.sh
6、负载均衡
HDFS的数据在各个DataNode中的分布可能很不均匀,尤其是在DataNode节点出现故障或新增DataNode节点时。新增数据块时NameNode对DataNode节点的选择策略也有可能导致数据块分布不均匀。用户可以使用命令重新平衡DataNode上的数据块的分布:/usr/local/hadoop$bin/start-balancer.sh
7、补充
1.对hdfs *** 作的命令格式是hdfs dfs
1.1 -ls 表示对hdfs下一级目录的查看
1.2 -lsr 表示对hdfs目录的递归查看
1.3 -mkdir 创建目录
1.4 -put 从Linux上传文件到hdfs
1.5 -get 从hdfs下载文件到linux
1.6 -text 查看文件内容
1.7 -rm 表示删除文件
1.7 -rmr 表示递归删除文件
2.hdfs在对数据存储进行block划分时,如果文件大小超过block,那么按照block大小进行划分;不如block size的,划分为一个块,是实际数据大小。
*****PermissionDenyException 权限不足**********
hadoop常用命令:
hdfs dfs 查看Hadoop HDFS支持的所有命令
hdfs dfs –ls 列出目录及文件信息
hdfs dfs –lsr 循环列出目录、子目录及文件信息
hdfs dfs –put test.txt /user/sunlightcs 将本地文件系统的test.txt复制到HDFS文件系统的/user/sunlightcs目录下
hdfs dfs –get /user/sunlightcs/test.txt . 将HDFS中的test.txt复制到本地文件系统中,与-put命令相反
hdfs dfs –cat /user/sunlightcs/test.txt 查看HDFS文件系统里test.txt的内容
hdfs dfs –tail /user/sunlightcs/test.txt 查看最后1KB的内容
hdfs dfs –rm /user/sunlightcs/test.txt 从HDFS文件系统删除test.txt文件,rm命令也可以删除空目录
hdfs dfs –rmr /user/sunlightcs 删除/user/sunlightcs目录以及所有子目录
hdfs dfs –copyFromLocal test.txt /user/sunlightcs/test.txt 从本地文件系统复制文件到HDFS文件系统,等同于put命令
hdfs dfs –copyToLocal /user/sunlightcs/test.txt test.txt 从HDFS文件系统复制文件到本地文件系统,等同于get命令
hdfs dfs –chgrp [-R] /user/sunlightcs 修改HDFS系统中/user/sunlightcs目录所属群组,选项-R递归执行,跟linux命令一样
hdfs dfs –chown [-R] /user/sunlightcs 修改HDFS系统中/user/sunlightcs目录拥有者,选项-R递归执行
hdfs dfs –chmod [-R] MODE /user/sunlightcs 修改HDFS系统中/user/sunlightcs目录权限,MODE可以为相应权限的3位数或+/-{rwx},选项-R递归执行
hdfs dfs –count [-q] PATH 查看PATH目录下,子目录数、文件数、文件大小、文件名/目录名
hdfs dfs –cp SRC [SRC …] DST 将文件从SRC复制到DST,如果指定了多个SRC,则DST必须为一个目录
hdfs dfs –du PATH 显示该目录中每个文件或目录的大小
hdfs dfs –dus PATH 类似于du,PATH为目录时,会显示该目录的总大小
hdfs dfs –expunge 清空回收站,文件被删除时,它首先会移到临时目录.Trash/中,当超过延迟时间之后,文件才会被永久删除
hdfs dfs –getmerge SRC [SRC …] LOCALDST [addnl] 获取由SRC指定的所有文件,将它们合并为单个文件,并写入本地文件系统中的LOCALDST,选项addnl将在每个文件的末尾处加上一个换行符
hdfs dfs –touchz PATH 创建长度为0的空文件
hdfs dfs –test –[ezd] PATH 对PATH进行如下类型的检查: -e PATH是否存在,如果PATH存在,返回0,否则返回1 -z 文件是否为空,如果长度为0,返回0,否则返回1 -d 是否为目录,如果PATH为目录,返回0,否则返回1
hdfs dfs –text PATH 显示文件的内容,当文件为文本文件时,等同于cat,文件为压缩格式(gzip以及hadoop的二进制序列文件格式)时,会先解压缩hdfs dfs –help ls 查看某个[ls]命令的帮助文档
本文转自 https://www.cnblogs.com/LHWorldBlog/p/8514994.html
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)