Hadoop 分布式高可用集群部署

网友投稿 278 2022-11-20

Hadoop 分布式高可用集群部署

一、集群环境说明

1、主机规划

IP地址 角色 服务组件
172.16.1.15 NameNode NameNode、JournalNode、Zookeeper、ZKFC
172.16.1.16 NameNode NameNode、JournalNode、Zookeeper、ZKFC、DataNode、NodeManager
172.16.1.17 ResourceManager DataNode、JournalNode、Zookeeper、NodeManager、ResourceManager
172.16.1.18 ResourceManager DataNode、NodeManager、ResourceManager

2、规划说明

关于高可用的分布式集群Hadoop集群的部署实验,最少服务器数量是三台,本次使用的四台主机 广义上说的 Hadoop 集群 ,其实是包括 Hadoop 和 Yarn 两个集群,下面多次提到 Hadoop集群,有些是说的大部分是指广义上的 Hadoop 集群,要知道区分 关于上面表格里面,对于规划主机的各个角色,都是可以进行调整的,如果使用三台主机,主机充当的角色又会不一样,这些取决于自己对主机的规划 有些实验环境里面,Namenode 的主节点也会存放 Datanode 数据,这个不影响实验的实现,但是一般的 Namenode的主节点,是不会用存放业务数据的,在具体环境里面里面的话,还得得看具体的配置而定

二、安装前准备

1、系统初始化相关准备 ( 四个节点都进行相同的操作 )

1)安装基本的系统命令包

[root@hadoop01 ~]# yum -y install epel-release [root@hadoop01 ~]# yum -y install net-tools gcc gcc-c++ lrzsz vim wget curl git zip unzip ntp telnet

2)关闭 SELINUX 、防火墙

[root@hadoop01 ~]# setenforce 0 [root@hadoop01 ~]# sed -i 's/enforcing/disabled/' /etc/selinux/config [root@hadoop01 ~]# systemctl stop firewalld && systemctl disable firewalld

3)配置主机名、添加解析

[root@hadoop01 ~]# hostnamectl set-hostname hadoop01 [root@hadoop02 ~]# hostnamectl set-hostname hadoop02 [root@hadoop03 ~]# hostnamectl set-hostname hadoop03 [root@hadoop04 ~]# hostnamectl set-hostname hadoop04 [root@hadoop01 ~]# vim /etc/hosts 172.16.1.15 hadoop01 172.16.1.16 hadoop02 172.16.1.17 hadoop03 172.16.1.18 hadoop04

4)配置时间同步

[root@hadoop01 ~]# \cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime [root@hadoop01 ~]# ntpdate ntp.aliyun.com [root@hadoop01 ~]# systemctl start ntpdate && systemctl enable ntpdate

2、安装配置 JDK

1)安装 JDK

[root@hadoop01 ~]# tar -zxvf jdk-8u131-linux-x64.tar.gz -C /usr/local/ [root@hadoop01 ~]# cd /usr/local/jdk1.8.0_131/bin [root@hadoop01 ~]# ./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)

2)配置环境变量

[root@hadoop01 ~]# cp /etc/profile /etc/profile.bak [root@hadoop01 ~]# vim /etc/profile # 文本末尾追加下面两行 export JAVA_HOME=/usr/local/jdk1.8.0_131 export PATH=.:$PATH:$JAVA_HOME/bin [root@hadoop01 ~]# source /etc/profile [root@hadoop01 ~]# 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) ### 其他三个节点 hadoop02 、hadoop03 、 hadoop04 同样的操作

3、配置 SSH 互信

​ 1)配置 SSH 免密登录

[root@hadoop01 ~]# ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa [root@hadoop01 ~]# ssh-copy-id hadoop01 [root@hadoop01 ~]# ssh-copy-id hadoop02 [root@hadoop01 ~]# ssh-copy-id hadoop03 [root@hadoop01 ~]# ssh-copy-id hadoop04 ### 其他三个节点 hadoop02 、hadoop03 、 hadoop04 同样的操作

​ 2)测试下免密登录

[root@hadoop01 ~]# ssh hadoop01 [root@hadoop01 ~]# ssh hadoop02 [root@hadoop01 ~]# ssh hadoop03 [root@hadoop01 ~]# ssh hadoop04 ### 其他三个节点 hadoop02 、hadoop03 、 hadoop04 同样的操作

4、安装 Zookeeper 集群

​ 1)安装集群

