Hadoop聯邦機制加HA容錯機制詳細配置說明-Hadoop商業環境實戰

凱新的技術社群發表於2018-12-19

本套技術專欄是作者(秦凱新)平時工作的總結和昇華,通過從真實商業環境抽取案例進行總結和分享,並給出商業應用的調優建議和叢集環境容量規劃等內容,請持續關注本套部落格。期待加入IOT時代最具戰鬥力的團隊。QQ郵箱地址:1120746959@qq.com,如有任何學術交流,可隨時聯絡。

1 core-site.xml 配置:

  • 1:配置統一檢視viewfs:///

  • 2: 配置不同名稱空間下,每一個HDFS例項預設的訪問空間,注意不是主機名。比如:

      <configuration>
              <property>
                      <name>fs.defaultFS</name>
                      <value>viewfs:///</value>
              </property>
              <property>
                      <name>fs.viewfs.mounttable.default.link./my</name>
                      <value>hdfs://mycluster/</value>
              </property>
              <property>
                      <name>fs.viewfs.mounttable.default.link./your</name>
                      <value>hdfs://yourcluster/</value>
              </property>
      		<property>
      				 <name>ha.zookeeper.quorum</name>
      				 <value>Master:2181,Worker1:2181,Worker2:2181</value>
      		</property>
              <property>
                      <name>hadoop.tmp.dir</name>
                      <value>/home/tmp/hadoop2.0</value>
              </property>
      </configuration>
    複製程式碼

2 hdfs-site.xml 配置:

  • 1:指定dfs.nameservices,也即Hdfs例項兩個。比如:mycluster,yourcluster

  • 2:指定兩個Hdfs例項mycluster和yourcluster的namenode Id 比如:nn1,nn2

  • 3:設定兩個Hdfs例項mycluster和yourcluster對應的兩個namenode(ANN,SNN)例項對應的rpc-address(4個)和http-address(4個)。比如:

      namenode1:9000(ANN),namenode2:9000(SNN)| namenode3:9000,namenode4:9000
      namenode1:50070,namenode2:50070|namenode3:50070,namenode4:50070
    複製程式碼
  • 4:指定自動容錯機制automatic-failover,比如:設定為True

  • 5:指定共享儲存指定目錄shared.edits.dir。比如:路徑為

          qjournal://Master:8485;Worker1:8485;Worker2:8485/mycluster
          和qjournal://Master:8485;Worker1:8485;Worker2:8485/yourcluster
    複製程式碼
  • 6 總覽配置

      <configuration>
      	<property>
                  <name>dfs.nameservices</name>
                  <value>mycluster,yourcluster</value>
          </property>
          <property>
                  <name>dfs.ha.namenodes.mycluster</name>
                  <value>nn1,nn2</value>
          </property>
          <property>
                  <name>dfs.ha.namenodes.yourcluster</name>
                  <value>nn1,nn2</value>
          </property>
      	
      	
          <property>
                  <name>dfs.namenode.rpc-address.mycluster.nn1</name>
                  <value>namenode1:9000</value>
          </property>
          <property>
                  <name>dfs.namenode.rpc-address.mycluster.nn2</name>
                  <value>namenode2:9000</value>
          </property>
      	
          <property>
                  <name>dfs.namenode.rpc-address.yourcluster.nn1</name>
                  <value>namenode3:9000</value>
          </property>
          <property>
                  <name>dfs.namenode.rpc-address.yourcluster.nn2</name>
                  <value>namenode4:9000</value>
          </property>
      	
      	<property>
                  <name>dfs.namenode.http-address.mycluster.nn1</name>
                  <value>namenode1:50070</value>
          </property>
          <property>
                  <name>dfs.namenode.http-address.mycluster.nn2</name>
                  <value>namenode2:50070</value>
          </property>
          <property>
                  <name>dfs.namenode.http-address.yourcluster.nn1</name>
                  <value>namenode3:50070</value>
          </property>
          <property>
                  <name>dfs.namenode.http-address.yourcluster.nn2</name>
                  <value>namenode4:50070</value>
          </property>
      	
          <property>
      			<name>dfs.journalnode.edits.dir</name>
      			<value>/usr/local/soft/cdh_support/hadoop-2.6.0-cdh5.9.3/journal</value>
          </property>
      	
      	<property>
      				<name>dfs.namenode.shared.edits.dir</name>
      				<value>qjournal://Master:8485;Worker1:8485;Worker2:8485/mycluster</value>
          </property>	
          <property>
      				<name>dfs.namenode.shared.edits.dir</name>
      				<value>qjournal://Master:8485;Worker1:8485;Worker2:8485/yourcluster</value>
          </property>	
          <property>
      				<name>dfs.client.failover.proxy.provider.my-cluster</name>
      				<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
          </property>
      	<property>
      				<name>dfs.client.failover.proxy.provider.yourcluster</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>/home/admin/.ssh/id_rsa</value>
          </property>
          <property>
      				<name>dfs.ha.fencing.ssh.connect-timeout</name>
      				<value>6000</value>
          </property>
          <property>
      				<name>dfs.ha.automatic-failover.enabled</name>
      				<value>true</value>
          </property>
     
     
     
          <property>
      				<name>dfs.replication</name>
      				<value>3</value>
          </property>
          <property>  
      				<name>dfs.datanode.max.xcievers</name>  
      				<value>8192</value>  
         </property>  
         <property>
      				<name>dfs.datanode.data.dir</name>
      				<value>file:/hadoop/datanode</value>
         </property>
         <property>
      				 <name>dfs.namenode.datanode.registration.ip-hostname-check</name>
      				 <value>false</value>
         </property>
         <property>
      				<name>dfs.namenode.name.dir</name>
      				<value>file:/hadoop/namenode</value>
         </property>
         <property>
      	            <name>dfs.permissions</name>
                      <value>false</value>
         </property>
      </configuration>  
    複製程式碼

3 引數設定

dfs.namenode.shared.edits.dir

這個引數要注意,在兩組HA中的值是不一樣的,即在“mycluster”(namenode1和namenode2)和是“yourcluster”(namenode3和namenode4)中不同。

4 管理

1 先啟動journalnode,在journalnode節點上執行以下命令

$HADOOP_HOME/sbin/hadoop-daemon.sh start journalnode
複製程式碼

2在namenode1和namenode3上執行格式化命令並啟動namenode

$HADOOP_HOME/bin/hdfs namenode -format –clusterId hellokitty
$HADOOP_HOME/sbin/hadoop-daemon.sh start namenode
複製程式碼

3 在namenode2和namenode4上執行bootstrapStandby命令並啟動namenode

$HADOOP_HOME/sbin/hadoop-daemon.sh start  namenode -bootstrapStandby
$HADOOP_HOME/sbin/hadoop-daemon.sh start namenode
複製程式碼

這時namenode1,namenode2,namenode3,namenode4四個namenode都是“standby”狀態。

4 在namenode1和namenode3執行以下命令,切換成“active”狀態

$HADOOP_HOME/bin/hdfs haadmin -transitionToActive nn1
複製程式碼

5 在zookeeper中初始化

$HADOOP_HOME/bin/hdfs zkfc -formatZK
複製程式碼

6 啟動zkfc daemon程式,在namenode1,namenode2,namenode3,namenode4上都啟動zkfc daemon程式。

$HADOOP_HOME/sbin/hadoop-daemon.sh start zkfc
複製程式碼

5 總結

秦凱新 於深圳

相關文章