本次实验采用VMware虚拟机,Linux版本为CentOS7;
因为实验所需的5台机器配置大多相同,所以采用配置其中一台,然后使用克隆功能复制另外4份再做具体修改;
其中有些步骤以前配置过,此处就说明一下不再做具体配置,具体配置可翻阅以前的博文。
二、实验环境
1.关闭selinux和firewall
2.Hadoop-2.7.4.tar.gz;zookeeper-3.4.10.tar.gz;jdk-8u131-linux-x64.tar.gz
三、主机规划
IP Host 进程192.168.100.11 hadoop1
NameNode
ResourceManager
DFSZKFailoverController
192.168.100.12 hadoop2
NameNode
ResourceManager
DFSZKFailoverController
192.168.100.13 hadoop3
DataNode
NodeManager
JournalNode
QuorumPeerMain
192.168.100.14 hadoop4
DataNode
NodeManager
JournalNode
QuorumPeerMain
192.168.100.15 hadoop5
DataNode
NodeManager
JournalNode
QuorumPeerMain
四、环境准备
1.设置IP地址:192.168.100.11
2.设置主机名:hadoop1
3.设置IP和主机名的映射
[root@hadoop1 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.100.11 hadoop1
192.168.100.12 hadoop2
192.168.100.13 hadoop3
192.168.100.14 hadoop4
192.168.100.15 hadoop5
4.配置ssh分发脚本
5.解压jdk
[root@hadoop1 ~]# tar -zxf jdk-8u131-linux-x64.tar.gz
[root@hadoop1 ~]# cp -r jdk1.8.0_131/ /usr/local/jdk
6.解压hadoop
[root@hadoop1 ~]# tar -zxf hadoop-2.7.4.tar.gz
[root@hadoop1 ~]# cp -r hadoop-2.7.4 /usr/local/hadoop
7.解压zookeeper
[root@hadoop1 ~]# tar -zxf zookeeper-3.4.10.tar.gz
[root@hadoop1 ~]# cp -r zookeeper-3.4.10 /usr/local/hadoop/zookeeper
[root@hadoop1 ~]# cd /usr/local/hadoop/zookeeper/conf/
[root@hadoop1 conf]# cp zoo_sample.cfg zoo.cfg
[root@hadoop1 conf]# vim zoo.cfg
#修改dataDir
dataDir=/usr/local/hadoop/zookeeper/data
#添加下面三行
server.1=hadoop3:2888:3888
server.2=hadoop4:2888:3888
server.3=hadoop5:2888:3888
[root@hadoop1 conf]# cd ..
[root@hadoop1 zookeeper]# mkdir data
#此处还有操作,但是hadoop1上不部署zookeeper模块所以后面再修改
8.配置环境变量
[root@hadoop1 ~]# tail -4 /etc/profile
export Java_HOME=/usr/local/jdk
export HADOOP_HOME=/usr/local/hadoop
export ZOOKEEPER_HOME=/usr/local/hadoop/zookeeper
export PATH=.:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin:$PATH
[root@hadoop1 ~]# source /etc/profile
9.测试环境变量可用
[root@hadoop1 ~]# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
[root@hadoop1 ~]# hadoop version
Hadoop 2.7.4
Subversion Unknown -r Unknown
Compiled by root on 2017-08-28T09:30Z
Compiled with protoc 2.5.0
From source with checksum 50b0468318b4ce9bd24dc467b7ce1148
This command was run using /usr/local/hadoop/share/hadoop/common/hadoop-common-2.7.4.jar
五、配置hadoop
1.core-site.xml
<configuration>
<!-- 指定hdfs的nameservice为master -->
<property>
<name>fs.defaultFS</name>
<value>hdfs://master/</value>
</property>
<!-- 指定hadoop临时目录 -->
<property>
<name>hadoop.tmp.dir</name>
<value>/usr/local/hadoop/tmp</value>
</property>
<!-- 指定zookeeper地址 -->
<property>
<name>ha.zookeeper.quorum</name>
<value>hadoop3:2181,hadoop4:2181,hadoop5:2181</value>
</property>
</configuration>
2.hdfs-site.xml
<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>/usr/local/hadoop/dfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/usr/local/hadoop/dfs/data</value>
</property>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
<!--HDFS高可用配置 -->
<!--指定hdfs的nameservice,需要和core-site.xml中的保持一致-->
<property>
<name>dfs.nameservices</name>
<value>master</value>
</property>
<!--指定master的两个namenode的名称 -->
<property>
<name>dfs.ha.namenodes.master</name>
<value>nn1,nn2</value>
</property>
<!-- nn1,nn2 rpc 通信地址 -->
<property>
<name>dfs.namenode.rpc-address.master.nn1</name>
<value>hadoop1:9000</value>
</property>
<property>
<name>dfs.namenode.rpc-address.master.nn2</name>
<value>hadoop2:9000</value>
</property>
<!-- nn1.nn2 http 通信地址 -->
<property>
<name>dfs.namenode.http-address.master.nn1</name>
<value>hadoop1:50070</value>
</property>
<property>
<name>dfs.namenode.http-address.master.nn2</name>
<value>hadoop2:50070</value>
</property>
<!--=========Namenode同步==========-->
<!--保证数据恢复 -->
<property>
<name>dfs.journalnode.http-address</name>
<value>0.0.0.0:8480</value>
</property>
<property>
<name>dfs.journalnode.rpc-address</name>
<value>0.0.0.0:8485</value>
</property>
<property>
<!--指定NameNode的元数据在JournalNode上的存放位置 -->
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://hadoop3:8485;hadoop4:8485;hadoop5:8485/master</value>
</property>
<property>
<!--JournalNode存放数据地址 -->
<name>dfs.journalnode.edits.dir</name>
<value>/usr/local/hadoop/dfs/journal</value>
</property>
<property>
<!--NameNode失败自动切换实现方式 -->
<name>dfs.client.failover.proxy.provider.master</name>
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
</property>
<!--=========Namenode fencing:======== -->
<!-- 配置隔离机制方法,多个机制用换行分割,即每个机制暂用一行 -->
<property>
<name>dfs.ha.fencing.methods</name>
<value>sshfence
shell(/bin/true)</value>
</property>
<!-- 使用sshfence隔离机制时需要ssh免登陆 -->
<property>
<name>dfs.ha.fencing.ssh.private-key-files</name>
<value>/root/.ssh/id_rsa</value>
</property>
<!-- 配置sshfence隔离机制超时时间 -->
<property>
<name>dfs.ha.fencing.ssh.connect-timeout</name>
<value>30000</value>
</property>
<!--开启基于Zookeeper及ZKFC进程的自动备援设置,监视进程是否死掉 -->
<property>
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
<property>
<name>ha.zookeeper.quorum</name>
<value>hadoop3:2181,hadoop4:2181,hadoop5:2181</value>
</property>
<property>
<!--指定ZooKeeper超时间隔,单位毫秒 -->
<name>ha.zookeeper.session-timeout.ms</name>
<value>2000</value>
</property>
</configuration>
3.yarn-site.xml