1、规划集群
hadoop102 | hadoop103 | hadoop104 |
---|---|---|
NameNode | NameNode | "" |
JournalNode | JournalNode | JournalNode |
DataNode | DataNode | DataNode |
ZK | ZK | ZK |
2、关闭所有HDFS服务
[yinggu@hadoop102 hadoop-2.7.2]$ sbin/stop-dfs.sh
3、增加配置参数
core-site.xml
<!-- 自动故障转移HA zookeeper -->
<property>
<name>ha.zookeeper.quorum</name>
<value>hadoop102:2181,hadoop103:2181,hadoop104:2181</value>
</property>
hdfs-site.xml
<!-- 自动故障转移HA zookeeper ,复活 -->
<property>
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
分发hadoop
[yinggu@hadoop102 HA]$ scp -r hadoop-2.7.2/ yinggu@hadoop103:/opt/module/HA/
[yinggu@hadoop102 HA]$ scp -r hadoop-2.7.2/ yinggu@hadoop104:/opt/module/HA/
4、zookeeper
(1)分别启动hadoop[102-104] 节点上的zookeeper
[yinggu@hadoop102 zookeeper-3.4.10]$ bin/zkServer.sh start
[yinggu@hadoop103 zookeeper-3.4.10]$ bin/zkServer.sh start
[yinggu@hadoop104 zookeeper-3.4.10]$ bin/zkServer.sh start
(2)分别查看zookeeper的运行状态
hadoop102
[yinggu@hadoop102 zookeeper-3.4.10]$ bin/zkServer.sh status
JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower
hadoop103
[yinggu@hadoop103 zookeeper-3.4.10]$ bin/zkServer.sh status
JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: leader
hadoop104
[yinggu@hadoop104 zookeeper-3.4.10]$ bin/zkServer.sh status
JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower
5、初始化zookeeper中的HA状态
[yinggu@hadoop102 hadoop-2.7.2]$ bin/hdfs zkfc -formatZK
尖叫提示:只需要在第一次部署时初始化
6、启动HDFS
方式一
[yinggu@hadoop102 hadoop-2.7.2]$ sbin/start-dfs.sh
注意:如果没有使用start-dfs.sh命令启动服务,每个服务需要单独启动
方式二
[yinggu@hadoop102 hadoop-2.7.2]$ sbin/hadoop-daemon.sh start namenode
[yinggu@hadoop103 hadoop-2.7.2]$ sbin/hadoop-daemon.sh start namenode
[yinggu@hadoop102 hadoop-2.7.2]$ sbin/hadoop-daemons.sh start datanode
[yinggu@hadoop103 hadoop-2.7.2]$ sbin/hadoop-daemons.sh start datanode
[yinggu@hadoop104 hadoop-2.7.2]$ sbin/hadoop-daemons.sh start datanode
[yinggu@hadoop102 hadoop-2.7.2]$ sbin/hadoop-daemon.sh start journalnode
[yinggu@hadoop103 hadoop-2.7.2]$ sbin/hadoop-daemon.sh start journalnode
[yinggu@hadoop104 hadoop-2.7.2]$ sbin/hadoop-daemon.sh start journalnode
[yinggu@hadoop102 hadoop-2.7.2]$ sbin/hadoop-daemin.sh start zkfc
[yinggu@hadoop103 hadoop-2.7.2]$ sbin/hadoop-daemin.sh start zkfc
7、测试
[yinggu@hadoop102 hadoop-2.7.2]$ sbin/hadoop-daemon.sh stop namenode