Hadoop Ha(高可用) 方案 配置和安装

前言:如果那里有错误的地方欢迎指出,谢谢。

方案

系统使用Ubuntu18_04_1。
Hadoop3.2.0
zookeeper-3.4.13
四台机器
第一台Ubuntu1安装:namenode,zkfc,resourcemanager
第二台Ubuntu2安装:namenode,zkfc,resourcemanager
第三台Ubuntu3安装:ZooKeeper,Journalnode,datanode,nodemanager
第四台Ubuntu4安装:ZooKeeper,Journalnode,datanode,nodemanager
这种方案不是特别好,但熟悉HA已经可以了。

准备

修改hostname
修改hosts
把主机名都换成自己定好的名字。
ssh安装和免密登陆

第一步:安装Hadoop

https://blog.csdn.net/q435201823/article/details/86764782
这是之前的博客。先装好Hadoop。ssh的安装和配置这里也有。

第二步:安装ZooKeeper

https://blog.csdn.net/q435201823/article/details/87628876
Zookeeper是HA的关键,不过很简单,照着装完就好了。

第三步:配置Hadoop HA

HA的配置和第一步的博客里的单节点配置不一样。
我们需要重新修改Hadoop的etc下的配置文件。

官方的配置文件是这样设置的
https://hadoop.apache.org/docs/r3.2.0/hadoop-project-dist/hadoop-hdfs/HDFSHighAvailabilityWithQJM.html
我稍微总结和翻译一下

hadoop-env.sh
这个和第一步网页里面一样,这里不赘述。

export JAVA_HOME=/usr/lib/jdk/jdk1.8.0_201

core-site.xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
<!-- 指定hdfs的文件系统,以及谁是namenode -->
	<property>
		<name>fs.defaultFS</name>
		<value>hdfs://ns1/</value>
	</property>
<!-- hadoop临时文件的存储目录 -->
	<property>
		<name>hadoop.tmp.dir</name>
		<value>/home/czq/hadoop/hadoop-3.2.0/tmp</value>
	</property>
<!-- 指定ZooKeeper主机以及端口-->
	<property>
		<name>ha.zookeeper.quorum</name>
		<value>Ubuntu3:2181,Ubuntu4:2181</value>
	</property>
</configuration>

hdfs-site.xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
	<!--指定hdfs的nameservice为ns1,需要和core-site.xml中保持一致-->
	<property>
		<name>dfs.nameservices</name>
		<value>ns1</value>
	</property>
	<!--ns1下面有两个namenode,分别是nn1,和nn2-->
	<property>
		<name>dfs.ha.namenodes.ns1</name>
		<value>nn1,nn2</value>
	</property>
	<!--nn1的RPC通信地址-->
	<property>
		<name>dfs.namenode.rpc-address.ns1.nn1</name>
		<value>Ubuntu1:8020</value>
	</property>
	<!--nn1的http通信地址-->
	<property>
		<name>dfs.namenode.http-address.ns1.nn1</name>
		<value>Ubuntu1:9870</value>
	</property>
	<!--nn2的RPC通信地址-->
	<property>
		<name>dfs.namenode.rpc-address.ns1.nn2</name>
		<value>Ubuntu2:8020</value>
	</property>
	<!--nn1的http通信地址-->
	<property>
		<name>dfs.namenode.http-address.ns1.nn2</name>
		<value>Ubuntu2:9870</value>
	</property>
	<!--指定NameNode的元数据放在JournalNode上的存放位置-->
	<property>
		<name>dfs.namenode.shared.edits.dir</name>
		<value>qjournal://Ubuntu3:8485;Ubuntu4:8485/ns1</value>
	</property>
	<!--指定JournalNode在本地磁盘存放数据的位置-->
	<property>
		<name>dfs.journalnode.edits.dir</name>
		<value>/home/czq/hadoop/hadoop-3.2.0/journaldata</value>
	</property>
	<!--开启NameNode失败自动切换-->
	<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>
	<!--使用sshfence隔离机制时需要ssh免登陆-->
	<property>
		<name>dfs.ha.fencing.ssh.private-key-files</name>
		<value>/home/czq/.ssh/id_rsa</value>
	</property>
	<!--配置sshfence隔离机制超过时间-->
	<property>
		<name>dfs.ha.fencing.ssh.connect-timeout</name>
		<value>30000</value>
	</property>
<!-- 指定HDFS副本的数量 -->
	<property>
		<name>dfs.replication</name>
		<value>2</value>
	</property>
<!-- 指定secondary namenode,(uri)host:50090 
	<property>
		<name>dfs.secondary.http.address</name>
		<value>Ubuntu3:50090</value>
	</property>
-->
</configuration>

mapred-site.xml

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
	<!-- 指定mapreduce运行在yarn上 -->
	<property>
		<name>mapreduce.framework.name</name>
		<value>yarn</value>
	</property>
</configuration>

yarn-site.xml

