基于Zookeeper与Hadooper HA集群

基础 Zookeeper Hadooper 集群搭建完毕
在这里插入图片描述
Zookeeper 高速数据库
JournalNode 负责对Zookeeper进行高速读取 (Master主机将配置通过JournalNode 放入Zookeeper JournalNode同时负责两台Master的同步 )

注:HA on ZK与原集群的主要区别

原集群,元数据和日志edits都存储于Secondary Namenode,合并后再转储至Master
HA集群,元数据镜像存储于Master(基础)、日志edits存储于zk集群。

JournalNode进程职责

在这里插入图片描述

第一步HA配置
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>

	<property>
		<name>hadoop.tmp.dir</name>
		<value>file:/usr/hadoop/hadoop-3.1.2</value>
	</property>
	<property>
		<name>fs.defaultFS</name>
		<value>hdfs://nnc1/</value>
	</property>
    <property>
        <name>ha.zookeeper.quorum</name>
        <value>192.168.150.111:2181,192.168.150.112:2181,192.168.150.113: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>


    <property>
        <name>dfs.replication</name>
        <value>1</value>
    </property>
    <property>
	<name>dfs.namenode.name.dir</name>
	<value>file:/usr/hadoop/hadoop-3.1.2/dfs/name</value>
    </property>

    <property>
	<name>dfs.blocksize</name>
	<value>1048576</value>
    </property>



	<!--HA-->
	<property><!--hdfs namenode集群别名,与core-site.xml中一致 -->
        	<name>dfs.nameservices</name>
        	<value>nnc1</value>
	</property>
	<property><!-- namenodes下面有两个NameNode,分别是nn1,nn2 -->
        	<name>dfs.ha.namenodes.nnc1</name>
        	<value>nn1,nn2</value>
	</property>
	<property><!-- nn1的RPC通信地址 -->
        	<name>dfs.namenode.rpc-address.nnc1.nn1</name>
	        <value>HadoopMaster01:9000</value>
	</property>
	<property><!-- nn2的RPC通信地址 -->
        	<name>dfs.namenode.rpc-address.nnc1.nn2</name>
        	<value>HadoopMaster02:9000</value>
	</property>
	<property><!-- 配置JournalNode组的访问地址,格式qjournal://host:port/journalId。 journalId需要与“nameserviceID”一致 -->
        	<name>dfs.namenode.shared.edits.dir</name>
        	<value>qjournal://192.168.150.111:8485;192.168.150.112:8485;192.168.150.113:8485/nnc1</value>
	</property>
	<property><!-- 指定JournalNode在本地磁盘存放数据的位置 -->
        	<name>dfs.journalnode.edits.dir</name>
        	<value>/usr/hadoop/hadoop-3.1.2/dfs/journalData</value>
	</property>
	<property><!-- 启用ZKFC,NameNode自动切换功能 -->
        	<name>dfs.ha.automatic-failover.enabled</name>
        	<value>true</value>
	</property>
	<property><!-- NameNode自动切换配置失败后的解决方案 -->
	        <name>dfs.client.failover.proxy.provider.nnc1</name>
        	<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
	</property>
	<property><!-- Fecing隔离机制指定,多个方案间换行分割 -->
        	<name>dfs.ha.fencing.methods</name>
        	<value>
         		sshfence
        		shell(/bin/true)
			shell(/usr/hadoop/hadoop-3.1.2/sbin/masterSwitchRecord.sh)
        	</value>
    	</property>
	<property><!-- sshfence隔离机制时需要ssh免登陆 -->
        	<name>dfs.ha.fencing.ssh.private-key-files</name>
        	<value>/root/.ssh/id_rsa</value>
    	</property>
	<property><!-- 配置sshfence隔离机制超时时间 -->
        	<name>dfs.ha.fencing.ssh.connect-timeout</name>
       		<value>30000</value>
	</property>

	<!--HA-->


</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>

	<!--ha 可选强制要求MapReduce作业运行在YARN平台-->
	<property>
        	<name>mapreduce.framework.name</name>
        	<value>yarn</value>
	</property>
	<!--ha-->

</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 -->
	<property><!-- 启用YARN HA -->
		<name>yarn.resourcemanager.ha.enabled</name>
		<value>true</value>
	</property>
	<property><!-- 指定YARN cluster id -->
		<name>yarn.resourcemanager.cluster-id</name>
		<value>yrmc1</value>
	</property>
	<property><!-- 指定ResourceManager的名字 -->
        	<name>yarn.resourcemanager.ha.rm-ids</name>
        	<value>rm1,rm2</value>
	</property>
	<property><!-- 分别指定ResourceManager的地址 -->
        	<name>yarn.resourcemanager.hostname.rm1</name>
        	<value>192.168.150.101</value>
    	</property>
	<property>
        	<name>yarn.resourcemanager.hostname.rm2</name>
        	<value>192.168.150.102</value>
	</property>
	<property>
        	<name>yarn.resourcemanager.zk-address</name>
        	<value>192.168.150.111:2181,192.168.150.112:2181,192,168.150.113:2181</value>
	</property>
	<property>
        	<name>yarn.nodemanager.aux-services</name>
        	<value>mapreduce_shuffle</value>
	</property>
	<property>
        	<name>yarn.nodemanager.aux-services.mapreduce_shuffle.class</name>
        	<value>org.apache.hadoop.mapred.ShuffleHandler</value>
	</property>

</configuration>

第二步:清理历史分区数据

在这里插入图片描述

第三步:同步文件

(同步整个Hadoop/etc/hadoop/*目录)

第四步:启动ZK集群、启动JournalNode集群

./zkServer.sh start  (启动)





hadoop-daemon.sh start journalnode

hdfs --daemon start journalnode

启动JournalNode 命令二选一

第五步:选一台Master进行重新格式化

Hdfs namenode -format

同步镜像文件至另一台Master
在这里插入图片描述

第六步:初始化ZKFC进程

选择一台master,运行即可:

Hdfs zkfc –formatZK

添加变量到 start-dfs.sh

HDFS_JOURNALNODE_USER=root
HDFS_ZKFC_USER=root

第七步:启动集群,测试HA

Start-dfs.sh
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值