当前位置: 代码迷 >> 综合 >> Hadoop2.7.2分布式集群HA模式安装
  详细解决方案

Hadoop2.7.2分布式集群HA模式安装

热度:46   发布时间:2023-11-26 21:45:36.0

服务节点分布

node1

NameNode、DFSZKFailoverController(ZKFC)、ResourceManager、JournalNode、ZooKeeper、QuorumPeerMain

node2

NameNode、DFSZKFailoverController(ZKFC)、ResourceManager、JournalNode、ZooKeeper、QuorumPeerMain

node3

DataNode、NodeManager、JournalNode、QuorumPeerMain、ZooKeeper

一、基础环境

1、安装依赖

yum install psmisc -y

2、配置主机名

hostnamectl set-hostname node1
hostnamectl set-hostname node2
hostnamectl set-hostname node3vim /etc/hosts
192.168.137.128 node1
192.168.137.129 node2
192.168.137.130 node3

3、安装JDK

tar zxf /root/jdk1.8.0_101.tar.gz -C /data/
echo 'export PATH=$PATH:/data/jdk1.8.0_101/bin' >>/etc/profile
source /etc/prssofile

4、配置SSH无密码登陆(三台服务器都需要免密)

ssh-keygen
ssh-copy-id -i id_rsa.pub  root@node1

二、安装Zookeeper

1、解压源码包

cd /root/zookeeper-3.4.12/conf
mv zoo_sample.cfg zoo.cfgcp -r zookeeper-3.4.12 /data/zookeeper

2、修改配置文件

#创建 data 文件夹 和 myid 文件
mkdir /data/zookeeper/data
mkdir /data/zookeeper/log
echo "1" >/data/zookeeper/data/myidtickTime=2000
initLimit=15
syncLimit=5
maxClientCnxns=150
autopurge.snapRetainCount=50
autopurge.purgeInterval=24
dataDir=/data/zookeeper/data
dataLogDir=/data/zookeeper/log
clientPort=2181
server.1=node1:5000:5100
server.2=node2:5000:5100
server.3=node3:5000:5100

3、把zookeeper目录复制到其他两个节点

scp -r zookeeper/ root@node2:/data/
scp -r zookeeper/ root@node3:/data/

4、修改myid

node2:
echo "2" >/data/zookeeper/data/myidnode3:
echo "3" >/data/zookeeper/data/myid

三、安装Hadoop2.7.2(首先在node1上安装)

1、解压安装包

mkdir /data/hadoop
mkdir -p /data/hadoop/hdfs
tar zxf hadoop-2.7.2.tar.gz  -C /data/hadoop/

2、设置环境变量

vim /etc/profile
export HADOOP_HOME=/data/hadoop/hadoop-2.7.2
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HADOOP_HOME/lib#使环境变量生效
source /etc/profile

3、配置Hadoop

(1)配置hadoop-env.sh

cd /data/hadoop/hadoop-2.7.2/etc/hadoop
vim hadoop-env.sh
export JAVA_HOME=/data/jdk1.8.0_101

(2)配置yarn-env.sh

vim yarn-env.sh
export JAVA_HOME=/data/jdk1.8.0_101vim mapred-env.sh
export JAVA_HOME=/data/jdk1.8.0_101

(3)配置core-site.xml

<configuration>
<property><name>fs.defaultFS</name><value>hdfs://cluster1</value></property>【这里的值指的是默认的HDFS路径。当有多个HDFS集群同时工作时,集群名称在这里指定!该值来自于hdfs-site.xml中的配置】<property><name>ha.zookeeper.quorum</name><value>node1:2181,node2:2181,node3:2181</value></property>
【这里是ZooKeeper集群的地址和端口。注意,数量一定是奇数,且不少于三个节点】
</configuration>

(4)配置hdfs-site.xml

