HA
ZK NN DN RM NM JN ZKFC
master 1 1 1 1 1
node1 1 1 1 1 1 1 1
node2 1 1 1 1
1.免密钥
在两个主节点生成密钥文件
ssh-keygen -t rsa
ssh-copy-id ip
master-->master,node1,node2
node1-->master,node1,node2
2.停止HDFS集群
stop-dfs.sh
3.修改hadoop配置文件
core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://cluster</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/usr/local/soft/hadoop-2.7.6/tmp</value>
</property>
<property>
<name>fs.trash.interval</name>
<value>1440</value>
</property>
<property>
<name>ha.zookeeper.quorum</name>
<value>master:2181,node1:2181,node2:2181</value>
</property>
</configuration>
hdfs-site.xml
<!-- //以下为HDFS HA的配置// -->
<!-- 指定hdfs的nameservices名称为mycluster -->
<property>
<name>dfs.nameservices</name>
<value>cluster</value>
</property>
<!-- 指定cluster的两个namenode的名称分别为nn1,nn2 -->
<property>
<name>dfs.ha.namenodes.cluster</name>
<value>nn1,nn2</value>
</property>
<!-- 配置nn1,nn2的rpc通信端口 -->
<property>
<name>dfs.namenode.rpc-address.cluster.nn1</name>
<value>master:8020</value>
</property>
<property>
<name>dfs.namenode.rpc-address.cluster.nn2</name>
<value>node1:8020</value>
</property>
<!-- 配置nn1,nn2的http通信端口 -->
<property>
<name>dfs.namenode.http-address.cluster.nn1</name>
<value>master:50070</value>
</property>
<property>
<name>dfs.namenode.http-address.cluster.nn2</name>
<value>node1:50070</value>
</property>
<!-- 指定namenode元数据存储在journalnode中的路径 -->
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://master:8485;node1:8485;node2:8485/cluster</value>
</property>
<!-- 指定journalnode日志文件存储的路径 -->
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/usr/local/soft/hadoop-2.7.6/data/journal</value>
</property>
<!-- 指定HDFS客户端连接active namenode的java类 -->
<property>
<name>dfs.client.failover.proxy.provider.cluster</name>
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
</property>
<!-- 配置隔离机制为ssh -->
<property>
<name>dfs.ha.fencing.methods</name>
<value>
sshfence
shell(/bin/true)
</value>
</property>
<!-- 指定秘钥的位置 -->
<property>
<name>dfs.ha.fencing.ssh.private-key-files</name>
<value>/root/.ssh/id_rsa</value>
</property>
<!-- 开启自动故障转移 -->
<property>
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
4.删除hadoop数据存储目录下的文件 每个节点都需要删除
rm -rf /usr/local/soft/hadoop-2.7.6/tmp
5.将hadoop目录下的所有配置文件同步到其它节点
cd /usr/local/soft/hadoop-2.7.6/etc/hadoop
scp ./* node1:`pwd`
scp ./* node2:`pwd`
6.启动zookeeper,三台都需要启动(若已启动则查看状态)
#启动zookeeper
zkServer.sh start
#查看状态
zkServer.sh status
7.启动JN(journalnode),三台都需启动
/usr/local/soft/hadoop-2.7.6/sbin/hadoop-daemon.sh start journalnode
8.格式化,在一台NN上执行(这里选择master)
#格式化
hdfs namenode -format
#启动当前NN
hadoop-daemon.sh start namenode
9.执行同步,没有格式化的NN上执行,在另外一台namenode上面执行(这里选择node1)
/usr/local/soft/hadoop-2.7.6/bin/hdfs namenode -bootstrapStandby
10.格式化ZK(这里再master上执行)
注意!一定要先把zk集群正常启动起来
/usr/local/soft/hadoop-2.7.6/bin/hdfs zkfc -formatZK
11.启动hdfs集群(在master上执行)
start-dfs.sh