hadoop ha

#################centos7###############
#########hadoop-2.5.0-cdh5.3.6分布式HA#########

#JDK
JAVA_HOME=/opt/app/jdk1.8.0_171
JRE_HOME=/opt/app/jdk1.8.0_171/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH


#/ect/hostname(update)
centos20.com
centos21.com
centos22.com

#/ect/hosts(add)
192.168.113.141  centos20.com
192.168.113.143  centos22.com
192.168.113.144  centos21.com

规划集群
    141                        143                    144

    NameNode                 NameNode

    JournalNode                JournalNode            JournalNode

    DataNode                 DataNode             DataNode

journalnode
bin/hdfs namenode -bootstrapStandby

#etc/hadoop/hadoop-env.sh再显示地重新声明一遍JAVA_HOME

#etc/hadoop/core-site.xml:
    
        fs.defaultFS
        hdfs://ns1:8020
    

    
        hadoop.tmp.dir
        /opt/app/hadoop-2.5.0-cdh5.3.6/data/temp
    

    
    
       ha.zookeeper.quorum
       centos20.com:2181,centos21.com:2181,centos22.com:2181
    

#etc/hadoop/hdfs-site.xml

  dfs.nameservices
  ns1


  dfs.ha.namenodes.ns1
  nn1,nn2


  dfs.namenode.rpc-address.ns1.nn1
  centos20.com:8020


  dfs.namenode.rpc-address.ns1.nn2
  centos22.com:8020


  dfs.namenode.http-address.ns1.nn1
  centos20.com:50070


  dfs.namenode.http-address.ns1.nn2
  centos22.com:50070



  dfs.namenode.shared.edits.dir
  qjournal://centos20.com:8485;centos22.com:8485;centos21.com:8485/ns1


  dfs.client.failover.proxy.provider.ns1
  org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider


  dfs.ha.fencing.methods
  sshfence


  dfs.ha.fencing.ssh.private-key-files
  /home/centos/.ssh/id_rsa


  dfs.journalnode.edits.dir
  /opt/app/hadoop-2.5.0-cdh5.3.6/data/journal/data


   dfs.ha.automatic-failover.enabled
   true

ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
cd .ssh
ssh-copy-id -i id_rsa.pub [email protected]
ssh-copy-id centos20.com

mkdir -p /opt/app/hadoop-2.5.0-cdh5.3.6/data/temp
mkdir -p /opt/app/hadoop-2.5.0-cdh5.3.6/data/journal/data

#小知识
scp -r etc/hadoop/core-site.xml etc/hadoop/hdfs-site.xml etc/hadoop/slaves [email protected]:/opt/app/hadoop-2.5.0-cdh5.3.6/etc/hadoop

cd /opt/app/hadoop-2.5.0-cdh5.3.6
QJM HA启动
1.JournalNode节点,启动journalnode服务
sbin/hadoop-daemon.sh start journalnode
2.nn1格式化并启动
bin/hdfs namenode -format
sbin/hadoop-daemon.sh start namenode
3.在nn2上同步nn1的元数据信息
bin/hdfs namenode -bootstrapStandby
4.启动nn2
sbin/hadoop-daemon.sh start namenode
5.将nn1切换成Active
bin/hdfs haadmin -transitionToActive nn1
6.在nn1,启动所有datanode
sbin/hadoop-daemon.sh start datanode


centos20.com:50070
centos22.com:50070

#zk 
mkdir -p  /opt/app/zookeeper-3.4.12/zktemp/data
mkdir -p  /opt/app/zookeeper-3.4.12/zktemp/log


cp -rf conf/zoo_sample.cfg    conf/zoo.cfg
vim   zoo.cfg
dataDir=/opt/app/zookeeper-3.4.12/zktemp/data
dataLogDir=/opt/app/zookeeper-3.4.12/zktemp/log
server.1=centos20.com:2888:3888
server.2=centos21.com:2888:3888
server.3=centos22.com:2888:3888


echo "1" > /opt/app/zookeeper-3.4.12/zktemp/data/myid
echo "2" > /opt/app/zookeeper-3.4.12/zktemp/data/myid
echo "3" > /opt/app/zookeeper-3.4.12/zktemp/data/myid

cd /opt/app/zookeeper-3.4.12
./bin/zkServer.sh start


NN HA自动故障转移
1.关闭所有HDFS服务  sbin/stop-dfs.sh
2.启动zookeeper集群 bin/zkServer.sh start
3.初始化HA在Zookeeper状态(单台) bin/hdfs zkfc -formatZK
4.启动HDFS服务 sbin/start-dfs.sh
5.启动DFSZK Failover Controller sbin/hadoop-daemons.sh start zkfc

验证
1.Active NameNode杀掉进程  kill -9 pid
2.Active NameNode断开网络  service network stop

    

你可能感兴趣的:(hadoop,hadoop)