[root@hadoop01 ~]# tar -zxvf zookeeper-3.4.14.tar.gz -C /usr/local/ [root@hadoop01 ~]# mv /usr/local/zookeeper-3.4.14 /usr/local/zookeeper [root@hadoop01 ~]# cd /usr/local/zookeeper/conf [root@hadoop01 ~]# cp zoo_sample.cfg zoo.cfg [root@hadoop01 ~]# vim zoo.cfg ... ... dataDir=/data/zookeeper/data dataLogDir=/data/zookeeper/logs server.1=hadoop01:2888:3888 server.2=hadoop02:2888:3888 server.3=hadoop03:2888:3888 [root@hadoop01 ~]# scp -r /usr/local/zookeeper hadoop02:/usr/local [root@hadoop01 ~]# scp -r /usr/local/zookeeper hadoop03:/usr/local [root@hadoop01 ~]# mkdir -p /data/zookeeper/{data,logs} [root@hadoop01 ~]# scp -r /data hadoop02:/ [root@hadoop01 ~]# scp -r /data hadoop03:/ [root@hadoop01 ~]# echo "1" > /data/zookeeper/data/myid [root@hadoop02 ~]# echo "2" > /data/zookeeper/data/myid [root@hadoop03 ~]# echo "3" > /data/zookeeper/data/myid

​ 2) 启动集群

[root@hadoop01 ~]# cd /usr/local/zookeeper/bin/ [root@hadoop01 ~]# zkServer.sh start [root@hadoop02 ~]# cd /usr/local/zookeeper/bin/ [root@hadoop02 ~]# zkServer.sh start [root@hadoop03 ~]# cd /usr/local/zookeeper/bin/ [root@hadoop03 ~]# zkServer.sh start

​ 3)验证集群启动情况

[root@hadoop01 ~]# cd /usr/local/zookeeper/bin/ [root@hadoop01 bin]# zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg Mode: follower [root@hadoop02 ~]# cd /usr/local/zookeeper/bin/ [root@hadoop02 bin]# zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg Mode: leader [root@hadoop03 ~]# cd /usr/local/zookeeper/bin/ [root@hadoop03 bin]# zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg Mode: follower

​ 4)配置环境变量

[root@hadoop01 ~]# cat << EOF >> /etc/profile > export ZOOKEEPER_HOME=/usr/local/zookeeper > export PATH=.:$PATH:$ZOOKEEPER_HOME/bin > EOF [root@hadoop01 ~]# source /etc/profile [root@hadoop01 ~]# zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg Mode: follower ### 同样的操作在 hadoop02 ,hadoop03 上执行一次,注意,这里没有 hadoop04

三、安装部署

1、上传并解压缩安装包

[root@hadoop01 ~]# tar -zxvf hadoop-2.7.3.tar.gz -C /usr/local/ [root@hadoop01 ~]# mv hadoop-2.7.3 hadoop [root@hadoop01 ~]# cd /usr/local/hadoop/etc/hadoop/

2、修改相关配置文件

[root@hadoop01 hadoop]# cp hadoop-env.sh hadoop-env.sh.default [root@hadoop01 hadoop]# vim hadoop-env.sh export JAVA_HOME=/usr/local/jdk1.8.0_131

[root@hadoop01 hadoop]# cp yarn-env.sh yarn-env.sh.default [root@hadoop01 hadoop]# vim yarn-env.sh export JAVA_HOME=/usr/local/jdk1.8.0_131

[root@hadoop01 hadoop]# cp core-site.xml core-site.xml.default [root@hadoop01 hadoop]# vim core-site.xml     fs.defaultFS      hdfs://myhadoop       hadoop.tmp.dir       /data/hadoop/tmpdata io.file.buffer.size 4096 ha.zookeeper.quorum hadoop01:2181,hadoop02:2181,hadoop03:2181 ha.zookeeper.session-timeout.ms 1000 hadoop.proxyuser.hadoop.hosts * hadoop.proxyuser.hadoop.groups *

[root@hadoop01 hadoop]# cp hdfs-site.xml hdfs-site.xml.default [root@hadoop01 hadoop]# vim hdfs-site.xml dfs.nameservices myhadoop dfs.namenode.name.dir /data/hadoop/data/namenode dfs.datanode.data.dir /home/hadoop/data/datanode dfs.ha.namenodes.myhadoop nn1,nn2 dfs.namenode.rpc-address.myhadoop.nn1 hadoop01:8020 dfs.namenode.rpc-address.myhadoop.nn2 hadoop02:8020 dfs.namenode.http-address.myhadoop.nn1 hadoop01:50070 dfs.namenode.http-address.myhadoop.nn2 hadoop02:50070 dfs.namenode.shared.edits.dir qjournal://hadoop01:8485;hadoop02:8485;hadoop03:8485/myhadoop dfs.journalnode.edits.dir /data/hadoop/data/journalnode dfs.client.failover.proxy.provider.ns org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider dfs.ha.fencing.methods sshfence shell(/bin/true) dfs.ha.fencing.ssh.connect-timeout 30000 ha.failover-controller.cli-check.rpc-timeout.ms 60000 dfs.ha.fencing.ssh.private-key-files /root/.ssh/id_rsa dfs.ha.automatic-failover.enabled true dfs.permissions.enabled false dfs.webhdfs.enabled true dfs.replication 2 dfs.blocksize 134217728