<configuration><property><name>dfs.replication</name><value>1</value></property>【指定DataNode存储block的副本数量。默认值是3个,我们现在有4个DataNode,该值不大于4即可。】<!-- 设置namenode存放的路径 --><property><name>dfs.namenode.name.dir</name><value>/data/hadoop/hdfs/name</value></property><!-- 设置datanode存放的路径 --><property><name>dfs.datanode.data.dir</name><value>/data/hadoop/hdfs/data</value></property><property><name>dfs.nameservices</name><value>cluster1</value></property>【使用federation时,HDFS集群别名。名字可以随便起,多个集群时相互不重复即可】<property><name>dfs.ha.namenodes.cluster1</name><value>node1,node2</value></property>【指定该集群的namenode的机器】<property><name>dfs.namenode.rpc-address.cluster1.node1</name><value>node1:9000</value></property>【指定hadoop100的RPC地址】<property><name>dfs.namenode.http-address.cluster1.node1</name><value>node1:50070</value></property>【指定hadoop100的http地址】<property><name>dfs.namenode.rpc-address.cluster1.node2</name><value>node2:9000</value></property>【指定hadoop101的RPC地址】<property><name>dfs.namenode.http-address.cluster1.node2</name><value>node2:50070</value></property>【指定hadoop101的http地址】<property><name>dfs.namenode.shared.edits.dir</name><value>qjournal://node1:8485;node2:8485;node3:8485/cluster1</value></property>【指定该集群的两个NameNode共享edits文件目录时,使用的JournalNode集群信息】<property><name>dfs.ha.automatic-failover.enabled.cluster1</name><value>true</value></property>【指定该集群是否启动自动故障恢复,即当NameNode出故障时,是否自动切换到另一台NameNode】<property><name>dfs.client.failover.proxy.provider.cluster1</name><value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value></property>【指定该集群出故障时,哪个实现类负责执行故障切换】<property><name>dfs.ha.fencing.methods</name><value>sshfence</value></property>【一旦需要NameNode切换,使用ssh方式进行操作】<property><name>dfs.ha.fencing.ssh.private-key-files</name><value>/root/.ssh/id_rsa</value></property>【如果使用ssh进行故障切换,使用ssh通信时用的密钥存储的位置】<property><name>dfs.ha.fencing.ssh.connect-timeout</name><value>30000</value></property>
【connect-timeout连接超时】
<property><name>dfs.journalnode.edits.dir</name><value>/data/hadoop/hdfs/jn</value></property>
<property><name>dfs.permissions.enable</name><value>false</value></property>
</configuration>

(5)配置mapred-site.xml

mv mapred-site.xml.template  mapred-site.xml
<configuration>
<property><name>mapreduce.framework.name</name><value>yarn</value>
</property>
</configuration><property>
<name>mapreduce.jobhistory.address</name>
<value>0.0.0.0:10020</value>
</property><property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>0.0.0.0:19888</value>
</property><property><name>mapreduce.jobhistory.joblist.cache.size</name><value>20000</value>
</property>

(6)配置yarn-site.xml

<configuration>
<property><name>yarn.resourcemanager.ha.enabled</name><value>true</value></property>【启动HA高可用性】<property><name>yarn.resourcemanager.cluster-id</name><value>yrc</value></property>【指定resourcemanager的名字】<property><name>yarn.resourcemanager.ha.rm-ids</name><value>rm1,rm2</value></property>【使用了2个resourcemanager,分别指定Resourcemanager的地址】<property><name>yarn.resourcemanager.hostname.rm1</name><value>node1</value></property>【自定ResourceManager1的地址】<property><name>yarn.resourcemanager.hostname.rm2</name><value>node2</value></property>【自定ResourceManager2的地址】<property><name>yarn.resourcemanager.zk-address</name><value>node1:2181,node2:2181,node3:2181</value></property>【制定Zookeeper机器】<property><name>yarn.nodemanager.aux-services</name><value>mapreduce_shuffle</value></property>
【默认】
<property><name>yarn.resourcemanager.webapp.address</name><value>${yarn.resourcemanager.hostname.rm1}:8088</value></property><property><name>yarn.resourcemanager.webapp.address</name><value>${yarn.resourcemanager.hostname.rm2}:8088</value></property>
</configuration>

(7)配置slaves文件

vim $HADOOP_HOME/etc/hadoop/slaves
node1
node2
node3

(8)拷贝安装目录至其他节点

scp -r hadoop/ root@node2:/data
scp -r hadoop/ root@node3:/data

四、启动服务

1、启动zookeeper集群

./zkServer.sh start
#查看状态:一个leader,两个follower
./zkServer.sh status

2、启动Hadoop

(1)启动journalnode(node1、node2、node3)

hadoop-daemon.sh start journalnode

(2)格式化namenode(node-1)

hdfs namenode -format

(3)格式化ZKFC(在node-1上执行)

hdfs zkfc -formatZK

(4)启动NameNode和DataNode

hadoop-daemon.sh start namenode
hadoop-daemon.sh start datanode

(5)NameNode从node1同步到node2

#在node2执行
hdfs namenode -bootstrapstandby

(6)启动hdfs(hadoop-1执行)

start-dfs.sh

(7)启动ZookeeperFailoverController(hadoop-1、hadoop-2执行)

hadoop-daemon.sh start zkfc

(8)启动yarn resourcemanager(node1、node2)

yarn-daemon.sh  start resourcemanager

(9)启动yarn NodeManager

yarn-daemon.sh  start nodemanager

(9)启动历史服务

mr-jobhistory-daemon.sh start historyserver