部署方案
朋贬、 | NN-1 | NN-2 | DN | ZK | ZKFC | JNN | RS | NM |
---|---|---|---|---|---|---|---|---|
node01 | * | * | * | |||||
node02 | * | * | * | * | * | * | ||
node03 | * | * | * | * | ||||
node04 | * | * | * | * |
環(huán)境準(zhǔn)備
- 先安裝一臺(tái)虛擬機(jī)
- 配置靜態(tài)ip
見centos7 配置靜態(tài)ip - 修改主機(jī)名
見linux修改 hostname - 安裝jdk
見centos7安裝java - 關(guān)閉防火墻
見centos7關(guān)閉防火墻 - 下載hadoop 安裝包
我們這里使用的是hadoop-3.2.1.tar.gz
放到/tmp目錄 - 解壓到/usr/local/hadoop/目錄下
mkdir /usr/local/hadoop
tar -zxvf /tmp/hadoop-3.2.1.tar.gz -C /usr/local/hadoop
- 克隆虛擬機(jī)
先保存當(dāng)前虛擬機(jī)的快照
然后右擊該虛擬機(jī)肥缔,點(diǎn)擊管理-->克隆
選擇現(xiàn)有快照乱陡,點(diǎn)擊下一步
選擇創(chuàng)建完整克隆玷过,點(diǎn)擊下一步
虛擬機(jī)名稱他托,輸入node02知残,點(diǎn)擊完成辱志。
開啟此虛擬機(jī)虐急,修改ip和hostname
按照上述步驟箱残,創(chuàng)建node03和node04 - 配置node01的hosts,添加node2止吁,node03被辑,node04
vi /etc/hosts
添加
192.168.88.201 node01
192.168.88.202 node02
192.168.88.203 node03
192.168.88.204 node04
并將hosts發(fā)送給其他三臺(tái)機(jī)器
scp /etc/hosts node02:/etc/hosts
scp /etc/hosts node03:/etc/hosts
scp /etc/hosts node04:/etc/hosts
輸入用戶名和密碼 完成
- 配置免密登錄
在所有4臺(tái)虛擬機(jī)上執(zhí)行以下操作
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys
將node01的id_rsa.pub發(fā)送給其他三臺(tái)機(jī)器
cd /root/.ssh
scp id_rsa.pub node02:`pwd`/node01.pub
scp id_rsa.pub node03:`pwd`/node01.pub
scp id_rsa.pub node04:`pwd`/node01.pub
在其他3太機(jī)器上執(zhí)行
cd /root/.ssh
cat node01.pub >> authorized_keys
在node01上試一下是否可以免密登錄到其他幾臺(tái)機(jī)器上
ssh node02
exit
ssh node03
exit
ssh node04
exit
可以即ok
配置node02免密登錄到其他三臺(tái)機(jī)器,操作同上
開始部署
- 在node01機(jī)器上敬惦,配置hdfs-site.xml
cd /usr/local/hadoop/hadoop-3.2.1/etc/hadoop
vi hdfs-site.xml
加入以下配置
<configuration>
<property>
<name>dfs.nameservices</name>
<value>mycluster</value>
</property>
<property>
<name>dfs.ha.namenodes.mycluster</name>
<value>nn1,nn2</value>
</property>
<property>
<name>dfs.namenode.rpc-address.mycluster.nn1</name>
<value>node01:8020</value>
</property>
<property>
<name>dfs.namenode.rpc-address.mycluster.nn2</name>
<value>node02:8020</value>
</property>
<property>
<name>dfs.namenode.http-address.mycluster.nn1</name>
<value>node01:9870</value>
</property>
<property>
<name>dfs.namenode.http-address.mycluster.nn2</name>
<value>node02:9870</value>
</property>
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://node01:8485;node02:8485;node03: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</value>
</property>
<property>
<name>dfs.ha.fencing.ssh.private-key-files</name>
<value>/root/.ssh/id_dsa</value>
</property>
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/var/path/to/journal/node/local/data</value>
</property>
<property>
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
</configuration>
- 配置core-site.xml
vi core-site.xml
加入以下配置
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://mycluster</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/var/hadoop/ha</value>
</property>
<property>
<name>ha.zookeeper.quorum</name>
<value>node02:2181,node03:2181,node04:2181</value>
</property>
</configuration>
- 編輯hadoop-env.sh中的JAVA_HOME
vi hadoop-env.sh
找到JAVA_HOME,并編輯
export JAVA_HOME=/usr/local/java/jdk1.8.0_251
- 編輯workes
vi workers
添加以下參數(shù)
node02
node03
node04
- 分發(fā) hdfs-site.xml 和core-site.xml盼理,hadoop-env.sh,workers 到node02俄删,node03宏怔,node04
scp core-site.xml hdfs-site.xml hadoop-env.sh workers node02:`pwd`
scp core-site.xml hdfs-site.xml hadoop-env.sh workers node03:`pwd`
scp core-site.xml hdfs-site.xml hadoop-env.sh workers node04:`pwd`
- 在node01上
- 修改sbin目錄下的幾個(gè)腳本,確保通過(guò)root用戶可以把hadoop啟起來(lái)
cd /usr/local/hadoop/hadoop-3.2.1/sbin
編輯start-dfs.sh和stop-dfs.sh文件畴椰,添加下列參數(shù):
HDFS_DATANODE_USER=root
HDFS_DATANODE_SECURE_USER=hdfs
HDFS_NAMENODE_USER=root
HDFS_SECONDARYNAMENODE_USER=root
HDFS_JOURNALNODE_USER=root
HDFS_ZKFC_USER=root
編輯start-yarn.sh和stop-yarn.sh文件臊诊,添加下列參數(shù):
YARN_RESOURCEMANAGER_USER=root
HDFS_DATANODE_SECURE_USER=yarn
YARN_NODEMANAGER_USER=root
把這幾個(gè)文件分發(fā)到其他節(jié)點(diǎn)
scp start-dfs.sh stop-dfs.sh start-yarn.sh stop-yarn.sh node02:`pwd`
scp start-dfs.sh stop-dfs.sh start-yarn.sh stop-yarn.sh node03:`pwd`
scp start-dfs.sh stop-dfs.sh start-yarn.sh stop-yarn.sh node04:`pwd`
- 搭建zookeeper
- 下載apache-zookeeper-3.6.1-bin.tar.gz,并放到node02的/tmp目錄下
- 解壓到/usr/local/zookeeper目錄
mkdir /usr/local/zookeeper
tar -zxvf /tmp/apache-zookeeper-3.6.1-bin.tar.gz -C /usr/local/zookeeper
- 修改配置文件
cd /usr/local/zookeeper/apache-zookeeper-3.6.1-bin/conf
cp zoo_sample.cfg zoo.cfg
vi zoo.cfg
添加以下配置
#找到dataDir斜脂,并改成以下值
dataDir=/var/zookeeper
#添加以下配置
server.1=node02:2888:3888
server.2=node03:2888:3888
server.3=node04:2888:3888
- 將zookeeper 分發(fā)到node03抓艳,node04
cd /usr/local
scp -r zookeeper/ node03:`pwd`
scp -r zookeeper/ node04:`pwd`
- 在node02,node03秽褒,node04上創(chuàng)建對(duì)應(yīng)的目錄
mkdir /var/zookeeper
- 在node02壶硅,node03,node04的/var/zookeeper創(chuàng)建myid文件
node02echo 1 > /var/zookeeper/myid
node03echo 2 > /var/zookeeper/myid
node04echo 3 > /var/zookeeper/myid
- 啟動(dòng)zookeeper集群
node02,node03,node04分別執(zhí)行
cd /usr/local/zookeeper/apache-zookeeper-3.6.1-bin/
bin/zkServer.sh start
可以執(zhí)行以下命令看一下狀態(tài)
bin/zkServer.sh status
- 啟動(dòng)journalnode
在node01,node02,node03上分別執(zhí)行
cd /usr/local/hadoop/hadoop-3.2.1/
bin/hdfs --daemon start journalnode
然后jps
看一下销斟,JournalNode是否起來(lái)了
- 格式化文件系統(tǒng)
在node01上執(zhí)行
cd /usr/local/hadoop/hadoop-3.2.1/
bin/hdfs namenode -format
- node01啟動(dòng)namenode
cd /usr/local/hadoop/hadoop-3.2.1/
sbin/hadoop-daemon.sh start namenode
- node02執(zhí)行bootstrapStandby
cd /usr/local/hadoop/hadoop-3.2.1/
bin/hdfs namenode -bootstrapStandby
- 在zookeeper上初始化Ha狀態(tài)
在node01上執(zhí)行
cd /usr/local/hadoop/hadoop-3.2.1/
bin/hdfs zkfc -formatZK
- 啟動(dòng)當(dāng)前hadoop集群
cd /usr/local/hadoop/hadoop-3.2.1/
sbin/start-dfs.sh
- jsp看一下庐椒,進(jìn)程是否正確
[root@node01 hadoop-3.2.1]# jps
15816 NameNode
16521 DFSZKFailoverController
16572 Jps
15615 JournalNode
[root@node02 hadoop-3.2.1]# jps
13063 Jps
13033 DFSZKFailoverController
1818 QuorumPeerMain
12763 NameNode
12875 DataNode
12606 JournalNode
[root@node03 hadoop-3.2.1]# jps
10513 Jps
10306 JournalNode
10402 DataNode
1734 QuorumPeerMain
[root@node04 var]# jps
2272 Jps
2209 DataNode
1764 QuorumPeerMain
- 瀏覽器訪問(wèn)
http://node01:9870
- 關(guān)閉hadoop集群和zookeeper集群
在node01上
cd /usr/local/hadoop/hadoop-3.2.1/
sbin/stop-dfs.sh
在node02,node03,node04上
cd /usr/local/zookeeper/apache-zookeeper-3.6.1-bin/
bin/zkServer.sh stop
- 開啟zookeeper集群和hadoop集群
在node02,node03,node04上
cd /usr/local/zookeeper/apache-zookeeper-3.6.1-bin/
bin/zkServer.sh start
在node01上
cd /usr/local/hadoop/hadoop-3.2.1/
sbin/start-dfs.sh
配置高可用資源管理
在node01節(jié)點(diǎn)上
- 配置mapred-site.xml
cd /usr/local/hadoop/hadoop-3.2.1/etc/hadoop/
vi mapred-site.xml
配置如下
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.application.classpath</name>
<value>$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/*:$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/lib/*</value>
</property>
</configuration>
- 配置yarn-site.xml
vi yarn-site.xml
配置如下
<configuration>
<!-- Site specific YARN configuration properties -->
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.env-whitelist</name>
<value>JAVA_HOME,HADOOP_COMMON_HOME,HADOOP_HDFS_HOME,HADOOP_CONF_DIR,CLASSPATH_PREPEND_DISTCACHE,HADOOP_YARN_HOME,HADOOP_MAPRED_HOME</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>rm1,rm2</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm1</name>
<value>node03</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm2</name>
<value>node04</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address.rm1</name>
<value>node03:8088</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address.rm2</name>
<value>node04:8088</value>
</property>
<property>
<name>hadoop.zk.address</name>
<value>node02:2181,node03:2181,node04:2181</value>
</property>
</configuration>
- 分發(fā)配置
scp mapred-site.xml yarn-site.xml node02:`pwd`
scp mapred-site.xml yarn-site.xml node03:`pwd`
scp mapred-site.xml yarn-site.xml node04:`pwd`
- 配置node03,node04之間的免密登錄
node03節(jié)點(diǎn)上
cd /root/.ssh
scp id_rsa.pub node04:`pwd`/node03.pub
node04節(jié)點(diǎn)上
cd /root/.ssh
cat node03.pub >> authorized_keys
scp id_rsa.pub node03:`pwd`/node04.pub
node03節(jié)點(diǎn)上
cat node04.pub >> authorized_keys
ssh node04
ssh node03
exit
exit
可以互相免密登錄即可
- 按照啟動(dòng)順序進(jìn)行啟動(dòng)
- 在node02,node03,node04上,先啟動(dòng)zookeeper
cd /usr/local/zookeeper/apache-zookeeper-3.6.1-bin/
bin/zkServer.sh start
- 在node01上蚂踊, 啟動(dòng)hdfs
cd /usr/local/hadoop/hadoop-3.2.1/
sbin/start-dfs.sh
- 在node01上啟動(dòng)資源管理
cd /usr/local/hadoop/hadoop-3.2.1/
sbin/start-yarn.sh
- 瀏覽器訪問(wèn)一下http://node03:8088/
出現(xiàn)Nodes of the cluster的頁(yè)面即可 - 關(guān)閉hadoop集群和zookeeper集群
在node01上
cd /usr/local/hadoop/hadoop-3.2.1/
sbin/stop-all.sh
在node02,node03,node04上
cd /usr/local/zookeeper/apache-zookeeper-3.6.1-bin/
bin/zkServer.sh stop