Hadoop-Yarn-HA集羣搭建(搭建篇)

1.前提條件

我學習過程是一塊一塊深刻的,在把hdfs基本弄懂以及HA成功的狀況開始嘗試搭建yarn的,建議在搭建前先去看一下轉載的原理篇,懂了原理後搭建會很快的,再次強調一下hdfs我默認已經搭建成功了node

2.搭建環境準備

  • 1,主機環境:4臺centos機器。

    rtest-mysql-01: 主NN,ResourceManager 運行進程(NameNode,ResourceManager,DFSZKFailoverControllermysql

      主要運行nn和ResourceManager。
web

    rtest-mysql-02:備NN,ResourceManager  運行程序(NameNode,DFSZKFailoverController,DataNode,ResourceManager,JournalNode,NodeManager,zookeeper)sql

      備nn和ResourceManager,同時和03,04搭建了zookeeper集羣和journalnode集羣。
express

     rtest-mysql-03:運行程序(DataNode,JournalNode,NodeManager,zookeeper)apache

         數據節點
centos

     rtest-mysql-04:運行程序(DataNode,JournalNode,NodeManager,zookeeper)app

                數據節點
less

  • 2,各主機詳解

    在hadoop2.X中一般由兩個NameNode組成,一個處於active狀態,另外一個處於standby狀態。Active NameNode對外提供服務,而Standby NameNode則不對外提供服務,僅同步active namenode的狀態,以便可以在它失敗時快速進行切換。hadoop2.0官方提供了兩種HDFS HA的解決方案,一種是NFS,另外一種是QJM(由cloudra提出,原理相似zookeeper)。這裏我使用QJM完成。主備NameNode之間經過一組JournalNode同步元數據信息,一條數據只要成功寫入多數JournalNode即認爲寫入成功。一般配置奇數個JournalNodewebapp

3.搭建過程

1.前提在強調一下

hdfs的ha已經成功,由於yarn的ha也是須要zkfc的,若是zkfc不沒有成功,天然yarn切換也沒有成功了。

2.mapred-site.xml

<configuration>
        <property>
                <name>mapreduce.framework.name</name>
                <value>yarn</value>
                <description>The runtime framework for executing MapReduce jobs.
                        Can be one of local, classic or yarn.
                </description>
        </property>

<!-- jobhistory properties -->
        <property>
                <name>mapreduce.jobhistory.address</name>
                <value>0.0.0.0:10020</value>
                <description>MapReduce JobHistory Server IPC host:port</description>
        </property>

        <property>
                <name>mapreduce.jobhistory.webapp.address</name>
                <value>0.0.0.0:19888</value>
                <description>MapReduce JobHistory Server Web UI host:port</description>
        </property>

</configuration>

3.yarn-site.xml 主要的配置文件

<?xml version="1.0"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->
<configuration>

<!-- Site specific YARN configuration properties -->
<!-- Resource Manager Configs -->

<!--rm失聯後從新連接的時間-->
    <property>
        <name>yarn.resourcemanager.connect.retry-interval.ms</name>
        <value>2000</value>
    </property>

<!--開啓resourcemanagerHA,默認爲false-->
    <property>
        <name>yarn.resourcemanager.ha.enabled</name>
        <value>true</value>
    </property>

<!--配置resourcemanager-->
    <property>
        <name>yarn.resourcemanager.ha.rm-ids</name>
        <value>rm1,rm2</value>
    </property>

    <property>
        <name>ha.zookeeper.quorum</name>
        <value>rtest-mysql-02:2181,rtest-mysql-03:2181,rtest-mysql-04:2181</value>
    </property>

<!--開啓故障自動切換-->
    <property>
        <name>yarn.resourcemanager.ha.automatic-failover.enabled</name>
        <value>true</value>
    </property>
    
   <property>
        <description>The hostname of the RM.</description>
        <name>yarn.resourcemanager.hostname</name>
        <value>rtest-mysql-01</value>
   </property> 
  
    <property>
        <name>yarn.resourcemanager.hostname.rm1</name>
        <value>rtest-mysql-01</value>
    </property>

    <property>
        <name>yarn.resourcemanager.hostname.rm2</name>
        <value>rtest-mysql-02</value>
    </property>
    
    <!--
    注意:通常都喜歡把配置好的文件遠程複製到其它機器上,但這個在YARN的另外一個機器上必定要修改
    -->
    <property>
        <name>yarn.resourcemanager.ha.id</name>
        <value>rm1</value>
        <description>If we want to launch more than one RM in single node,we need this configuration</description>
    </property>

<!--開啓自動恢復功能-->
    <property>
        <name>yarn.resourcemanager.recovery.enabled</name>
        <value>true</value>
    </property>

<!--配置與zookeeper的鏈接地址-->
    <property>
        <name>yarn.resourcemanager.zk-state-store.address</name>
        <value>rtest-mysql-02:2181,rtest-mysql-03:2181,rtest-mysql-04:2181</value>
    </property>

    <property>
        <name>yarn.resourcemanager.store.class</name>
        <value>org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStore</value>
    </property>

    <property>
        <name>yarn.resourcemanager.zk-address</name>
        <value>rtest-mysql-02:2181,rtest-mysql-03:2181,rtest-mysql-04:2181</value>
    </property>

    <property>
        <name>yarn.resourcemanager.cluster-id</name>
        <value>yarn-cluster</value>
    </property>
    
    <!--schelduler失聯等待鏈接時間-->
    <property>
        <name>yarn.app.mapreduce.am.scheduler.connection.wait.interval-ms</name>
        <value>5000</value>
    </property>
   
    <!--注意:通常都喜歡把配置好的文件遠程複製到其它機器上,但這個在YARN的另外一個機器上必定要修改-->
   <property>
        <description>The address of the applications manager interface in the RM.</description>
        <name>yarn.resourcemanager.address.rm1</name>
        <value>rtest-mysql-01:8032</value>
   </property>

   <property>
        <description>The address of the scheduler interface.</description>
        <name>yarn.resourcemanager.scheduler.address.rm1</name>
        <value>rtest-mysql-01:8030</value>
   </property>

   <property>
        <description>The http address of the RM web application.</description>
        <name>yarn.resourcemanager.webapp.address.rm1</name>
        <value>rtest-mysql-01:8088</value>
   </property>

   <property>
        <description>The https adddress of the RM web application.</description>
        <name>yarn.resourcemanager.webapp.https.address.rm1</name>
        <value>rtest-mysql-01:8090</value>
   </property>

   <property>
        <name>yarn.resourcemanager.resource-tracker.address.rm1</name>
        <value>rtest-mysql-01:8031</value>
   </property>

   <property>
        <description>The address of the RM admin interface.</description>
        <name>yarn.resourcemanager.admin.address.rm1</name>
        <value>rtest-mysql-01:8033</value>
   </property>
  
    <property>
        <name>yarn.resourcemanager.ha.admin.address.rm1</name>
        <value>rtest-mysql-01:23142</value>
    </property>

    <!--*******************************************************-->
    
    <property>
        <description>the valid service name should only contain a-zA-Z0-9_ and can not start with numbers</description>
        <name>yarn.nodemanager.aux-services</name>
        <value>mapreduce_shuffle</value>
   </property>
    <property>
        <name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
        <value>org.apache.hadoop.mapred.ShuffleHandler</value>
    </property>
    
   <property>
        <description>The class to use as the resource scheduler.</description>
        <name>yarn.resourcemanager.scheduler.class</name>
        <value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler</value>
   </property>
  
    <property>
        <name>yarn.nodemanager.log-dirs</name>
        <value>/home/biedong/hadoop/yarn/log</value>
    </property>

    <property>
        <name>mapreduce.shuffle.port</name>
        <value>23080</value>
    </property>

   <property>
        <description>fair-scheduler conf location</description>
        <name>yarn.scheduler.fair.allocation.file</name>
        <value>/home/biedong/hadoop-2.7.0/etc/hadoop/fairscheduler.xml</value>
   </property>

   <property>
        <description>List of directories to store localized files in. An 
              application's localized file directory will be found in:
              ${yarn.nodemanager.local-dirs}/usercache/${user}/appcache/application_${appid}.
              Individual containers' work directories, called container_${contid}, will
              be subdirectories of this.
         </description>
        <name>yarn.nodemanager.local-dirs</name>
        <value>/home/biedong/hadoop/yarn/local</value>
   </property>

   <property>
        <description>Whether to enable log aggregation</description>
        <name>yarn.log-aggregation-enable</name>
        <value>true</value>
   </property>

   <property>
        <description>Where to aggregate logs to.</description>
        <name>yarn.nodemanager.remote-app-log-dir</name>
        <value>/tmp/logs</value>
   </property>

   <property>
        <description>Amount of physical memory, in MB, that can be allocated for containers.</description>
        <name>yarn.nodemanager.resource.memory-mb</name>
        <value>8192</value>
   </property>

   <property>
        <description>Number of CPU cores that can be allocated for containers.</description>
        <name>yarn.nodemanager.resource.cpu-vcores</name>
        <value>4</value>
   </property>
  
  <!--故障處理類-->
    <property>
        <name>yarn.client.failover-proxy-provider</name>
        <value>org.apache.hadoop.yarn.client.ConfiguredRMFailoverProxyProvider</value>
    </property>

    <property>
        <name>yarn.resourcemanager.ha.automatic-failover.zk-base-path</name>
        <value>/yarn-leader-election</value>
        <description>Optionalsetting.Thedefaultvalueis/yarn-leader-election</description>
    </property>

</configuration>
詳細配置

4.啓動YARN

你可使用如下命令分別啓動ResourceManager和NodeManager:
  sbin/yarn-daemon.sh start resourcemanager
  sbin/yarn-daemon.sh start nodemanager(若是有多個datanode,需使用yarn-daemons.sh)
  或者一次啓動過:sbin/start-yarn.sh

5.驗證是否成功

輸入命令驗證主備關係:

  yarn rmadmin -getServiceState rm1

  yarn rmadmin -getServiceState rm2

在網頁輸入:http:rtest-mysql-02:8088,是否能打開這個頁面

 6.主備自動切換驗證

訪問rm1節點的nodemanager會提示
This is standby RM. Redirecting to the current active RM: http://rtest-mysql-01:8088/cluster/apps
下面KILL掉rm2的resourcemanager

再次驗證主備關係:

7.運行應用程序

執行以下:bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.0.jar pi 20 10

若是程序沒有明顯報錯,證實安裝成功!

相關文章
相關標籤/搜索