Hadoop HA部署(防火墙全部关闭)
修改三台虚拟机主机名
[root@localhost ~]# hostnamectl set-hostname master
[root@localhost ~]# bash
[root@localhost ~]# hostnamectl set-hostname slave1
[root@localhost ~]# bash
[root@localhost ~]# hostnamectl set-hostname slave2
[root@localhost ~]# bash
配置三台虚拟机IP与主机名映射
[root@master ~]# vi /etc/hosts
分发hosts文件到slave
[root@master ~]# scp /etc/hosts slave1:/etc
[root@master ~]# scp /etc/hosts slave2:/etc
配置三台虚拟机SSH无密登录
生成密钥对
[root@master ~]# ssh-keygen -t rsa -P ''
[root@slave1 ~]# ssh-keygen -t rsa -P ''
[root@slave2 ~]# ssh-keygen -t rsa -P ''
复制公钥到slave
[root@master ~]# ssh-copy-id master
[root@master ~]# ssh-copy-id slave1
[root@master ~]# ssh-copy-id slave2
测试从master登录到slave1、slave2
[root@master ~]# ssh slave1
[root@slave1 ~]# exit
[root@master ~]# ssh slave2
[root@slave2 ~]# exit
安装配置jdk
检查三台虚拟机是否有openjdk,如若有需要将其卸载掉,没有可进行下一步操作
[root@master ~]# rpm -qa | grep openjdk
卸载命令
rpm -e --nodeps +查询出来的openjdk包
解压缩jdk包到指定目录
[root@master ~]# tar -zxvf /h3cu/jdk-8u144-linux-x64.tar.gz -C /usr/local/src
配置jdk环境变量
[root@master ~]# vi /root/.bash_profile
添加配置:
export JAVA_HOME=/usr/local/src/jdk1.8.0_144
export JRE_HOME=/usr/local/src/jdk1.8.0_144/jre
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
生效环境变量
[root@master ~]# source /root/.bash_profile
复制分发jdk环境变量文件到slave
[root@master ~]# scp -r /root/.bash_profile slave1:/root
[root@master ~]# scp -r /root/.bash_profile slave2:/root
复制分发jdk安装包文件到slave
[root@master ~]# scp -r /usr/local/src/jdk1.8.0_144/ slave1:/usr/local/src
[root@master ~]# scp -r /usr/local/src/jdk1.8.0_144/ slave2:/usr/local/src
生效环境变量
[root@slave1 ~]# source /root/.bash_profile
[root@slave2 ~]# source /root/.bash_profile
查看jdk版本
[root@slave1 ~]# java -version
[root@slave2 ~]# java -version
安装配置zookeeper
解压缩
[root@master ~]# tar -zxvf /h3cu/zookeeper-3.4.8.tar.gz -C /usr/local/src
重命名
[root@master ~]# mv /usr/local/src/zookeeper-3.4.8/ /usr/local/src/zookeeper
配置环境变量
[root@master ~]# vi /root/.bash_profile
添加配置
export ZOOKEEPER_HOME=/usr/local/src/zookeeper
export PATH=$ZOOKEEPER_HOME/bin:$PATH
分发环境变量文件
[root@master ~]# scp -r /root/.bash_profile slave1:/root
[root@master ~]# scp -r /root/.bash_profile slave2:/root
生效环境变量文件
[root@master ~]# source /root/.bash_profile
[root@slave1 ~]# source /root/.bash_profile
[root@slave2 ~]# source /root/.bash_profile
修改zoo.cfg文件
切换到zookeeper配置文件目录
[root@master ~]# cd /usr/local/src/zookeeper/conf/
[root@master conf]# cp zoo_sample.cfg zoo.cfg
[root@master conf]# vi zoo.cfg
修改
dataDir=/usr/local/src/zookeeper/data
增加
dataLogDir=/usr/local/src/zookeeper/logs
server.1=master:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888
创建myid配置文件
[root@master conf]# mkdir /usr/local/src/zookeeper/data
[root@master conf]# cd /usr/local/src/zookeeper/data
[root@master data]# echo '1' > myid
分发zookeeper文件
[root@master data]# scp -r /usr/local/src/zookeeper/ slave1:/usr/local/src
[root@master data]# scp -r /usr/local/src/zookeeper/ slave2:/usr/local/src
修改slave1、slave2的myid
[root@slave1 ~]# cd /usr/local/src/zookeeper/data/
[root@slave1 data]# echo '2' > myid
[root@slave2 ~]# cd /usr/local/src/zookeeper/data/
[root@slave2 data]# echo '3' > myid
启动zookeeper
[root@master ~]# zkServer.sh start
[root@slave1 data]# zkServer.sh start
[root@slave2 data]# zkServer.sh start
查看slave2状态
[root@slave2 data]# zkServer.sh status
配置hadoop ha
解压缩
[root@master ~]# tar -zxvf /h3cu/hadoop-2.7.1.tar.gz -C /usr/local/src
重命名
[root@master ~]# mv /usr/local/src/hadoop-2.7.1/ /usr/local/src/hadoop
配置环境变量并分发生效
[root@master ~]# vi /root/.bash_profile
添加配置:
export HADOOP_HOME=/usr/local/src/hadoop
export PATH=$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PATH
分发文件
[root@master ~]# scp -r /root/.bash_profile slave1:/root
[root@master ~]# scp -r /root/.bash_profile slave2:/root
生效环境变量文件
[root@master ~]# source /root/.bash_profile
[root@slave1 ~]# source /root/.bash_profile
[root@slave2 ~]# source /root/.bash_profile
配置hadoop配置文件
切换到配置目录下
[root@master ~]# cd /usr/local/src/hadoop/etc/hadoop/
[root@master hadoop]# vi hadoop-env.sh
修改jdk路径
export JAVA_HOME=/usr/local/src/jdk1.8.0_144`
[root@master hadoop]# vi core-site.xml
添加配置:
<property>
<name>fs.defaultFS</name>
<value>hdfs://mycluster</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>file:/usr/local/src/hadoop/tmp</value>
</property>
<property>
<name>ha.zookeeper.quorum</name>
<value>master:2181,slave1:2181,slave2:2181</value>
</property>
[root@master hadoop]# vi hdfs-site.xml
添加配置:
<property>
<name>dfs.qjournal.start-segment.timeout.ms</name>
<value>60000</value>
</property>
<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:8020</value>
</property>
<property>
<name>dfs.namenode.rpc-address.mycluster.slave1</name>
<value>slave1:8020</value>
</property>
<property>
<name>dfs.namenode.http-address.mycluster.master</name>
<value>master:50070</value>
</property>
<property>
<name>dfs.namenode.http-address.mycluster.slave1</name>
<value>slave1:50070</value>
</property>
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://master:8485;slave1:8485;slave2:8485/mycluster</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>
<property>
<name>dfs.permissions.enabled</name>
<value>false</value>
</property>
<property>
<name>dfs.support.append</name>
<value>true</value>
</property>
<property>
<name>dfs.ha.fencing.ssh.private-key-files</name>
<value>/root/.ssh/id_rsa</value>
</property>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>/usr/local/src/hadoop/tmp/hdfs/nn</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/usr/local/src/hadoop/tmp/hdfs/dn</value>
</property>
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/usr/local/src/hadoop/tmp/hdfs/jn</value>
</property>
<property>
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
<property>
<name>dfs.ha.fencing.ssh.connect-timeout</name>
<value>30000</value>
</property>
[root@master hadoop]# cp mapred-site.xml.template mapred-site.xml
[root@master hadoop]# vi mapred-site.xml
添加配置:
<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>
[root@master hadoop]# vi yarn-site.xml
添加配置:
<property>
<name>yarn.resourcemanager.ha.enabled</name>
<value>true</value>
</property>
<property>
<name>yarn.resourcemanager.cluster-id</name>
<value>yrc</value>
</property>
<property>
<name>yarn.resourcemanager.ha.rm-ids</name>
<value>rm1,rm2</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm1</name>
<value>master</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm2</name>
<value>slave1</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address.rm1</name>
<value>master:8088</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address.rm2</name>
<value>slave1:8088</value>
</property>
<property>
<name>hadoop.zk.address</name>
<value>master:2181,slave1:2181,slave2:2181</value>
</property>
[root@master hadoop]# vi slaves
添加配置:
master
slave1
slave2
namenode、datanode、journalnode等存放数据的公共目录为/usr/local/src/hadoop/tmp;
在master上执行如下:
[root@master hadoop]# mkdir -p /usr/local/src/hadoop/tmp/hdfs/nn
[root@master hadoop]# mkdir -p /usr/local/src/hadoop/tmp/hdfs/dn
[root@master hadoop]# mkdir -p /usr/local/src/hadoop/tmp/hdfs/jn
[root@master hadoop]# mkdir -p /usr/local/src/hadoop/tmp/logs
分发文件
[root@master hadoop]# scp -r /usr/local/src/hadoop root@slave1:/usr/local/src/
[root@master hadoop]# scp -r /usr/local/src/hadoop root@slave2:/usr/local/src/
journalNode初始化和启动
[root@master hadoop]# hadoop-daemons.sh start journalnode
格式化namenode
[root@master hadoop]# hdfs namenode -format
注册ZNode
[root@master hadoop]# hdfs zkfc -formatZK
复制namenode元数据到其它节点(在master节点执行)
[root@master hadoop]# scp -r /usr/local/src/hadoop/tmp/hdfs/nn/* slave1:/usr/local/src/hadoop/tmp/hdfs/nn/
启动hdfs
[root@master hadoop]# start-all.sh
若没有resourcemanager,就自己手动重启一下
yarn-daemon.sh start resourcemanager
在slave1上启动resourcemanager和namenode进程
[root@slave1 hadoop]# yarn-daemon.sh start resourcemanager
启动 MapReduce任务历史服务器
[root@master hadoop]# yarn-daemon.sh start proxyserver
[root@master hadoop]# mr-jobhistory-daemon.sh start historyserver
查看master和slave1的进程
[root@master hadoop]# jps
[root@slave1 hadoop]# jps