1.现在的虚拟机集合
192.168.137.2 node1
192.168.137.3 node2
192.168.137.4 node3
192.168.137.5 node4
2.配置ssh免密码登录
在node1,2,3,4上都运行下面两行:
- ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
- cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
将node1的id_dsa.pub 追加到其他node的authorized_keys中
- scp id_dsa.pub root@node2:~
- cat id_dsa.pub >> ~/.ssh/authorized_keys
![](https://img-blog.csdn.net/20170115224011249?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZ2FvMTQ0MDE1NjA1MQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
3.下载hadoop
下载hadoop-aboutyun-Linux64-2.5.2-.tar.gz到/root目录。
注意官网没有64位的bin版,需要自己编译。我是在网上找的一个编译好的。
1)解压
tar -zxvf hadoop-aboutyun-Linux64-2.5.2-.tar.gz
2)建立软链
ln -sf /root/hadoop-2.5.2 /home/hadoop-2.5.2
3)修改hadoop-env.sh
进入 /home/hadoop-2.5.2/etc/hadoop/,修改hadoop-env.sh
JAVA_HOME=/opt/java/jdk1.8.0_111
4)修改hdfs-site.xml文件
- <configuration>
- <property>
- <name>dfs.nameservices</name>
- <value>mycluster</value>
- </property>
- <property>
- <name>dfs.ha.namenodes.mycluster</name>
- <value>nn1,nn2</value>
- </property>
- <property>
- <name>dfs.namenode.rpc-address.mycluster.nn1</name>
- <value>node1:8020</value>
- </property>
- <property>
- <name>dfs.namenode.rpc-address.mycluster.nn2</name>
- <value>node2:8020</value>
- </property>
- <property>
- <name>dfs.namenode.http-address.mycluster.nn1</name>
- <value>node1:50070</value>
- </property>
- <property>
- <name>dfs.namenode.http-address.mycluster.nn2</name>
- <value>node2:50070</value>
- </property>
- <property>
- <name>dfs.namenode.shared.edits.dir</name>
- <value>qjournal://node2:8485;node3:8485;node4:8485/mycluster</value>
- </property>
- <property>
- <name>dfs.client.failover.proxy.provider.mycluster</name>
- <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
- </property>
- <property>
- <name>dfs.ha.fencing.methods</name>
- <value>sshfence</value>
- </property>
-
-
- <property>
- <name>dfs.ha.fencing.ssh.private-key-files</name>
- <value>/root/.ssh/id_dsa</value>
- </property>
- <property>
- <name>dfs.journalnode.edits.dir</name>
- <value>/opt/jn/data</value>
- </property>
- <property>
- <name>dfs.ha.automatic-failover.enabled</name>
- <value>true</value>
- </property>
-
- </configuration>
5)配置core-site.xml
- <configuration>
- <property>
- <name>fs.defaultFS</name>
- <value>hdfs://mycluster</value>
- </property>
- <property>
- <name>ha.zookeeper.quorum</name>
- <value>node1:2181,node2:2181,node3:2181</value>
- </property>
-
- <property>
- <name>hadoop.tmp.dir</name>
- <value>/opt/hadoop2</value>
- </property>
-
- </configuration>
6)修改slaves
slaves文件中加入
node2
node3
node4
7) 将Hadoop拷贝到其他节点上
scp hadoop-aboutyun-Linux64-2.5.2-.tar.gz root@node2:~/
scp hadoop-aboutyun-Linux64-2.5.2-.tar.gz root@node3:~/
scp hadoop-aboutyun-Linux64-2.5.2-.tar.gz root@node4:~/
在各自节点上解压,并建立软链
进入 /home/hadoop-2.5.2/etc/hadoop/
将下面的配置文件全部拷贝到其他节点
scp ./* root@node2:/home/hadoop-2.5.2/etc/hadoop/
scp ./* root@node3:/home/hadoop-2.5.2/etc/hadoop/
scp ./* root@node4:/home/hadoop-2.5.2/etc/hadoop/
4.下载zookeeper
1)下载zookeeper,解压到/root/
tar -zxvf zookeeper-3.4.6.tar.gz
2)建立软链
ln -sf /root/zookeeper-3.4.6 /home/zookeeper
3)配置zoo.cfg
复制得到zoo.cfg
cp zoo_sample.cfg zoo.cfg
修改zoo.cfg:
将 dataDir=/opt/zookeeper
末尾加上
server.1=node1:2888:3888
server.2=node2:2888:3888
server.3=node3:2888:3888
4)myid
建立目录
mkdir /opt/zookeeper
这个目录下建立文件
vi myid
node1里面写1
把这个目录拷贝到node2和node3
scp -r zookeeper/ root@node2:/opt/
scp -r zookeeper/ root@node3:/opt/
把node2里面myid写2,node3里面写3
5)配置zookeeper环境变量
在 /etc/profile 下面加上
export PATH=$PATH:/home/zookeeper/bin
保存,运行source /etc/profile
将配置文件拷贝到其他两个node
scp /etc/profile root@node2:/etc/
scp /etc/profile root@node3:/etc/
各自运行source /etc/profile
6)启动
关闭防火墙
service iptables stop
启动
zkServer.sh start
5.部署
1)启动node2,3,4的journalnode
进入 /home/hadoop-2.5.2/sbin/ 下
运行
./hadoop-daemon.sh start journalnode
2)format
进入/home/hadoop-2.5.2/bin/
执行 ./hdfs namenode -format
报错: No Route to Host from node1/192.168.137.2 to node2:8485 failed on socket timeout exception:
java.net.NoRouteToHostException: 没有到主机的路由; For more detail
原因是没有关闭防火墙
systemctl stop firewalld.service
可以进入到
/home/hadoop-2.5.2/logs/
下查看日志 tail -n50 hadoop-root-journalnode-node1.log
3)namenode
启动node1的namenode
进入目录 /home/hadoop-2.5.2/sbin/
执行 ./hadoop-daemon.sh start namenode
拷贝元数据到node2
node2进入目录 /home/hadoop-2.5.2/bin/
执行 ./hdfs namenode -bootstrapStandby
4)关闭所有组件
node1进入目录 /home/hadoop-2.5.2/sbin/
执行 ./stop-dfs.sh
5)formatZK
执行 ./hdfs zkfc -formatZK
6)全部启动
执行 ./start-dfs.sh ,全部启动
7)查看
在宿主机的hosts文件里加上
192.168.137.2 node1
192.168.137.3 node2
192.168.137.4 node3
192.168.137.5 node4
通过浏览器输入 http://node1:50070/ 或者http://node2:50070/即可访问