此文章的假设是hadoop集群已经搭建好。zookeeper已经搭建完成!参考《安装zookeeper笔记》
主机名 | ip | 角色 |
---|---|---|
hadoop01 | 192.168.56.10 | NameNode ResourceManager ZK |
hadoop02 | 192.168.56.11 | DataNode NodeManager ZK |
hadoop03 | 192.168.56.12 | DataNode NodeManager ZK |
hadoop04 | 192.168.56.13 | DataNode NodeManager |
主机名 | ip | 角色 |
---|---|---|
hadoop01 | 192.168.56.10 | NameNode ResourceManager ZK |
hadoop02 | 192.168.56.11 | NameNode,DataNode NodeManager ZK journalnode |
hadoop03 | 192.168.56.12 | DataNode NodeManager ZK journalnode |
hadoop04 | 192.168.56.13 | DataNode NodeManager journalnode |
<property>
<name>fs.defaultFS</name>
<value>hdfs://mycluster</value>
</property>
<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>hadoop01:8020</value>
</property>
<property>
<name>dfs.namenode.rpc-address.mycluster.nn2</name>
<value>hadoop02:8020</value>
</property>
<property>
<name>dfs.namenode.http-address.mycluster.nn1</name>
<value>hadoop01:50070</value>
</property>
<property>
<name>dfs.namenode.http-address.mycluster.nn2</name>
<value>hadoop02:50070</value>
</property>
<!--指定JournalNode -->
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://hadoop02:8485;hadoop03:8485;hadoop04:8485/mycluster</value>
</property>
<!--指定cluster1出故障时,哪个实现类负责执行故障切换-->
<property>
<name>dfs.client.failover.proxy.provider.mycluster</name>
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
</property>
<!--SSH to the Active NameNode and kill the process-->
<property>
<name>dfs.ha.fencing.methods</name>
<value>sshfence</value>
</property>
<property>
<name>dfs.ha.fencing.ssh.private-key-files</name>
<value>/home/cluster/.ssh/id_rsa</value>
</property>
<!--the path where the JournalNode daemon will store its local state-->
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/home/cluster/journalnode/localdata</value>
</property>
sbin/start-dfs.sh之后,两个namenode都进入standby状态
命令行:
查看状态:
hdfs haadmin -getServiceState nn1
hdfs haadmin -checkHealth nn1(没有输出)
切换NameNode状态
hdfs haadmin -ns mycluster -transitionToActive nn1
hdfs haadmin -ns mycluster -transitionToStandby nn1
<property>
<name>ha.zookeeper.quorum</name>
<value>hadoop01:2181,hadoop02:2181,hadoop03:2181</value>
</property>
2181是zookeeper配置的ClientPort * 然后要在hdfs-site.xml上添加配置:
<property>
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
[cluster@hadoop01 bin]$ pwd
/home/cluster/hadoop/bin
[cluster@hadoop01 bin]$ ./hadoop jar ../share/hadoop/mapreduce/hadoop-mapreduce-examples-2.6.0.jar pi 10 100
http://segmentfault.com/a/1190000000624579
喜欢 (1)or分享 (0)