<?xml version="1.0"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->
<configuration>
<!-- Site specific YARN configuration properties -->
<!--开启RM高可用-->
	<property>
		<name>yarn.resourcemanager.ha.enabled</name>
		<value>true</value>
	</property>
	<!--指定RM的Cluster id-->
	<property>
		<name>yarn.resourcemanager.cluster-id</name>
		<value>yrc</value>
	</property>
	<!--指定RM的名字-->
	<property>
		<name>yarn.resourcemanager.ha.rm-ids</name>
		<value>rm1,rm2</value>
	</property>
	<!--分别指定RM的地址-->
	<property>
		<name>yarn.resourcemanager.hostname.rm1</name>
		<value>Ubuntu1</value>
	</property>
	<property>
		<name>yarn.resourcemanager.hostname.rm2</name>
		<value>Ubuntu2</value>
	</property>
	<!--指定zk集群地址-->
	<property>
		<name>yarn.resourcemanager.zk-address</name>
		<value>Ubuntu3:2181,Ubuntu4:2181</value>
	</property>

<!-- reducer获取数据的方式 ,当前只有mapreduce_shuffle这种方式-->
	<property>
		<name>yarn.nodemanager.aux-services</name>
		<value>mapreduce_shuffle</value>
	</property>
<!-- 将 hadoop classpath输出的信息粘贴到value中,指定yarn需要的classpath,这里和之前的版本不同,之前的版本不需要-->
	<property>
		<name>yarn.application.classpath</name>
		<value>/home/czq/hadoop/hadoop-3.2.0/etc/hadoop:/home/czq/hadoop/hadoop-3.2.0/share/hadoop/common/lib/*:/home/czq/hadoop/hadoop-3.2.0/share/hadoop/common/*:/home/czq/hadoop/hadoop-3.2.0/share/hadoop/hdfs:/home/czq/hadoop/hadoop-3.2.0/share/hadoop/hdfs/lib/*:/home/czq/hadoop/hadoop-3.2.0/share/hadoop/hdfs/*:/home/czq/hadoop/hadoop-3.2.0/share/hadoop/mapreduce/lib/*:/home/czq/hadoop/hadoop-3.2.0/share/hadoop/mapreduce/*:/home/czq/hadoop/hadoop-3.2.0/share/hadoop/yarn:/home/czq/hadoop/hadoop-3.2.0/share/hadoop/yarn/lib/*:/home/czq/hadoop/hadoop-3.2.0/share/hadoop/yarn/*</value>
	</property>
</configuration>

workers
旧版本叫slaves

Ubuntu3
Ubuntu4

配置完成。

初始化之前的注意事项

因为我一开始做的时候出了点问题,所以导致我做了两次初始化
讲道理,做两次初始化应该是没问题的。
可问题就恰恰出在多次初始化。
其实出现的问题很多,原因也很多,不过好在有一个简单的解决办法
在初始化之前,
删除core-site.xml里面配置的hadoop.tmp.dir所指向的目录
删除Hadoop根目录下journalnode目录

记得每一个节点的都要删除
这两个目录都是初始化会生成的,再次初始化后他们可能残留下数据(比如和datanode联系的版本号),这样就会导致各种各样的问题

第四部:初始化

初始化是有顺序的,必须要按照下面步骤来。

1.启动ZooKeeper集群
分别在Ubuntu3和Ubuntu4键入命令

zkServer.sh start   #开启ZooKeeper集群
zkServer.sh status  #查看状态
#一个node是leader,其他都是follower。当然,我这里只有一个follower

2.启动journalnode
分别在Ubuntu3和4上键入命令

hdfs --daemon start journalnode  #这个是新版本的命令,建议使用
hadoop-daemon.sh start journalnode #这个是旧版本的命令

3.格式化hdfs
在Ubuntu1上执行命令(因为Ubuntu1是NameNode节点)

hdfs namenode -format

4.namenode数据文件复制
先启动一个namenode节点

hdfs --daemon start namenode

为了让其他namenode节点同步
在其他NameNode上执行(现在剩Ubuntu2)

hdfs namenode -bootstrapStandby

其实还可以直接将hadoop.tmp.dir所指向的目录复制到其他节点,效果是一样的。

然后最好先关一下最先启动的namenode

hdfs --daemon stop namenode

5.格式化zkfc
Ubuntu1上执行

hdfs zkfc -formatZK

6.启动hdfs和yarn

start-dfs.sh
start-yarn.sh

然后就可以用了。

日常启动

初始化之后,以后再启动就不用格式化了。只需要启动ZooKeeper和hdfs和yarn就可以了。
先开ZooKeeper再开hdfs和yarn

    zkServer.sh start   #开启ZooKeeper集群
    start-dfs.sh  #启动hdfs
    start-yarn.sh  #启动yarn
    stop-all.sh #全部关闭
    zkServer.sh stop   #关闭ZooKeeper集群
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值