因为前面我们已经配置启动了普通的Hadoop相关服务,需要先停止相关服务并清除数据。
(1)停止Hadoop服务
首先停止YARN
[root@node1 ~]# stop-yarn.sh
stopping yarn daemons
stopping resourcemanager
node2: stopping nodemanager
node3: stopping nodemanager
node1: stopping nodemanager
node2: nodemanager did not stop gracefully after 5 seconds: killing with kill -9
node3: nodemanager did not stop gracefully after 5 seconds: killing with kill -9
node1: nodemanager did not stop gracefully after 5 seconds: killing with kill -9
no proxyserver to stop
停止HDFS服务
[root@node1 ~]# stop-dfs.sh
Stopping namenodes on [node1]
node1: stopping namenode
node3: stopping datanode
node1: stopping datanode
node2: stopping datanode
Stopping secondary namenodes [node2]
node2: stopping secondarynamenode
[root@node1 ~]#
(2)删除HDFS数据
[root@node1 ~]# rm -rf /var/data/hadoop
[root@node2 ~]# rm -rf /var/data/hadoop
[root@node3 ~]# rm -rf /var/data/hadoop
[root@node1 ~]# rm -rf /tmp/*
[root@node2 ~]# rm -rf /tmp/*
[root@node3 ~]# rm -rf /tmp/*
(3)准备zookeeper
启动Zookeeper集群。在每个节点上启动Zookeeper服务并确定状态正确
node1
[root@node1 ~]# jps
6117 Jps
2623 QuorumPeerMain
[root@node1 ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower
[root@node1 ~]#
node2
[root@node2 ~]# jps
3632 Jps
2354 QuorumPeerMain
[root@node2 ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: leader
[root@node2 ~]#
node3
[root@node3 ~]# jps
2278 QuorumPeerMain
3277 Jps
[root@node3 ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower
[root@node3 ~]#
实际上,上面命令执行过程是:
(1)通过XShell执行zkServer.sh start
(2)等待1到2秒,再通过通过XShell执行zkServer.sh status
[root@node1 ~]# cd /opt/hadoop-2.7.3/etc/hadoop/
[root@node1 hadoop]# vi core-site.xml
编辑内容如下,
[root@node1 hadoop]# cat core-site.xml
<configuration>
<property>
<name>fs.defaultFSname>
<value>hdfs://cetcvalue>
<description>默认路径前缀description>
property>
<property>
<name>hadoop.tmp.dirname>
<value>/hadoopvalue>
<description>Hadoop临时目录description>
property>
<property>
<name>io.file.buffer.sizename>
<value>65536value>
<description>序列文件的缓冲区的大小description>
property>
<property>
<name>dfs.ha.fencing.methodsname>
<value>
sshfence
shell(/bin/true)
value>
<description>配置隔离机制,多个机制用换行分割description>
property>
<property>
<name>dfs.ha.fencing.ssh.private-key-filesname>
<value>/root/.ssh/id_rsavalue>
<description>使用隔离机制时需要ssh免登录description>
property>
<property>
<name>ha.zookeeper.quorumname>
<value>node1:2181,node2:2181,node2:2181value>
<description>由ZKFC在自动故障转移中使用的ZooKeeper列表description>
property>
configuration>
提醒:一些教程将dfs.ha.fencing.methods和dfs.ha.fencing.ssh.private-key-files属性配置在hdfs-site.xml文件中。通过查看官方文件http://hadoop.apache.org/docs/r2.7.3/hadoop-project-dist/hadoop-common/core-default.xml 和 http://hadoop.apache.org/docs/r2.7.3/hadoop-project-dist/hadoop-hdfs/hdfs-default.xml,发现这两个属性应该在core-site.xml文件进行配置,而非hdfs-site.xml。
[root@node1 hadoop]# vi hdfs-site.xml
[root@node1 hadoop]# cat hdfs-site.xml
<configuration>
<property>
<name>dfs.nameservicesname>
<value>cetcvalue>
<description>名称服务的逻辑名称description>
property>
<property>
<name>dfs.ha.namenodes.cetcname>
<value>nn1,nn2value>
<description>名称服务中每个NameNode的唯一标识符description>
property>
<property>
<name>dfs.namenode.rpc-address.cetc.nn1name>
<value>node1:8020value>
<description>每个NameNode要监听的完全限定的RPC地址description>
property>
<property>
<name>dfs.namenode.rpc-address.cetc.nn2name>
<value>node2:8020value>
<description>每个NameNode要监听的完全限定的RPC地址description>
property>
<property>
<name>dfs.namenode.http-address.cetc.nn1name>
<value>node1:50070value>
<description>每个NameNode要监听的完全限定的HTTP地址description>
property>
<property>
<name>dfs.namenode.http-address.cetc.nn2name>
<value>node2:50070value>
<description>每个NameNode要监听的完全限定的HTTP地址description>
property>
<property>
<name>dfs.namenode.shared.edits.dirname>
<value>qjournal://node1:8485;node2:8485;node3:8485/abcvalue>
<description>HA群集中多个节点之间的共享存储上的目录。description>
property>
<property>
<name>dfs.journalnode.edits.dirname>
<value>/hadoop/journalnodevalue>
<description>指定JournalNode在本地磁盘存放数据的位置description>
property>
<property>
<name>dfs.ha.automatic-failover.enabledname>
<value>truevalue>
<description>启用namenode自动切换description>
property>
<property>
<name>dfs.client.failover.proxy.provider.cetcname>
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvidervalue>
<description>NameNode自动切换实现方式description>
property>
<property>
<name>dfs.replicationname>
<value>3value>
<description>副本数description>
property>
configuration>
[root@node1 hadoop]#
提醒:
请注意检查参数,别写错了。比如单词写错,很难检查出来。
[root@node1 hadoop]# vi hadoop-env.sh
修改3处
(1)JAVA_HOME
export JAVA_HOME=/opt/jdk1.8.0_112
(2)HADOOP_PID_DIR
export HADOOP_PID_DIR=/var/run/hadoop
注意,如果设置了export HADOOP_PID_DIR=/var/run/hadoop
,需要创建/var/run/hadoop目录。
[hadoop@node1 hadoop]$ sudo mkdir /var/run/hadoop
[hadoop@node1 hadoop]$ sudo chown hadoop:hadoop /var/run/hadoop
(3)HADOOP_LOG_DIR
# Where log files are stored. $HADOOP_HOME/logs by default.
#export HADOOP_LOG_DIR=/var/log/hadoop
[hadoop@node1 hadoop]$ sudo mkdir /var/log/hadoop
[hadoop@node1 hadoop]$ sudo chown hadoop:hadoop /var/log/hadoop
因为node2和node3节点上已经存在hadoop软件包,只需要向这两个节点分发配置文件即可。
[root@node1 hadoop]# scp core-site.xml node2:/opt/hadoop-2.7.3/etc/hadoop/
core-site.xml 100% 1003 1.0KB/s 00:00
[root@node1 hadoop]# scp hdfs-site.xml node2:/opt/hadoop-2.7.3/etc/hadoop/
hdfs-site.xml 100% 2434 2.4KB/s 00:00
[root@node1 hadoop]# scp core-site.xml node3:/opt/hadoop-2.7.3/etc/hadoop/
core-site.xml 100% 1003 1.0KB/s 00:00
[root@node1 hadoop]# scp hdfs-site.xml node3:/opt/hadoop-2.7.3/etc/hadoop/
hdfs-site.xml 100% 2434 2.4KB/s 00:00
[root@node1 hadoop]# scp hadoop-env.sh node2:/opt/hadoop-2.7.3/etc/hadoop/
hadoop-env.sh 100% 4227 4.1KB/s 00:00
[root@node1 hadoop]# scp hadoop-env.sh node3:/opt/hadoop-2.7.3/etc/hadoop/
hadoop-env.sh 100% 4227 4.1KB/s 00:00
[root@node1 hadoop]#