高可用hadoop集群

在Hadoop2.0之前,只有一个NameNode,若NameNode机器出现故障,那么整个集群都无法使用。这个架构存在单点故障的隐患。之后推出了HA的架构,即有两个NameNode,一台为active状态,一台为standby状态。active NameNode对外提供服务,standby实时同步了active NameNode的元数据,当active NameNode节点出现故障,standby NameNode节点可立即切换为active状态并对外提供服务。所以,在实际生产中一般采用HA架构。这里用三台机器测试搭建Hadoop高可用集群。

避坑--配置隔离机制shell(/bin/true)
Host    安装软件    进程
hadoop001    hadoop、zookeeper    NameNode、DFSZKFailoverController、JournalNode、DataNode 、 ResourceManager 、JobHistoryServer、NodeManager 、QuorumPeerMain
hadoop002    hadoop、zookeeper    NameNode 、DFSZKFailoverController、JournalNode 、DataNode 、ResourceManager 、NodeManager 、QuorumPeerMain
hadoop003    hadoop、zookeeper    JournalNode 、DataNode 、NodeManager、QuorumPeerMain
    修改配置文件
cd /usr/local/src/hadoop-2.6.0/etc/hadoop

hadoop-env.sh
  export JAVA_HOME=/opt/apps/jdk1.8.0_172

core-site.xml
mkdir –p /usr/local/src/hadoop-2.6.0/tmp

<configuration>
        <property>
                <name>fs.defaultFS</name>
                <value>hdfs://ns</value>
        </property>
        <property>
                <name>hadoop.tmp.dir</name>
                <value>/usr/local/src/hadoop-2.6.0/tmp</value>
        </property>
        <property>
                <name>ha.zookeeper.quorum</name>
                <value>master:2181,slave1:2181,slave2:2181</value>
        </property>
</configuration>

hdfs-site.xml
<!--指定hdfs的nameservice为ns,需要和core-site.xml中的保持一致 -->      
    <property>      
        <name>dfs.nameservices</name>      
        <value>ns</value>      
    </property>    
    <!-- ns下面有两个NameNode,分别是nn1,nn2 -->  
    <property>  
       <name>dfs.ha.namenodes.ns</name>  
       <value>nn1,nn2</value>  
    </property>  
    <!-- nn1的RPC通信地址 -->  
    <property>  
       <name>dfs.namenode.rpc-address.ns.nn1</name>  
       <value>master:9000</value>  
    </property>  
    <!-- nn1的http通信地址 -->  
    <property>  
        <name>dfs.namenode.http-address.ns.nn1</name>  
        <value>master:50070</value>  
    </property>  
    <!-- nn2的RPC通信地址 -->  
    <property>  
        <name>dfs.namenode.rpc-address.ns.nn2</name>  
        <value>slave1:9000</value>  
    </property>  
    <!-- nn2的http通信地址 -->  
    <property>  
        <name>dfs.namenode.http-address.ns.nn2</name>  
        <value>slave1:50070</value>  
    </property>  
    <!-- 指定NameNode的元数据在JournalNode上的存放位置 -->  
    <property>  
         <name>dfs.namenode.shared.edits.dir</name>  
         <value>qjournal://master:8485;slave1:8485;slave2:8485/ns</value>  
    </property>  
    <!-- 指定JournalNode在本地磁盘存放数据的位置 -->  
    <property>  
          <name>dfs.journalnode.edits.dir</name>  
          <value>/usr/local/src/hadoop-2.6.0/hdf_journal</value>  
    </property>  
    <!-- 开启NameNode故障时自动切换 -->  
    <property>  
          <name>dfs.ha.automatic-failover.enabled</name>  
          <value>true</value>  
    </property>  
    <!-- 配置失败自动切换实现方式 -->  
    <property>  
            <name>dfs.client.failover.proxy.provider.ns</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>  
    <!-- 使用隔离机制时需要ssh免登陆 -->  
    <property>  
            <name>dfs.ha.fencing.ssh.private-key-files</name>  
            <value>/root/.ssh/id_rsa</value>  
    </property>  
    <!-- 配置sshfence隔离机制超时时间 -->
    <property>  
             <name>dfs.ha.fencing.ssh.connect-timeout</name>  
             <value>30000</value>  
    </property>                                 
    <property>      
        <name>dfs.namenode.name.dir</name>      
        <value>/usr/local/src/hadoop-2.6.0/hdf_name</value>
        <final>true</final>   
    </property>      
      
    <property>      
        <name>dfs.datanode.data.dir</name>      
        <value>/usr/local/src/hadoop-2.6.0/hdf_data</value>      
    </property>      
      
    <property>      
       <name>dfs.replication</name>      
       <value>3</value>      
    </property>     
    <!-- 在NN和DN上开启WebHDFS (REST API)功能,不是必须 -->                                                                      
    <property>      
       <name>dfs.webhdfs.enabled</name>      
       <value>true</value>      
    </property>

mapred-site.xml
cp mapred-site.xml.template mapred-site.xml

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


yarn-site.xml

  <!-- 开启YARN HA -->
  <property>
    <name>yarn.resourcemanager.ha.enabled</name>
    <value>true</value>
  </property>

  <!-- 启用自动故障转移 -->
  <property>
    <name>yarn.resourcemanager.ha.automatic-failover.enabled</name>
    <value>true</value>
  </property>

  <!-- 指定YARN HA的名称 -->
  <property>
    <name>yarn.resourcemanager.cluster-id</name>
    <value>yarncluster</value>
  </property>

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

  <!-- 配置rm1,rm2的主机 -->
  <property>
    <name>yarn.resourcemanager.hostname.rm1</name>
    <value>slave2</value>
  </property>
  <property>
    <name>yarn.resourcemanager.hostname.rm2</name>
    <value>slave1</value>
  </property>

  <!-- 配置YARN的http端口 -->
  <property>
    <name>yarn.resourcemanager.webapp.address.rm1</name>
    <value>slave2:8088</value>
  </property>
  <property>
    <name>yarn.resourcemanager.webapp.address.rm2</name>
    <value>slave1:8088</value>
  </property>

  <!-- 配置zookeeper的地址 -->
  <property>
    <name>yarn.resourcemanager.zk-address</name>
    <value>master:2181,slave1:2181,slave2:2181</value>
  </property>

  <!-- 配置zookeeper的存储位置 -->
  <property>
    <name>yarn.resourcemanager.zk-state-store.parent-path</name>
    <value>/rmstore</value>
  </property>

  <!-- 开启yarn resourcemanager restart -->
  <property>
    <name>yarn.resourcemanager.recovery.enabled</name>
    <value>true</value>
  </property>

  <!-- 配置resourcemanager的状态存储到zookeeper中 -->
  <property>
    <name>yarn.resourcemanager.store.class</name>
    <value>org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStore</value>
  </property>

  <!-- 开启yarn nodemanager restart -->
  <property>
    <name>yarn.nodemanager.recovery.enabled</name>
    <value>true</value>
  </property>
  <property>
    <name>yarn.nodemanager.aux-services</name>
    <value>mapreduce_shuffle</value>
  </property>
  <property>
    <name>yarn.nodemanager.address</name>
    <value>${yarn.nodemanager.hostname}:8041</value>
  </property>
    修改slaves文件
master
slave1
slave2


    拷贝到其他环境
scp -r /usr/local/src/hadoop-2.6.0 slave1:/usr/local/src/
scp -r /usr/local/src/hadoop-2.6.0 slave2:/usr/local/src/
Last modification:April 12th, 2020 at 05:58 pm
如果觉得我的文章对你有用,请随意赞赏