Hadoop HA高可用配置

来源:互联网 发布:网络名誉侵权管辖 编辑:程序博客网 时间:2024/05/02 01:16

 【注:文中配置未实际验证】 



 

 

一) 配置:

修改hdfs-site.xml

1. dfs.nameservices - the logical name for this new nameservice

Note: If you are also using HDFS Federation, this configuration setting should also include the list of other nameservices, HA or otherwise, as a comma-separated list.

<property>  <name>dfs.nameservices</name>  <value>mycluster</value></property>

 

2. dfs.ha.namenodes.[nameservice ID] - unique identifiers for each NameNode in the nameservice

<property>  <name>dfs.ha.namenodes.mycluster</name>  <value>nn1,nn2</value></property>

 

3. dfs.namenode.rpc-address.[nameservice ID].[name node ID] - the fully-qualified RPC address for each NameNode to listen on

<property>  <name>dfs.namenode.rpc-address.mycluster.nn1</name>  <value>machine1.example.com:8020</value></property><property>  <name>dfs.namenode.rpc-address.mycluster.nn2</name>  <value>machine2.example.com:8020</value></property>

 或者使用http地址:

<property>  <name>dfs.namenode.http-address.mycluster.nn1</name>  <value>machine1.example.com:50070</value></property><property>  <name>dfs.namenode.http-address.mycluster.nn2</name>  <value>machine2.example.com:50070</value></property>

 

4. dfs.namenode.shared.edits.dir - the URI which identifies the group of JNs where the NameNodes will write/read edits

<property>  <name>dfs.namenode.shared.edits.dir</name>  <value>qjournal://node1.example.com:8485;node2.example.com:8485;node3.example.com:8485/mycluster</value></property>

 

5. dfs.client.failover.proxy.provider.[nameservice ID] - the Java class that HDFS clients use to contact the Active NameNode

<property>  <name>dfs.client.failover.proxy.provider.mycluster</name>  <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value></property>

 

6. dfs.ha.fencing.methods - a list of scripts or Java classes which will be used to fence the Active NameNode during a failover

有两种可选方案:

sshfence - 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/exampleuser/.ssh/id_rsa</value></property>

或 

shell - run an arbitrary shell command to fence the Active NameNode

<property>  <name>dfs.ha.fencing.methods</name>  <value>shell(/path/to/my/script.sh arg1 arg2 ...)</value></property>

 

7. fs.defaultFS - the default path prefix used by the Hadoop FS client when none is given

<property>  <name>fs.defaultFS</name>  <value>hdfs://mycluster</value></property>

 

8.dfs.journalnode.edits.dir - the path where the JournalNode daemon will store its local state 

<property>  <name>dfs.journalnode.edits.dir</name>  <value>/path/to/journal/node/local/data</value></property>

 

 二)、部署

上述配置调整完毕后,我们就可以启动journalNodes守护进程,默认的"sbin/start-dfs.sh"脚本会根据"dfs.namenode.shared.edits.dir"配置,在相应的Datanode上启动journalNodes。当然我们可以使用::"bin/hdfs start journalnode"分别在相应的机器上启动。

一旦JournalNodes启动成功,它们将会从Namenode上同步metadata。

1、如果你的HDFS集群是新建的,那么需要在每个Namenode上执行"hdfs namenode -format"指令。

2、如果你的namenodes已经format了,或者是将non-ha转换成ha架构,你应该在将其中一个namenode上的metadata复制到另一台上(dfs.namenode.name.dir目录下的数据),然后在那个没有format的新加入的namenode上执行"hdfs namenode -bootstrapStandby"。运行这个指令需要确保JournalNodes中持有足够多的edits。

3、如果你将一个non-ha的Namenode(比如backup,其已经formated)切换成HA,你需要首先运行"hdfs -initializeSharedEdits",这个指令将本地Namenode中的edits初始化Journalnodes。

 

此后,你就可以启动HA Namenodes。可以通过配置指定的HTTP地址(dfs.namenode.https-address)来查看各个Namenode的状态,Active or Standby。

 

三)、管理员指令 手动切换主备namenode

HA集群启动后,我们可以通过一些指令来管理HDFS集群。“bin/hdfs haadmin -DFSHAAdmin”指令,其可选参数:

1、-transitionToActive <namenode id>与-transitionToStandbyl <namenode id>:将指定的namenode ID切换为Active或者standby。这个指令并不会触发“fencing method”,所以不常用,我们通常使用"hdfs haadmin -failover"来切换Namenode状态。

2、-failover [--forcefence] [--foreactive] <serviceId-fist> <serviceId-second>:在两个Namenode之间failover。这个指令会触发将first节点failover到second节点。如果first处于standby,那么只是简单的将second提升为Active。如果first为Active,那么将会友好的将其切换为standby,如果失败,那么fencing methods将会触发直到成功,此后second将会提升为Active。如果fencing method失败,那么second将不会被提升为Active。

例如:"hdfs haadmin -DFSHAAdmin -failover nn1 nn2"

3、-getServiceState <serviceId>:获取serviceId的状态,Active还是Standby。链接到指定的namenode上,并获取其当前的状态,打印出“standby”或者“active”。我可以在crontab中使用此命令,用来监测各个Namenode的状况。

4、-checkHealth <serviceId>:检测指定的namenode的健康状况。

 

四 自动Failover  失败情况下自动切换主备namenode

1. hdfs-site.xml

<property>      <name>dfs.ha.automatic-failover.enabled</name>      <value>true</value>  </property>  

 2. core-site.xml

<property>   <name>ha.zookeeper.quorum</name>   <value>zk1.example.com:2181,zk2.example.com:2181,zk3.example.com:2181</value> </property>

 

3. 初始化HA状态

上述准备工作结束后,我们还需要在zookeeper中初始化HA的状态,通过执行“hdfs zkfc -formatZK”,此命令将会在zookeeker中创建一个znode,用来保存HA或failover的数据。

 

4. 启动集群

可以使用"start-dfs.sh"这个便捷的指令,它启动了hdfs所需要的所有守护进程,当然包括ZKFC。也可以使用"hadoop-daemon.sh start zkfc"手动启动ZKFC客户端。

 

 

 

 

 

参考:

http://hadoop.apache.org/docs/r2.6.5/hadoop-project-dist/hadoop-hdfs/HDFSHighAvailabilityWithQJM.html

http://shift-alt-ctrl.iteye.com/blog/2102571

  • 大小: 11.5 KB
  • 查看图片附件
原创粉丝点击