#################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:
<property>
<name>fs.defaultFS</name>
<value>hdfs://ns1:8020</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/opt/app/hadoop-2.5.0-cdh5.3.6/data/temp</value>
</property>
<property>
<name>ha.zookeeper.quorum</name>
<value>centos20.com:2181,centos21.com:2181,centos22.com:2181</value>
</property>
#etc/hadoop/hdfs-site.xml
<property>
<name>dfs.nameservices</name>
<value>ns1</value>
</property>
<property>
<name>dfs.ha.namenodes.ns1</name>
<value>nn1,nn2</value>
</property>
<property>
<name>dfs.namenode.rpc-address.ns1.nn1</name>
<value>centos20.com:8020</value>
</property>
<property>
<name>dfs.namenode.rpc-address.ns1.nn2</name>
<value>centos22.com:8020</value>
</property>
<property>
<name>dfs.namenode.http-address.ns1.nn1</name>
<value>centos20.com:50070</value>
</property>
<property>
<name>dfs.namenode.http-address.ns1.nn2</name>
<value>centos22.com:50070</value>
</property>
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://centos20.com:8485;centos22.com:8485;centos21.com:8485/ns1</value>
</property>
<property>
<name>dfs.client.failover.proxy.provider.ns1</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/centos/.ssh/id_rsa</value>
</property>
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/opt/app/hadoop-2.5.0-cdh5.3.6/data/journal/data</value>
</property>
<property>
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub centos@centos22.com
cd .ssh
ssh-copy-id -i id_rsa.pub centos@centos20.com
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 centos@centos22.com:/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