hadoop完全高可用配置

保證普通集羣可運行後, 修改配置文件

高可用依賴 zookeeper 集羣實現主從切換

先搭建 zookeeper 集羣, 詳見 zookeeper 集羣部署

core-site.xml

<configuration>
  <property>
    <name>fs.defaultFS</name>
    <value>hdfs://nncluster</value>
  </property>
  <property>
    <name>hadoop.tmp.dir</name>
    <value>/opt/modules/hadoop/data/tmp</value>
  </property>

  <property>
    <name>ha.zookeeper.quorum</name>
    <value>hadoop151:2181,hadoop152:2181,hadoop153:2181,hadoop154:2181,hadoop155:2181</value>
  </property>

<!--oozie-->
  <property>
    <name>hadoop.proxyuser.hadoop.hosts</name>
    <value>*</value>
  </property>
  <property>
    <name>hadoop.proxyuser.hadoop.groups</name>
    <value>*</value>
  </property>
</configuration>

hdfs-site.xml

<configuration>
  <property>
    <name>dfs.replication</name>
    <value>3</value>
  </property>

  <property>
    <name>dfs.namenode.secondary.http-address</name>
    <value>hadoop155:50090</value>
  </property>

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

  <property>
    <name>dfs.ha.namenodes.nncluster</name>
    <value>nn1,nn2</value>
  </property>
  <property>
    <name>dfs.namenode.rpc-address.nncluster.nn1</name>
    <value>hadoop151:8020</value>
  </property>
  <property>
    <name>dfs.namenode.http-address.nncluster.nn1</name>
    <value>hadoop151:50070</value>
  </property>
  <property>
    <name>dfs.namenode.rpc-address.nncluster.nn2</name>
    <value>hadoop152:8020</value>
  </property>
  <property>
    <name>dfs.namenode.http-address.nncluster.nn2</name>
    <value>hadoop152:50070</value>
  </property>
  <property>
    <name>dfs.namenode.shared.edits.dir</name>
    <value>qjournal://hadoop151:8485;hadoop152:8485;hadoop153:8485;hadoop154:8485;hadoop155:8485/nncluster</value>
  </property>
  <property>
    <name>dfs.journalnode.edits.dir</name>
    <value>/opt/modules/hadoop/journaldata</value>
  </property>
  <property>
    <name>dfs.ha.automatic-failover.enabled</name>
    <value>true</value>
  </property>
  <property>
    <name>dfs.client.failover.proxy.provider.nncluster</name>
    <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
  </property>
  <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>/home/hadoop/.ssh/id_rsa</value>
  </property>
  <property>
    <name>dfs.ha.fencing.ssh.connect-timeout</name>
    <value>30000</value>
  </property>

</configuration>

mapred-site.xml

<configuration>
  <property>
    <name>mapreduce.framework.name</name>
    <value>yarn</value>
  </property>

  <!--配置MapReduce JobHistory Server 地址, 默認端口 10020-->
  <property>
    <name>mapreduce.jobhistory.address</name>
    <value>hadoop151:10020</value>
  </property>
  <!--配置 MapReduce JobHistory Server web ui 地址, 默認端口19888-->
  <property>
    <name>mapreduce.jobhistory.webapp.address</name>
    <value>hadoop151:19888</value>
  </property>
</configuration>

yarn-site.xml

<configuration>

<!-- Site specific YARN configuration properties -->
  <property>
    <name>yarn.nodemanager.aux-services</name>
    <value>mapreduce_shuffle</value>
  </property>
  
  <property>
    <name>yarn.resourcemanager.ha.enabled</name>
    <value>true</value>
  </property>

  <!-- 指定RM的cluster id -->
  <property>
    <name>yarn.resourcemanager.cluster-id</name>
    <value>rmcluster</value>
  </property>

  <!-- 指定RM的名字 -->
  <property>
    <name>yarn.resourcemanager.ha.rm-ids</name>
    <value>rm1,rm2</value>
  </property>

  <!-- 分別指定RM的地址 -->
  <property>
    <name>yarn.resourcemanager.hostname.rm1</name>
    <value>hadoop153</value>
  </property>
  <property>
    <name>yarn.resourcemanager.hostname.rm2</name>
    <value>hadoop154</value>
  </property>

  <!-- 指定zk集羣地址 -->
  <property>
    <name>yarn.resourcemanager.zk-address</name>
    <value>hadoop151:2181,hadoop152:2181,hadoop153:2181,hadoop154:2181,hadoop155:2181</value>
  </property>
</configuration>

  1. 啓動所有 zookeeper 節點, jps 可見進程中有 QuorumPeerMain

  2. 啓動所有 journalnode 節點

    $ sbin/hadoop-daemon.sh start journalnode
    
  3. 格式化 namenode 節點,

    • 在任一 namenode 節點執行格式化命令
    $ hdfs namenode -format
    
    • 在另一 namenode 節點同步格式化數據 core-site.xml 中 hadoop.tmp.dir 的值所指向的文件夾
    $ scp hadoop@hadoop151:/opt/modules/hadoop/etc/hadoop/data/ /opt/modules/hadoop/etc/hadoop/
    
    • 或在另一節點執行命令
    $ hdfs namenode -bootstrapStandby
    
  4. 格式化 zkfc, 在 namenode 節點執行

    $ hdfs zkfc -formatZK
    
  5. 分別啓動 hdfs 和 yarn

    $ sbin/start-dfs.sh
    $ sbin/start-yarn.sh
    
  6. jps 查看各節點,
    在這裏插入圖片描述

  7. 訪問管理臺查看

在這裏插入圖片描述
在這裏插入圖片描述

可關閉當前active狀態 namenode, 刷新standby 狀態頁面, 可看到狀態變爲 active

  1. 也可手動切換 active 節點
    在這裏插入圖片描述
    在這裏插入圖片描述

    $ hdfs haadmin -transitionToActive --forcemanual nn1
    
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章