搭建准备
Centos 7 主机三台
主机名 | IP 地址 |
---|---|
master | 192.168.1.121 |
slave1 | 192.168.1.122 |
slave2 | 192.168.1.123 |
软件版本
软件名称 | 软件版本 |
---|---|
JDK | 8u261 |
Zookeeper | 3.5.9 |
Hadoop | 2.7.7 |
软件安装
安装包: /home/apps/package
安装路径:/home/apps/
安装步骤
一、关闭防火墙
三个节点防火墙均关闭
[root@master ~]# systemctl stop firewalld
[root@master ~]# systemctl status firewalld
二、解压组件
解压zookeeper
[root@master package]# tar -zxvf apache-zookeeper-3.5.9-bin.tar.gz
解压hadoop-2.7.7.tar.gz
[root@master package]# tar -zxvf hadoop-2.7.7.tar.gz
将Hadoop文件放在/home/apps/下
[root@master package]# pwd
/home/apps/package
[root@master package]# mv hadoop-2.7.7 ../
解压jdk-8u261-linux-x64.tar.gz
[root@master package]# tar -zxvf jdk-8u261-linux-x64.tar.gz
将jdk解压文件放在/home/apps/下
[root@master package]# mv jdk1.8.0_261 jdk1.8
[root@master package]# pwd
/home/apps/package
[root@master package]# mv jdk1.8 ../
三、配置文件
core-site.xml
[root@master hadoop]# vi /home/apps/hadoop-2.7.7/etc/hadoop/core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://ns1</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/home/apps/hdfs/tmp</value>
</property>
<property>
<name>ha.zookeeper.quorum</name>
<value>master,slave1,slave2</value>
</property>
</configuration>
hdfs-site.xml
[root@master hadoop]# vi /home/apps/hadoop-2.7.7/etc/hadoop/hdfs-site.xml
<configuration>
<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>master:9000</value>
</property>
<property>
<name>dfs.namenode.http-address.ns1.nn1</name>
<value>master:50070</value>
</property>
<property>
<name>dfs.namenode.rpc-address.ns1.nn2</name>
<value>slave1:9000</value>
</property>
<property>
<name>dfs.namenode.http-address.ns1.nn2</name>
<value>slave1:50070</value>
</property>
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://master;slave1;slave2/ns1</value>
</property>
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/home/apps/hdfs/journal</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>/home/apps/hdfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/home/apps/hdfs/data</value>
</property>
<property>
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</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
shell(/bin/true)
</value>
</property>
<property>
<name>dfs.ha.fencing.ssh.private-key-files</name>
<value>/root/.ssh/id_rsa</value>
</property>
</configuration>
yarn-site.xml
[root@master hadoop]# vi /home/apps/hadoop-2.7.7/etc/hadoop/yarn-site.xml
<configuration>
<property>
<name>yarn.resourcemanager.ha.enabled</name>
<value>true</value>
</property>
<property>
<name>yarn.resourcemanager.cluster-id</name>
<value>yrc</value>
</property>
<property>
<name>yarn.resourcemanager.ha.rm-ids</name>
<value>rm1,rm2</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm1</name>
<value>slave1</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm2</name>
<value>slave2</value>
</property>
<property>
<name>yarn.resourcemanager.zk-address</name>
<value>master,slave1,slave2</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.log-aggregation-enable</name>
<value>true</value>
</property>
</configuration>
mapred-site.xml
[root@master hadoop]# vi /home/apps/hadoop-2.7.7/etc/hadoop/mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>yarn.app.mapreduce.am.staging-dir</name>
<value>/home/apps/hdfs/history</value>
</property>
</configuration>
slaves
[root@master hadoop]# vi /home/apps/hadoop-2.7.7/etc/hadoop/slaves
slave1
slave2
四、环境变量
设置全局环境变量
三台主机都要设置
/etc/profile
[root@master hadoop]# vi /etc/profile
export JAVA_HOME=/home/apps/jdk1.8
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export HADOOP_HOME=/home/apps/hadoop-2.7.7
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
[root@master hadoop]# source /etc/profile
hadoop-env.sh环境变量
hadoop-env.sh
[root@master hadoop]# vi /home/apps/hadoop-2.7.7/etc/hadoop/hadoop-env.sh
export HADOOP_HOME=/home/apps/hadoop-2.7.7/
export HADOOP_CONF_DIR=/home/apps/hadoop-2.7.7/etc/hadoop
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
[root@master hadoop]# source /home/apps/hadoop-2.7.7/etc/hadoop/hadoop-env.sh
五、发送到其他两个节点
hadoop文件
[root@master hadoop]# scp -r /home/apps/hadoop slave1:/home/apps/
[root@master hadoop]# scp -r /home/apps/hadoop slave2:/home/apps/
JDK文件
[root@master apps]# scp -r /home/apps/jdk1.8 slave1:/home/apps/
[root@master apps]# scp -r /home/apps/jdk1.8 slave2:/home/apps/
在其他两个节点上面使环境变量立即生效
- slave1
[root@slave1 hadoop]# source /home/apps/hadoop-2.7.7/etc/hadoop/hadoop-env.sh
[root@slave1 hadoop]# source /etc/profile
- slave2
[root@slave2 hadoop]# source /home/apps/hadoop-2.7.7/etc/hadoop/hadoop-env.sh
[root@slave1 hadoop]# source /etc/profile
六、初始化HDFS
- 三台机器都要启动
[root@master hadoop]# hadoop-daemon.sh start journalnode
- 在master节点上面对HDFS和zookeeper进行格式化
[root@master apps]# hdfs namenode -format
[root@master apps]# hdfs zkfc -formatZK
[root@master apps]# hadoop-daemon.sh start namenode
- 在节点slave1上面将master格式化的元目录同步到slave1上
[root@slave1 ~]# hdfs namenode -bootstrapStandby
七、启动Hadoop
- master
[root@master apps]# start-dfs.sh
[root@master apps]# mr-jobhistory-daemon.sh start historyserver
- slave1
[root@slave1 ~]# start-yarn.sh
[root@master apps]# mr-jobhistory-daemon.sh start historyserver
- slave2
[root@slave2 ~]# yarn-daemon.sh start resourcemanager
[root@master apps]# mr-jobhistory-daemon.sh start historyserver
启动结果
- master
[root@master ~]# jps
2454 NameNode
2154 DataNode
3215 Jps
2541 QuorumPeerMain
2231 DFSZKFailoverController
55412 JobHistoryServer
45751 JournalNode
- slave1
[root@slave1 ~]# jps
3249 NodeManager
2403 DFSZKFailoverController
2292 DataNode
1926 JournalNode
1800 QuorumPeerMain
2201 NameNode
2940 JobHistoryServer
3724 Jps
3437 ResourceManager
- slave2
[root@slave2 ~]# jps
2456 QuorumPeerMain
11547 NodeManager
54978 Jps
54121 JournalNode
21544 ResourceManager
22124 DataNode
1445 JobHistoryServer
结语:大数据笔记 Hadoop HA 搭建