埋没技术 / 大数据技术 / 学习日志 · 2023年3月16日 0

Hdoop HA搭建

前言

Hadoop HA是集群,需要三台以上机器进行搭建
配置文件最佳配置顺序
hadoop-env.sh->core-site.xml->hdfs-site.xml->yarn-site.xml->mapred-site.xml->slaves

开始搭建

第一步 解压

tar -zxvf /chinaskills/hadoop-2.7.7.tar.gz -C /opt/module

第二步 进入hadoop目录配置目录

cd /opt/module/hadoop-2.7.7/etc/hadoop

第三步 配置文件

hadoop-env.sh

vi hadoop-env.sh
修改JAVA_HOME

core-site.xml

<configuration>
	<property>
		<name>fs.defaultFS</name>
 <--这里填写hdfs://ns 不填写hdfs://master:9000 是因为是hadoop ha集群,需要填写集群id -- >
		<value>hdfs://ns</value>
	</property>
	<property>
                <name>hadoop.proxyuser.root.hosts</name>
                <value>*</value>
        </property>
        <property>
                <name>hadoop.proxyuser.root.groups</name>
                <value>*</value>
        </property>
	<property>
		<name>hadoop.tmp.dir</name>
		<value>/opt/module/hadoop-2.7.7/tmp</value>
	</property>
	<property>
		<name>ha.zookeeper.quorum</name>
		<value>master:2181,slave1:2181,slave2:2181</value>
	</property>
 <--以下是超时及最大连接配置,可选,若出现连接超时,可以加上以下配置 -- >
	<property>
		<name>ha.zookeeper.session-timeout.ms</name>
		<value>30000</value>
	</property>
	<property>
		<name>ipc.client.connect.max.retries</name>
		<value>100</value>
	</property>
	<property>
		<name>ipc.client.connect.retry.interval</name>
		<value>10000</value>
	</property>
</configuration>

hdfs-site.xml

<configuration>
	<property>
		<name>dfs.replication</name>
		<value>3</value>
	</property>
<-- namenode辅助节点,可选 -->
	<property>
  		<name>dfs.namenode.secondary.http-address</name>
  		<value>slave1:50090</value>
	</property>
<-- juornal超时时间,建议配置 -->
	<property>
		<name>qjuornal.start-segment.timeout.ms</name>
		<value>60000</value>
	</property>
<-- 集群id -->
	<property>
		<name>dfs.nameservices</name>
		<value>ns</value>	
	</property>
	<property>
		<name>dfs.ha.namenodes.ns</name>
		<value>nn1,nn2</value>
	</property>
	<property>
		<name>dfs.namenode.rpc-address.ns.nn1</name>
		<value>master:8020</value>
	</property>
	<property>
		<name>dfs.namenode.rpc-address.ns.nn2</name>
		<value>slave1:8020</value>
	</property>
	<property>
		<name>dfs.namenode.http-address.ns.nn1</name>
		<value>master:50070</value>
	</property>
	<property>
		<name>dfs.namenode.http-address.ns.nn2</name>
		<value>slave1:50070</value>
	</property>
<-- 指定Namenode元数据在jourNalNode的存放位置 -->
	<property>
		<name>dfs.namenode.shared.edits.dir</name>
		<value>qjournal://master:8485;slave1:8485;slave2:8485/ns</value>
	</property>
	<property>
		<name>dfs.journalnode.edits.dir</name>
		<value>/opt/module/hadoop-2.7.7/ha/journal</value>
	</property>
<-- 开启namenode故障自动切换 -->
	<property>
		<name>dfs.ha.automatic-failover.enabled</name>
		<value>true</value>
	</property>
<-- 失败自动切换方式 -->
	<property>
		<name>dfs.client.failover.proxy.provider.ns</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>
<--开启webhdfs-->
	<property>
		<name>dfs.webhdfs.enabled</name>
		<value>true</value>
	</property>
</configuration>

yarn-site.xml

<configuration>

    <!-- Site specific YARN configuration properties -->
    <property>
        <name>yarn.nodemanager.aux-services</name>
        <value>mapreduce_shuffle</value>
    </property>

    <property>
        <name>yarn.resourcemanager.ha.enabled</name>
        <value>true</value>
    </property>

    <property>
        <name>yarn.resourcemanager.cluster-id</name>
        <value>cluster1</value>
    </property>

    <property>
        <name>yarn.resourcemanager.ha.rm-ids</name>
        <value>r1,r2</value>
    </property>

    <property>
        <name>yarn.resourcemanager.hostname.r1</name>
        <value>master</value>
    </property>

    <property>
        <name>yarn.resourcemanager.hostname.r2</name>
        <value>slave1</value>
    </property>

    <property>
        <name>yarn.resourcemanager.webapp.address.r1</name>
        <value>master:8088</value>
    </property>

    <property>
        <name>yarn.resourcemanager.webapp.address.r2</name>
        <value>slave1:8088</value>
    </property>

    <property>
        <name>yarn.resourcemanager.zk-address</name>
        <value>master,slave1,slave2</value>
    </property>

    <property>
        <name>yarn.resourcemanager.recovery.enabled</name>
        <value>true</value>
    </property>

    <property>
        <name>yarn.resourcemanager.store.class</name>  <value>org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStore</value>
    </property>

    <property>
        <name>yarn.log-aggregation.retain-seconds</name>
        <value>86400</value>
    </property>
</configuration>

mapred-site.xml

<configuration>
	<property>
		<name>mapreduce.framework.name</name>
		<value>yarn</value>
	</property>
	<property>
		<name>mapreduce.jobhistory.address</name>
		<value>master:10020</value>
	</property>
	<property>
		<name>mapreduce.jobhistory.webapp.address</name>
		<value>master:19888</value>
	</property>
</configuration>

slaves

master
slave1
slave2

第四步 启动journalnode

每个节点都启动
sbin/hadoop-daemon.sh start journalnode

第五步 格式化namenode

bin/hadoop namenode -format
master即可

第六步 分发namenode tmp目录

scp -r /opt/module/hadoop-2.7.7/tmp slave1:/opt/module/hadoop-2.7.7
只有nn1和nn2,所以是分发给nn2

第七步 格式化zkfc

bin/hdfs zkfc -formatZK

第八步 在每个namenode节点上启动zkfc

sbin/hadoop-daemon.sh start zkfc

第九步 启动集群

sbin/start-all.sh

第十步 查看集群进程

jps

第十一步 查看nn1 nn2状态

hdfs haadmin -getServiceState nn1


微信扫描下方的二维码阅读本文