[root@hadoop01 hadoop]# cp mapred-queues.xml.template mapred-site.xml [root@hadoop01 hadoop]# vim mapred-site.xml mapreduce.framework.name yarn       mapreduce.map.output.compress       true           mapreduce.map.output.compress.codec       org.apache.hadoop.io.compress.SnappyCodec    

[root@hadoop01 hadoop]# vim slaves slaves.default [root@hadoop01 hadoop]# vim slaves hadoop02 hadoop03 hadoop04

3、创建相关的数据目录

[root@hadoop01 ~]# cd /data # 定义的数据存放路径 ( Zookeeper 也是这个路径 ) [root@hadoop01 data]# mkdir -pv hadoop/{data,tmpdata} [root@hadoop01 data]# mkdir -pv hadoop/data/{namenode,datanode,journalnode}

4、传送 hadoop目录到其他节点

[root@hadoop01 ~]# scp -r /usr/local/hadoop hadoop02:/usr/local [root@hadoop01 ~]# scp -r /usr/local/hadoop hadoop03:/usr/local [root@hadoop01 ~]# scp -r /usr/local/hadoop hadoop04:/usr/local [root@hadoop01 ~]# scp -r /data/hadoop hadoop02:/data [root@hadoop01 ~]# scp -r /data/hadoop hadoop03:/data [root@hadoop01 ~]# scp -r /data/hadoop hadoop04:/data

5、配置 HADOOP 环境变量

[root@hadoop01 ~]# vim /etc/profile export HADOOP_HOME=/usr/local/hadoop export PATH=.:$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin [root@hadoop01 ~]# source /etc/profile ### 其他三个节点 hadoop02 、hadoop03 、 hadoop04 同样的操作

四、初始化并启动集群

1、确认 Zookeeper 集群正常运行

[root@hadoop01 ~]# zkServer.sh status [root@hadoop02 ~]# zkServer.sh status [root@hadoop03 ~]# zkServer.sh status

2、启动 journalnode 节点进程

[root@hadoop01 ~]# hadoop-daemon.sh start journalnode [root@hadoop02 ~]# hadoop-daemon.sh start journalnode [root@hadoop03 ~]# hadoop-daemon.sh start journalnode

3、初始化 集群

1、在其中一个 Namenode 的主节点操作 ( 按照主机规划这里是 hadoop01 主机 ) [root@hadoop01 ~]# hdfs namenode -format [root@hadoop01 ~]# hdfs zkfc -formatZK [root@hadoop01 ~]# hadoop-daemon.sh start namenode 2、在 Namenode 的从节点上操作 ( 按照主机规划这里是 hadoop02 主机 ) [root@hadoop02 ~]# hdfs namenode -bootstrapStandby

4、启动集群

1、启动集群 [root@hadoop01 ~]# start-dfs.sh ( 启动 hadoop 集群,在 hadoop01 上操作 ) [root@hadoop03 ~]# start-yarn.sh ( 启动 yarn 集群,在 hadoop03 或者 hadoop04 上操作 ) ### 可以直接在 hadoop01 上执行 start-all.sh ,效果等同于上面两个命令 2、相关命令的说明 1)启动和停止命令 start-dfs.sh 、stop-dfs.sh 启动和停止所有HDFS集群相关的守护进程 start-yarn.sh 、stop-yarn.sh 启动和停止所有YARN集群相关的守护进程 2)替代命令 start-all.sh 、stop-all.sh 命令的效果等同于上面两个启动和停止命令 3)当个进程启动命令 ( 较少使用 ) hadoop-daemon.sh start/stop XXX 、yarn-daemon.sh start/stop XXX

5、查看集群相关进程

[root@hadoop01 ~]# jps 20929 Jps 12468 QuorumPeerMain 19700 NameNode 19913 JournalNode 20094 DFSZKFailoverController [root@hadoop02 ~]# jps 16658 NodeManager 15734 DataNode 15830 JournalNode 16104 DFSZKFailoverController 11291 QuorumPeerMain 15660 NameNode 18559 Jps [root@hadoop03 ~]# jps 14576 DataNode 14672 JournalNode 15904 ResourceManager 16018 NodeManager 16405 Jps 11310 QuorumPeerMain [root@hadoop04 ~]# jps 13703 ResourceManager 13209 DataNode 14075 NodeManager 14382 Jps

五、浏览器访问验证

1、访问HDFS集群 ( 、 )

2、访问 YARN 集群 ( 、)

六、命令查看集群的主备状态

1、HDFS 集群节点状态查看

[root@hadoop01 ~]# hdfs haadmin -getServiceState nn1 active [root@hadoop01 ~]# hdfs haadmin -getServiceState nn2 standby

2、YARN 集群节点状态查看

[root@hadoop03 ~]# yarn rmadmin -getServiceState rm1 standby [root@hadoop03 ~]# yarn rmadmin -getServiceState rm2 active

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:基于Windows CE的SPI接口驱动程序设计
下一篇:如何使用 DragonBoard 410c 低速扩展接口控制 LED 灯
相关文章

 发表评论

暂时没有评论,来抢沙发吧~