一、集群的规划
Zookeeper集群:
192.168.182.12 (bigdata12)
192.168.182.13 (bigdata13)
192.168.182.14 (bigdata14)
Hadoop集群:
192.168.182.12 (bigdata12) NameNode1主节点 ResourceManager1主节点 Journalnode
192.168.182.13 (bigdata13) NameNode2备用主节点 ResourceManager2备用主节点 Journalnode
192.168.182.14 (bigdata14) DataNode1 NodeManager1
192.168.182.15 (bigdata15) DataNode2 NodeManager2
二、准备工作
1、安装JDK:每台机器都需要安装
我这里使用的是jdk-8u152-linux-x64.tar.gz安装包
解压JDK:
tar -zxvf jdk-8u144-linux-x64.tar.gz -C ~/training
2、配置环境变量:
1)配置java环境变量:
vi ~/.bash_profile
export JAVA_HOME=/root/training/jdk1..0_144
export PATH=$JAVA_HOME/bin:$PATH
2)生效环境变量:
source ~/.bash_profile
3)验证是否安装成功:
java -version
3、配置IP地址与主机名的映射关系 原因:方便SSH调用 方便Ping通
vi /etc/hosts
输入:
192.168.182.13 bigdata13
192.168.182.14 bigdata14
192.168.182.15 bigdata15
4、配置免密码登录
1)在每台机器上产生公钥和私钥
ssh-keygen -t rsa
含义:通过ssh协议采用非对称加密算法的rsa算法生成一组密钥对:公钥和私钥
2)在每台机器上将自己的公钥复制给其他机器
注:以下四个命令需要在每台机器上都运行一遍
ssh-copy-id -i .ssh/id_rsa.pub root@bigdata12
ssh-copy-id -i .ssh/id_rsa.pub root@bigdata13
ssh-copy-id -i .ssh/id_rsa.pub root@bigdata14
ssh-copy-id -i .ssh/id_rsa.pub root@bigdata15
三、安装Zookeeper集群(在bigdata12上安装)
在主节点(bigdata12)上安装和配置ZooKeeper
我这里使用的是zookeeper-3.4.10.tar.gz安装
1、解压Zookeeper:
tar -zxvf zookeeper-3.4..tar.gz -C ~/training
2、配置和生效环境变量:
export ZOOKEEPER_HOME=/root/training/zookeeper-3.4.
export PATH=$ZOOKEEPER_HOME/bin:$PATH
source ~/.bash_profile
3、修改zoo.cfg配置文件:
vi /root/training/zookeeper-3.4./conf/zoo.cfg
修改:
dataDir=/root/training/zookeeper-3.4./tmp
在最后一行添加:
server.=bigdata12::
server.=bigdata13::
server.=bigdata14::
4、修改myid配置文件
在/root/training/zookeeper-3.4.10/tmp目录下创建一个myid的空文件:
mkdir /root/training/zookeeper-3.4./tmp/myid
echo > /root/training/zookeeper-3.4./tmp/myid
5、将配置好的zookeeper拷贝到其他节点,同时修改各自的myid文件
scp -r /root/training/zookeeper-3.4./ bigdata13:/root/training
scp -r /root/training/zookeeper-3.4./ bigdata14:/root/training
进入bigdata13和bigdata14两台机器中,找到myid文件,将其中的1分别修改为2和3:
vi myid
在bigdata13中输入:2在bigdata14中输入:3
四、安装Hadoop集群(在bigdata12上安装)
1、修改hadoop-env.sh
export JAVA_HOME=/root/training/jdk1..0_144
2、修改core-site.xml
<configuration>
<!-- 指定hdfs的nameservice为ns1 -->
<property>
<name>fs.defaultFS</name>
<value>hdfs://ns1</value>
</property> <!-- 指定HDFS数据存放路径,默认存放在linux的/tmp目录中 -->
<property>
<name>hadoop.tmp.dir</name>
<value>/root/training/hadoop-2.7./tmp</value>
</property> <!-- 指定zookeeper的地址 -->
<property>
<name>ha.zookeeper.quorum</name>
<value>bigdata12:,bigdata13:,bigdata14:</value>
</property>
</configuration>
3、修改hdfs-site.xml(配置这个nameservice中有几个namenode)
<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>bigdata12:</value>
</property>
<!-- nn1的http通信地址 -->
<property>
<name>dfs.namenode.http-address.ns1.nn1</name>
<value>bigdata12:</value>
</property>
<!-- nn2的RPC通信地址 -->
<property>
<name>dfs.namenode.rpc-address.ns1.nn2</name>
<value>bigdata13:</value>
</property>
<!-- nn2的http通信地址 -->
<property>
<name>dfs.namenode.http-address.ns1.nn2</name>
<value>bigdata13:</value>
</property>
<!-- 指定NameNode的日志在JournalNode上的存放位置 -->
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://bigdata12:8485;bigdata13:8485;/ns1</value>
</property>
<!-- 指定JournalNode在本地磁盘存放数据的位置 -->
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/root/training/hadoop-2.7./journal</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>/root/.ssh/id_rsa</value>
</property> <!-- 配置sshfence隔离机制超时时间 -->
<property>
<name>dfs.ha.fencing.ssh.connect-timeout</name>
<value></value>
</property>
</configuration>
4、修改mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
配置Yarn的HA
5、修改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>bigdata12</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm2</name>
<value>bigdata13</value>
</property> <!-- 指定zk集群地址 -->
<property>
<name>yarn.resourcemanager.zk-address</name>
<value>bigdata12:,bigdata13:,bigdata14:</value>
</property> <property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
6、修改slaves 从节点的地址
bigdata14
bigdata15
7、将配置好的hadoop拷贝到其他节点
scp -r /root/training/hadoop-2.7./ root@bigdata13:/root/training/
scp -r /root/training/hadoop-2.7./ root@bigdata14:/root/training/
scp -r /root/training/hadoop-2.7./ root@bigdata15:/root/training/
五、启动Zookeeper集群
在每一台机器上输入:
zkServer.sh start
六、启动journalnode
在bigdata12和bigdata13两台节点上启动journalnode节点:
hadoop-daemon.sh start journalnode
七、格式化HDFS和Zookeeper(在bigdata12上执行)
格式化HDFS:
hdfs namenode -format
将/root/training/hadoop-2.7.3/tmp拷贝到bigdata13的/root/training/hadoop-2.7.3/tmp下
scp -r dfs/ root@bigdata13:/root/training/hadoop-2.7./tmp
格式化zookeeper:
hdfs zkfc -formatZK
日志:INFO ha.ActiveStandbyElector: Successfully created /hadoop-ha/ns1 in ZK.
以上日志表明在Zookeeper的文件系统中创建了/hadoop-ha/ns1的子目录用于保存Namenode的结构信息
八、启动Hadoop集群(在bigdata12上执行)
启动Hadoop集群的命令:
start-all.sh
日志:
Starting namenodes on [bigdata12 bigdata13]
bigdata12: starting namenode, logging to /root/training/hadoop-2.4./logs/hadoop-root-namenode-hadoop113.out
bigdata13: starting namenode, logging to /root/training/hadoop-2.4./logs/hadoop-root-namenode-hadoop112.out
bigdata14: starting datanode, logging to /root/training/hadoop-2.4./logs/hadoop-root-datanode-hadoop115.out
bigdata15: starting datanode, logging to /root/training/hadoop-2.4./logs/hadoop-root-datanode-hadoop114.out
bigdata13: starting zkfc, logging to /root/training/hadoop-2.7./logs/hadoop-root-zkfc- bigdata13.out
bigdata12: starting zkfc, logging to /root/training/hadoop-2.7./logs/hadoop-root-zkfc-bigdata12.out
在bigdata13上手动启动ResourceManager作为Yarn的备用主节点:
yarn-daemon.sh start resourcemanager
至此,Hadoop集群的HA架构就已经搭建成功。
版权声明:本文为博主原创文章, 未经博主允许不得转载。http://www.cnblogs.com/lijinze-tsinghua/