(1)修改IP
(2)修改主机名及主机名和IP地址的映射
(3)关闭防火墙
(4)ssh免密登录
(5)安装JDK,配置环境变量等
hadoop102 | hadoop103 | hadoop104 |
---|---|---|
NameNode | NameNode | NameNode |
ZKFC | ZKFC | ZKFC |
JournalNode | JournalNode | JournalNode |
DataNode | DataNode | DataNode |
ZK | ZK | ZK |
ResourceManager | ResourceManager | ResourceManager |
NodeManager | NodeManager | NodeManager |
1)集群规划
在hadoop102、hadoop103和hadoop104三个节点上部署Zookeeper。
2)解压安装
(1)解压Zookeeper安装包到/opt/module/目录下
[qinjl@hadoop102 software]$ tar -zxvf zookeeper-3.5.7.tar.gz -C /opt/module/
(2)在/opt/module/zookeeper-3.5.7/这个目录下创建zkData
[qinjl@hadoop102 zookeeper-3.5.7]$ mkdir -p zkData
(3)重命名/opt/module/zookeeper-3.4.14/conf这个目录下的zoo_sample.cfg为zoo.cfg
[qinjl@hadoop102 conf]$ mv zoo_sample.cfg zoo.cfg
3)配置zoo.cfg文件
(1)具体配置
dataDir=/opt/module/zookeeper-3.5.7/zkData
增加如下配置
#######################cluster##########################
server.2=hadoop102:2888:3888
server.3=hadoop103:2888:3888
server.4=hadoop104:2888:3888
(2)配置参数解读
Server.A=B:C:D
A:是一个数字,表示这个是第几号服务器;
B:是这个服务器的IP地址;
C:是这个服务器与集群中的Leader服务器交换信息的端口;
D:是万一集群中的Leader服务器挂了,需要一个端口来重新进行选举,选出一个新的Leader,而这个端口就是用来执行选举时服务器相互通信的端口。
集群模式下配置一个文件myid,这个文件在dataDir目录下,这个文件里面有一个数据就是A的值,Zookeeper启动时读取此文件,拿到里面的数据与zoo.cfg里面的配置信息比较从而判断到底是哪个server。
4)集群操作
(1)在/opt/module/zookeeper-3.5.7/zkData目录下创建一个myid的文件
[qinjl@hadoop102 zkData]$ touch myid
添加myid文件,注意一定要在linux里面创建,在notepad++里面很可能乱码
(2)编辑myid文件
[qinjl@hadoop102 zkData]$ vi myid
在文件中添加与server对应的编号:如2
(3)拷贝配置好的zookeeper到其他机器上
[qinjl@hadoop102 module]$ scp -r zookeeper-3.5.7/ qinjl@hadoop103:/opt/module/
[qinjl@hadoop102 module]$ scp -r zookeeper-3.5.7/ qinjl@hadoop104:/opt/module/
并分别修改myid文件中内容为3、4
(4)分别启动zookeeper
[qinjl@hadoop102 zookeeper-3.5.7]$ bin/zkServer.sh start
[qinjl@hadoop103 zookeeper-3.5.7]$ bin/zkServer.sh start
[qinjl@hadoop104 zookeeper-3.5.7]$ bin/zkServer.sh start
(5)查看状态
[qinjl@hadoop102 zookeeper-3.5.7]$ bin/zkServer.sh status
JMX enabled by default
Using config: /opt/module/zookeeper-3.5.7/bin/../conf/zoo.cfg
Mode: follower
[qinjl@hadoop103 zookeeper-3.5.7]$ bin/zkServer.sh status
JMX enabled by default
Using config: /opt/module/zookeeper-3.5.7/bin/../conf/zoo.cfg
Mode: leader
[qinjl@hadoop104 zookeeper-3.5.7]$ bin/zkServer.sh status
JMX enabled by default
Using config: /opt/module/zookeeper-3.5.7/bin/../conf/zoo.cfg
Mode: follower
1)官方地址:http://hadoop.apache.org/
2)在opt目录下创建一个ha文件夹
[qinjl@hadoop102 ~]$ cd /opt
[qinjl@hadoop102 opt]$ sudo mkdir ha
[qinjl@hadoop102 opt]$ sudo chown qinjl:qinjl /opt/ha
3)将/opt/module/下的 hadoop-3.1.3拷贝到/opt/ha目录下(记得删除data 和 log目录)
[qinjl@hadoop102 opt]$ cp -r /opt/module/hadoop-3.1.3 /opt/ha/
4)配置hadoop-env.sh
export JAVA_HOME=/opt/module/jdk1.8.0_212
5)配置core-site.xml
<configuration>
<property>
<name>fs.defaultFSname>
<value>hdfs://myclustervalue>
property>
<property>
<name>hadoop.tmp.dirname>
<value>/opt/ha/hadoop-3.1.3/datavalue>
property>
configuration>
6)配置hdfs-site.xml
<configuration>
<property>
<name>dfs.namenode.name.dirname>
<value>file://${hadoop.tmp.dir}/namevalue>
property>
<property>
<name>dfs.datanode.data.dirname>
<value>file://${hadoop.tmp.dir}/datavalue>
property>
<property>
<name>dfs.journalnode.edits.dirname>
<value>${hadoop.tmp.dir}/jnvalue>
property>
<property>
<name>dfs.nameservicesname>
<value>myclustervalue>
property>
<property>
<name>dfs.ha.namenodes.myclustername>
<value>nn1,nn2,nn3value>
property>
<property>
<name>dfs.namenode.rpc-address.mycluster.nn1name>
<value>hadoop102:8020value>
property>
<property>
<name>dfs.namenode.rpc-address.mycluster.nn2name>
<value>hadoop103:8020value>
property>
<property>
<name>dfs.namenode.rpc-address.mycluster.nn3name>
<value>hadoop104:8020value>
property>
<property>
<name>dfs.namenode.http-address.mycluster.nn1name>
<value>hadoop102:9870value>
property>
<property>
<name>dfs.namenode.http-address.mycluster.nn2name>
<value>hadoop103:9870value>
property>
<property>
<name>dfs.namenode.http-address.mycluster.nn3name>
<value>hadoop104:9870value>
property>
<property>
<name>dfs.namenode.shared.edits.dirname>
<value>qjournal://hadoop102:8485;hadoop103:8485;hadoop104:8485/myclustervalue>
property>
<property>
<name>dfs.client.failover.proxy.provider.myclustername>
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvidervalue>
property>
<property>
<name>dfs.ha.fencing.methodsname>
<value>sshfencevalue>
property>
<property>
<name>dfs.ha.fencing.ssh.private-key-filesname>
<value>/home/qinjl/.ssh/id_rsavalue>
property>
configuration>
7)分发配置好的hadoop环境到其他节点
1)将HADOOP_HOME环境变量更改到HA目录
[qinjl@hadoop102 ~]$ sudo vim /etc/profile.d/my_env.sh
将HADOOP_HOME部分改为如下
##HADOOP_HOME
export HADOOP_HOME=/opt/ha/hadoop-3.1.3
export PATH=$PATH:$HADOOP_HOME/bin
export PATH=$PATH:$HADOOP_HOME/sbin
2)在各个JournalNode节点上,输入以下命令启动journalnode服务
[qinjl@hadoop102 ~]$ hdfs --daemon start journalnode
[qinjl@hadoop103 ~]$ hdfs --daemon start journalnode
[qinjl@hadoop104 ~]$ hdfs --daemon start journalnode
3)在[nn1]上,对其进行格式化,并启动
[qinjl@hadoop102 ~]$ hdfs namenode -format
[qinjl@hadoop102 ~]$ hdfs --daemon start namenode
4)在[nn2]和[nn3]上,同步nn1的元数据信息
[qinjl@hadoop103 ~]$ hdfs namenode -bootstrapStandby
[qinjl@hadoop104 ~]$ hdfs namenode -bootstrapStandby
5)启动[nn2]和[nn3]
[qinjl@hadoop103 ~]$ hdfs --daemon start namenode
[qinjl@hadoop104 ~]$ hdfs --daemon start namenode
6)查看web页面显示
全部节点的状态为standby
7)在所有节点上,启动datanode
[qinjl@hadoop102 ~]$ hdfs --daemon start datanode
[qinjl@hadoop103 ~]$ hdfs --daemon start datanode
[qinjl@hadoop104 ~]$ hdfs --daemon start datanode
8)将[nn1]切换为Active
[qinjl@hadoop102 ~]$ hdfs haadmin -transitionToActive nn1
9)查看是否Active
[qinjl@hadoop102 ~]$ hdfs haadmin -getServiceState nn1
1)具体配置
(1)在hdfs-site.xml中增加
<property>
<name>dfs.ha.automatic-failover.enabledname>
<value>truevalue>
property>
(2)在core-site.xml文件中增加
<property>
<name>ha.zookeeper.quorumname>
<value>hadoop102:2181,hadoop103:2181,hadoop104:2181value>
property>
(3)修改后分发配置文件
[qinjl@hadoop102 etc]$ pwd
/opt/ha/hadoop-3.1.3/etc
[qinjl@hadoop102 etc]$ xsync hadoop/
2)启动
(1)关闭所有HDFS服务:
[qinjl@hadoop102 ~]$ stop-dfs.sh
(2)启动Zookeeper集群:
[qinjl@hadoop102 ~]$ zkServer.sh start
[qinjl@hadoop103 ~]$ zkServer.sh start
[qinjl@hadoop104 ~]$ zkServer.sh start
(3)启动Zookeeper以后,然后再初始化HA在Zookeeper中状态:
[qinjl@hadoop102 ~]$ hdfs zkfc -formatZK
(4)启动HDFS服务:
[qinjl@hadoop102 ~]$ start-dfs.sh
(5)可以去zkCli.sh客户端查看Namenode选举锁节点内容:
[zk: localhost:2181(CONNECTED) 7] get -s /hadoop-ha/mycluster/ActiveStandbyElectorLock
myclusternn2 hadoop103 �>(�>
cZxid = 0x10000000b
ctime = Tue Jul 14 17:00:13 CST 2020
mZxid = 0x10000000b
mtime = Tue Jul 14 17:00:13 CST 2020
pZxid = 0x10000000b
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x40000da2eb70000
dataLength = 33
numChildren = 0
3)验证
(1)将Active NameNode进程kill,查看网页端三台Namenode的状态变化
[qinjl@hadoop102 ~]$ kill -9 namenode的进程id
1)官方文档:
http://hadoop.apache.org/docs/r3.1.3/hadoop-yarn/hadoop-yarn-site/ResourceManagerHA.html
2)YARN-HA工作机制
1)具体配置
(1)yarn-site.xml
<configuration>
<property>
<name>yarn.nodemanager.aux-servicesname>
<value>mapreduce_shufflevalue>
property>
<property>
<name>yarn.resourcemanager.ha.enabledname>
<value>truevalue>
property>
<property>
<name>yarn.resourcemanager.cluster-idname>
<value>cluster-yarn1value>
property>
<property>
<name>yarn.resourcemanager.ha.rm-idsname>
<value>rm1,rm2,rm3value>
property>
<property>
<name>yarn.resourcemanager.hostname.rm1name>
<value>hadoop102value>
property>
<property>
<name>yarn.resourcemanager.webapp.address.rm1name>
<value>hadoop102:8088value>
property>
<property>
<name>yarn.resourcemanager.address.rm1name>
<value>hadoop102:8032value>
property>
<property>
<name>yarn.resourcemanager.scheduler.address.rm1name>
<value>hadoop102:8030value>
property>
<property>
<name>yarn.resourcemanager.resource-tracker.address.rm1name>
<value>hadoop102:8031value>
property>
<property>
<name>yarn.resourcemanager.hostname.rm2name>
<value>hadoop103value>
property>
<property>
<name>yarn.resourcemanager.webapp.address.rm2name>
<value>hadoop103:8088value>
property>
<property>
<name>yarn.resourcemanager.address.rm2name>
<value>hadoop103:8032value>
property>
<property>
<name>yarn.resourcemanager.scheduler.address.rm2name>
<value>hadoop103:8030value>
property>
<property>
<name>yarn.resourcemanager.resource-tracker.address.rm2name>
<value>hadoop103:8031value>
property>
<property>
<name>yarn.resourcemanager.hostname.rm3name>
<value>hadoop104value>
property>
<property>
<name>yarn.resourcemanager.webapp.address.rm3name>
<value>hadoop104:8088value>
property>
<property>
<name>yarn.resourcemanager.address.rm3name>
<value>hadoop104:8032value>
property>
<property>
<name>yarn.resourcemanager.scheduler.address.rm3name>
<value>hadoop104:8030value>
property>
<property>
<name>yarn.resourcemanager.resource-tracker.address.rm3name>
<value>hadoop104:8031value>
property>
<property>
<name>yarn.resourcemanager.zk-addressname>
<value>hadoop102:2181,hadoop103:2181,hadoop104:2181value>
property>
<property>
<name>yarn.resourcemanager.recovery.enabledname>
<value>truevalue>
property>
<property>
<name>yarn.resourcemanager.store.classname>
<value>org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStorevalue>
property>
<property>
<name>yarn.nodemanager.env-whitelistname>
<value>JAVA_HOME,HADOOP_COMMON_HOME,HADOOP_HDFS_HOME,HADOOP_CONF_DIR,CLASSPATH_PREPEND_DISTCACHE,HADOOP_YARN_HOME,HADOOP_MAPRED_HOMEvalue>
property>
configuration>
(2)同步更新其他节点的配置信息,分发配置文件
[qinjl@hadoop102 etc]$ xsync hadoop/
2)启动hdfs
[qinjl@hadoop102 ~]$ start-dfs.sh
3)启动YARN
(1)在hadoop102或者hadoop103、hodoop104中执行:
[qinjl@hadoop102 ~]$ start-yarn.sh
(2)查看服务状态
[qinjl@hadoop102 ~]$ yarn rmadmin -getServiceState rm1
(3)可以去zkCli.sh客户端查看ResourceManager选举锁节点内容:
[qinjl@hadoop102 ~]$ zkCli.sh
[zk: localhost:2181(CONNECTED) 16] get -s /yarn-leader-election/cluster-yarn1/ActiveStandbyElectorLock
cluster-yarn1rm1
cZxid = 0x100000022
ctime = Tue Jul 14 17:06:44 CST 2020
mZxid = 0x100000022
mtime = Tue Jul 14 17:06:44 CST 2020
pZxid = 0x100000022
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x30000da33080005
dataLength = 20
numChildren = 0