四台主机上:/etc/profile中添加两个环境变量并使之生效:
export HDFS_JOURNALNODE_USER=root
export HDFS_ZKFC_USER=root
hdfs-site.xml:
<property>
<name>dfs.nameservices</name>
<value>mycluster</value>
</property>
<property>
<name>dfs.ha.namenodes.mycluster</name>
<value>nn1,nn2,nn3</value>
</property>
<property>
<name>dfs.namenode.rpc-address.mycluster.nn1</name>
<value>node1:8020</value>
</property>
<property>
<name>dfs.namenode.rpc-address.mycluster.nn2</name>
<value>node2:8020</value>
</property>
<property>
<name>dfs.namenode.rpc-address.mycluster.nn3</name>
<value>node3:8020</value>
</property>
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://node1:8485;node2:8485;node3:8485/mycluster</value>
</property>
<property>
<name>dfs.client.failover.proxy.provider.mycluster</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>/root/.ssh/id_dsa</value>
</property>
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/var/bjsxt/hadoop/ha/jnnedits</value>
</property>
<property>
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
core-site.xml
<property>
<name>fs.defaultFS</name>
<value>hdfs://mycluster</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/var/bjsxt/hadoop/ha</value>
</property>
<property>
<name>ha.zookeeper.quorum</name>
<value>node2:2181,node3:2181,node4:2181</value>
</property>
node2/node3/node4上传zookeeper-3.4.9.tar.gz
tar -zxf zookeeper-3.4.9.tar.gz -C /opt
cd /opt/zookeeper-3.4.9/conf
复制zoo_sample.cfg为zoo.cfg
编辑zoo.cfg
dataDir=/var/bjsxt/zookeeper/data
# the port at which the clients will connect
clientPort=2181
server.1=node2:2881:3881
server.2=node3:2001:3881
server.3=node3:2881:3881
node2上执行
mkdir -p /var/bjsxt/zookeeper/data
echo 1 > /var/bjsxt/zookeeper/data/myid
node3上执行
mkdir -p /var/bjsxt/zookeeper/data
echo 2 > /var/bjsxt/zookeeper/data/myid
node4上执行
mkdir -p /var/bjsxt/zookeeper/data
echo 3 > /var/bjsxt/zookeeper/data/myid
在node2/node3/node4上的/etc/profile中添加
export ZOOKEEPER_PREFIX=/opt/zookeeper-3.4.9
export PATH=$PATH:$ZOOKEEPER_PREFIX/bin
使之生效
source /etc/profile
启动zk1/zk2/zk3
zkServer.sh start
zkServer.sh status
zkServer.sh stop
[root@node004 ~]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@node004 ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.9/bin/../conf/zoo.cfg
Mode: leader
在node1和node2和node3上执行:
hdfs --daemon start journalnode
启动JournalNodes
在node1上执行:
hdfs --daemon start namenode
在node2上执行:
hdfs namenode -bootstrapStandby
在node3上执行:
hdfs namenode -bootstrapStandby
初始化zookeeper上NameNode的状态
在node1上执行:
hdfs zkfc -formatZK
在node2或node3或node4上执行:
zkCli.sh
在node1或node2或node3上执行
start-dfs.sh
启动集群(记着先开启zookeeper集群)
[root@node001 opt]# start-dfs.sh
19/03/19 17:20:02 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Starting namenodes on [node001 node002]
node001: starting namenode, logging to /opt/hadoop-2.6.5/logs/hadoop-root-namenode-node001.out
node002: starting namenode, logging to /opt/hadoop-2.6.5/logs/hadoop-root-namenode-node002.out
node004: starting datanode, logging to /opt/hadoop-2.6.5/logs/hadoop-root-datanode-node004.out
node003: starting datanode, logging to /opt/hadoop-2.6.5/logs/hadoop-root-datanode-node003.out
node002: starting datanode, logging to /opt/hadoop-2.6.5/logs/hadoop-root-datanode-node002.out
Starting journal nodes [node001 node002]
node001: starting journalnode, logging to /opt/hadoop-2.6.5/logs/hadoop-root-journalnode-node001.out
node002: starting journalnode, logging to /opt/hadoop-2.6.5/logs/hadoop-root-journalnode-node002.out
19/03/19 17:20:39 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Starting ZK Failover Controllers on NN hosts [node001 node002]
node001: starting zkfc, logging to /opt/hadoop-2.6.5/logs/hadoop-root-zkfc-node001.out
node002: starting zkfc, logging to /opt/hadoop-2.6.5/logs/hadoop-root-zkfc-node002.out