没想到时隔一年多,hadoop安装的文章突然这么多人看到,既然有人看,那我近期就把其他的实验手册一块整理一下,传上来。
不过课程已经是三年前的了,可能略有点老,手册仅供参考。
第一期的Hadoop大数据集群搭建(超详细):
Hadoop大数据集群搭建(超详细)_hadoop集群搭建-CSDN博客
第二期的ZooKeeper的下载及安装(接第一期的hadoop集群搭建)
ZooKeeper安装实验手册-CSDN博客
今天主要介绍HA高可用集群的搭建,在第二期ZooKeeper的基础上继续操作。
1. 修改core-site.xml
cd /export/servers/hadoop-3.1.3/etc/hadoop
vim core-site.xml
修改defaultFS并新增zookeeper
<property><name>ha.zookeeper.quorum</name>
<value>hadoop01:2181,hadoop02:2181,hadoop03:2181</value>
</property>2. 修改hdfs-site.xml
cd /export/servers/hadoop-3.1.3/etc/hadoop
vim hdfs-site.xml
新增以下内容(上图没截全):
<property><name>dfs.namenode.name.dir</name>
<value>file:/export/data/hadoop/name</value>
</property> <property><name>dfs.datanode.data.dir</name>
<value>file:/export/data/hadoop/data</value>
</property> <property><name>dfs.webhdfs.enabled</name>
<value>true</value>
</property> <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>hadoop01:9000</value>
</property> <property><name>dfs.namenode.http-address.ns1.nn1</name>
<value>hadoop01:9870</value>
</property> <property><name>dfs.namenode.rpc-address.ns1.nn2</name>
<value>hadoop02:9000</value>
</property> <property><name>dfs.namenode.http-address.ns1.nn2</name>
<value>hadoop02:9870</value>
</property> <property><name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://hadoop01:8485;hadoop02:8485;hadoop03:8485/ns1
</value> </property> <property><name>dfs.journalnode.edits.dir</name>
<value>/export/data/hadoop/journaldata</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> <property><name>dfs.ha.fencing.ssh.connect-timeout</name>
<value>30000</value>
</property>3. 修改mapred-site.xml
cd /export/servers/hadoop-3.1.3/etc/hadoop
vim mapred-site.xml
无改动
4. 修改yarn-site.xml
cd /export/servers/hadoop-3.1.3/etc/hadoop
vim yarn-site.xml
新增以下内容
<property><name>yarn.nodemanager.resource.memory-mb</name>
<value>2048</value>
</property> <property><name>yarn.scheduler.maximum-allocation-mb</name>
<value>2048</value>
</property> <property><name>yarn.nodemanager.resource.cpu-vcores</name>
<value>1</value>
</property> <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>hadoop01</value>
</property> <property><name>yarn.resourcemanager.hostname.rm2</name>
<value>hadoop02</value>
</property> <property><name>yarn.resourcemanager.zk-address</name>
<value>hadoop01:2181,hadoop02:2181,hadoop03:2181</value>
</property>5. 将配置文件xml发给hadoop02和03
在hadoop01上执行以下命令:
scp -r /export/servers/hadoop-3.1.3/etc/hadoop/yarn-site.xml hadoop03:/export/servers/hadoop-3.1.3/etc/hadoop
scp -r /export/servers/hadoop-3.1.3/etc/hadoop/hdfs-site.xml hadoop03:/export/servers/hadoop-3.1.3/etc/hadoop
scp -r /export/servers/hadoop-3.1.3/etc/hadoop/core-site.xml hadoop03:/export/servers/hadoop-3.1.3/etc/hadoop
scp -r /export/servers/hadoop-3.1.3/etc/hadoop/mapred-site.xml hadoop03:/export/servers/hadoop-3.1.3/etc/hadoop
scp -r /export/servers/hadoop-3.1.3/etc/hadoop/yarn-site.xml hadoop02:/export/servers/hadoop-3.1.3/etc/hadoop
scp -r /export/servers/hadoop-3.1.3/etc/hadoop/hdfs-site.xml hadoop02:/export/servers/hadoop-3.1.3/etc/hadoop
scp -r /export/servers/hadoop-3.1.3/etc/hadoop/core-site.xml hadoop02:/export/servers/hadoop-3.1.3/etc/hadoop
scp -r /export/servers/hadoop-3.1.3/etc/hadoop/mapred-site.xml hadoop02:/export/servers/hadoop-3.1.3/etc/hadoop
6. 修改/etc/profile
vim /etc/profile
新增
export HDFS_ZKFC_USER=root
分发profile文件到其他服务器
scp /etc/profile hadoop02:/etc/profile
scp /etc/profile hadoop03:/etc/profile
传完之后要在hadoop01、02和03上分别执行source /etc/profile命令,来刷新配置文件
7. 第一次启动高可用集群(HA)
7.1 启动zookeeper
在三个虚拟机上分别执行
zkServer.sh start
查看状态
zkServer.sh status
7.2 启动JournalNode
在三个虚拟机上分别执行
hadoop-daemon.sh start journalnode (最新命令:hdfs --daemon start journalnode)
等待2分钟
7.3 格式化目录并复制到hadoop02
注意:只格式化一次,不要多次格式化,等待JournalNode执行2分钟后再执行
在hadoop01上执行
hadoop namenode -format
scp -r /export/data/hadoop/ hadoop02:/export/data
7.4 格式化ZKFC
在hadoop01上执行
hdfs zkfc -formatZK
7.5 启动HDFS
start-dfs.sh
7.6 启动YARN
start-yarn.sh
7.7 查看进程
jps
7.8 查看主备namenode
hdfs haadmin -getServiceState nn1
hdfs haadmin -getServiceState nn2
其他命令
#将standby状态namenode切换到active
hdfs haadmin -transitionToActive nn1
#将active状态namenode切换到standby
hdfs haadmin -transitionToStandby nn2
测试集群工作状态的一些指令 :
hdfs dfsadmin -report 查看hdfs的各节点状态信息
可能遇到的问题:
- hadoop02的NameNode起来后很快就没了,可以使用下述命令再次重启
hdfs --daemon start namenode
- datanode或者namenode或者其他进程没起来
查看log实现,查找对应的log
cd /export/servers/hadoop-3.1.3/logs
vim hadoop-root-namenode-hadoop01.log
8. 再次启动高可用集群
在3台虚拟机执行
zkServer.sh start
hadoop-daemon.sh start journalnode
等待1分钟
在hadoop01执行
start-dfs.sh
start-yarn.sh
版权归原作者 小飞飞V5 所有, 如有侵权,请联系我们删除。