环境:centos7 + hadoop2.5.2 + jdk1.7
已经在前两篇博客中出现的步骤具体细节一笔带过,不再展示,具体可以参考ssh免密码登陆,伪分布
1) SSH免密码登陆
2) 主节点安装jdk和hadoop,并配置环境变量
3) 配置主节点hadoop配置文件
除了需要额外配置slave,其他的跟伪分布一致。
yarn-site.xml配置文件需要额为一下信息
<span style="font-size:14px;"><configuration> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> <property> <name>yarn.resourcemanager.address</name> <value>master:8032</value> </property> <property> <name>yarn.resourcemanager.scheduler.address</name> <value>master:8030</value> </property> <property> <name>yarn.resourcemanager.resource-tracker.address</name> <value>master:8031</value> </property> </configuration></span>
4) 复制拷贝上述2.3中jdk,hadoop及其配置至所有从节点
如:scp /usr/local/hadoop2.5/etc/hadoop/*[email protected]:/usr/local/hadoop2.5/etc/hadoop
5) 初始化hadoop
初始化和运行hadoop只需要在主节点进行,系统会自动登陆到从节点进行相关的操作
hdfs namenode –format 格式化HDFS文件系统
INFO common.Storage: Storage directory/usr/local/hadoop2.5/hdfs/name has been successfully formatted.
6) 运行hadoop
start-dfs.sh,start-yarn.sh 启动hadoop
7) 测试程序
hadoop jar../share/hadoop/mapreduce/hadoop-mapreduce-examples-2.5.2.jar wordcount inputoutput #运行wordcount
hadoop fs -ls output 查看运行之后产生的文件
hadoop fs -cat output/part-r-00000 查看运行结果
8) 同步文件脚本
a) vi scp.sh
b) #!/sbin/bash
<span style="font-size:14px;">#slave1 scp/usr/local/hadoop2.5/etc/hadoop/core-site.xmlroot@slave1:/usr/local/hadoop2.5/etc/hadoop scp /usr/local/hadoop2.5/etc/hadoop/hdfs-site.xmlroot@slave1:/usr/local/hadoop2.5/etc/hadoop scp/usr/local/hadoop2.5/etc/hadoop/mapred-site.xmlroot@slave1:/usr/local/hadoop2.5/etc/hadoop scp/usr/local/hadoop2.5/etc/hadoop/yarn-site.xml root@slave1:/usr/local/hadoop2.5/etc/hadoop #slave2 scp/usr/local/hadoop2.5/etc/hadoop/core-site.xmlroot@slave2:/usr/local/hadoop2.5/etc/hadoop scp/usr/local/hadoop2.5/etc/hadoop/hdfs-site.xmlroot@slave2:/usr/local/hadoop2.5/etc/hadoop scp /usr/local/hadoop2.5/etc/hadoop/mapred-site.xmlroot@slave2:/usr/local/hadoop2.5/etc/hadoop scp/usr/local/hadoop2.5/etc/hadoop/yarn-site.xmlroot@slave2:/usr/local/hadoop2.5/etc/hadoop </span>
c) 保存scp.sh
d) bash scp.sh
9) 总结
a) hadoop初始化前的所有操作,master和slave都一样。
b) 初始化hadoop和运行程序只在master上进行。
c) hadoop全分布部署中尽量不要出现localhost或者127.0.0.1,否则就是给自己挖坑。
d) 尽量用hostname,直接使用ip地址容易出错,也不利于维护,有些人说的用hostname会导致异常,纯粹是自己hostname和ip地址映射出现问题,与hostname无关。
e) 全分布与伪分布,在最简单配置的情况下,配置文件的差别一般发生在yarn-site.xml中,比伪分布需要的配置信息要更全面一些。另外,全分布需要配置slave文件。
10)异常信息及解决方案1. Q;WARN hdfs.DFSClient:DataStreamer Exception
org.apache.hadoop.ipc.RemoteException(java.io.IOException):File /user/root/input/hello.txt._COPYING_ could only be replicated to 0 nodesinstead of minReplication (=1). Thereare 0 datanode(s) running and no node(s) are excluded in this operation.
A:关闭master的防火墙
2. Q:INFO hdfs.DFSClient:Exception in createBlockOutputStreamjava.net.NoRouteToHostException: No routeto host
WARN hdfs.DFSClient: DataStreamer Exception
org.apache.hadoop.ipc.RemoteException(java.io.IOException): File/user/root/input/hello.txt._COPYING_ could only be replicated to 0 nodesinstead of minReplication (=1). Thereare 2 datanode(s) running and 2 node(s) are excluded in this operation.
A:关闭所有slave的防火墙
3. Q:INFO ipc.Client: Retryingconnect to server: 0.0.0.0/0.0.0.0:8032.
A:yarn.xml中添加如下:
<property>
<name>yarn.resourcemanager.address</name>
<value>master:8032</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>master:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>master:8031</value>
</property>
4. Q:运行到running job时卡住不动了,INFO mapreduce.Job: Running job: job_1434601129948_0002
A:running job时不动了,也就是说nodemanager出现问题了额,jsp发现nodemanager启动正常,但是监控slave的nodemanager日志时发现一直在连接8031端口,始终连接不上,几分钟之后nodemanager就挂了。信息如下:
INFO org.apache.hadoop.ipc.Client: Retryingconnect to server: localhost/127.0.0.1:8031. Already tried 8 time(s); retrypolicy is
RetryUpToMaximumCountWithFixedSleep(maxRetries=10,sleepTime=1000 MILLISECONDS)
需要连接的8031端口应该时master的,由于master的配置文件中用的就是localhost,同步到slave中之后就有问题了,所以尽量不要在hadoop中使用诸如localhost或者127.0.0.1.