Hadoop的HA高可用搭建

Hadoop的HA高可用搭建

解压hadoop 并配置环境变量 vi /etc/profile

export HADOOP_HOME=/root/hadoop
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin

重启生效

source /etc/profile

查看安装成功

hadoop

配置hadoop-env.xml

export JAVA_HOME=/export/servers/jdk

配置core-site.xml

<configuration>
    <!-- 指定hdfs的nameservice为nameService1 -->
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://mycluster</value>
    </property>
    <!-- 指定hadoop临时目录 -->
    <property>
        <name>hadoop.tmp.dir</name>
        <value>/export/servers/hadoop/data/hadoopdata</value>
    </property>

    <!-- 指定zookeeper地址 -->
    <property>
        <name>ha.zookeeper.quorum</name>
        <value>master:2181,slave1:2181,slave2:2181</value>
    </property>
</configuration>

配置hdfs-site.xml

<configuration>
<!--指定hdfs的nameservice为mycluster,需要和core-site.xml中的保持一致 -->
    <property>
        <name>dfs.nameservices</name>
        <value>mycluster</value>
    </property>

    <property>
        <name>dfs.ha.namenodes.mycluster</name>
        <value>master,slave1</value>
    </property>
    <property>
        <name>dfs.namenode.rpc-address.mycluster.master</name>
        <value>master:9000</value>
    </property>
        <property>
        <name>dfs.namenode.http-address.mycluster.master</name>
        <value>master:50070</value>
    </property>
        <property>
        <name>dfs.namenode.rpc-address.mycluster.s1</name>
        <value>slave1:9000</value>
    </property>
    <property>
        <name>dfs.namenode.http-address.mycluster.s1</name>
        <value>slave1:50070</value>
    </property>


<!-- 指定NameNode的元数据在JournalNode上的存放位置 -->
    <property>
        <name>dfs.namenode.shared.edits.dir</name>
        <value>qjournal://master:8485;slave1:8485;slave2:8485/mycluster</value>
    </property>
<!-- 指定JournalNode在本地磁盘存放数据的位置 -->
    <property>
        <name>dfs.journalnode.edits.dir</name>
        <value>/export/servers/hadoop/data/journaldata</value>
    </property>
<!-- 开启NameNode失败自动切换 -->
    <property>
        <name>dfs.ha.automatic-failover.enabled</name>
        <value>true</value>
    </property>
<!-- 配置失败自动切换实现方式 -->
    <property>
        <name>dfs.client.failover.proxy.provider.mycluster</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>/root/.ssh/id_rsa</value>
    </property>
<!-- 配置sshfence隔离机制超时时间 -->
    <property>
        <name>dfs.ha.fencing.ssh.connect-timeout</name>
        <value>30000</value>
    </property>
</configuration>

配置mapred-site.xml

<configuration>
<!-- 指定mr框架为yarn方式 -->
    <property>
   		 <name>mapreduce.framework.name</name>
   		 <value>yarn</value>
    </property>
</configuration>

配置yarn-site.xml

<configuration>
<!-- 开启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>master</value>
    </property>
    <property>
        <name>yarn.resourcemanager.hostname.rm2</name>
        <value>s1</value>
    </property>
<!-- 指定zk集群地址 -->
    <property>
        <name>yarn.resourcemanager.zk-address</name>
        <value>master:2181,slave1:2181,slave2:2181</value>
    </property>
    <property>
        <name>yarn.nodemanager.aux-services</name>
        <value>mapreduce_shuffle</value>
    </property>
</configuration>

修改slaves

master
slave1
slave2

master新建文件

mkdir /export/servers//hadoop/data/hadoopdata

mkdir /export/servers//hadoop/data/journaldata

拷贝文件到slave1 slave2

scp -r /export/servers/jdk root@slave1:/export/servers
scp -r /export/servers/jdk root@slave2:/export/servers
scp -r /export/servers/hadoop root@slave1:/export/servers
scp -r /export/servers/hadoop root@slave2:/export/servers
scp -r /export/servers/zookeeper root@slave1:/export/servers
scp -r /export/servers/zookeeper root@slave2:/export/servers

修改slave1 zookeeper data下的myid内容改为2
修改slave2 zookeeper data下的myid内容改为3

启动master slave1 slave2 zookeeper

zkServer.sh start

启动master journalnode

./sbin/hadoop-daemons.sh start journalnode

初始化master namemode

./bin/hadoop namenode -format

注册ZNode

bin/hdfs zkfc -formatZK

启动hdfs

start-dfs.sh

启动yarn

start-yarn.sh

slave1上同步元数据

hdfs namenode -bootstrapStandby

启动slave1 namemode

hadoop-daemon.sh start namenode

去网页验证

关闭master的NameNode

hadoop-daemon.sh stop namenode
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值