集羣規劃:
主機名 IP 安裝的軟件 運行的進程html
hadoop01 192.168.88.155 jdk、hadoop、zookeeper DataNode、NodeManager、JournalNode、QuorumPeerMain
hadoop02(A)192.168.88.164 jdk、hadoop、zookeeper DataNode、NodeManager、JournalNode、QuorumPeerMain
hadoop03(B)192.168.88.165 jdk、hadoop、zookeeper DataNode、NodeManager、JournalNode、QuorumPeerMain
hadoop04(C)192.168.88.162 jdk、hadoop NameNode、DFSZKFailoverController(zkfc)
hadoop05(D)192.168.88.166 jdk、hadoop NameNode、DFSZKFailoverController(zkfc)java
hadoop06(E)192.168.88.167 jdk、hadoop ResourceManager
node
hadoop07(F) 192.168.88.168 jdk、hadoop ResourceManager
shell
說明:
1.在hadoop2.0中一般由兩個NameNode組成,一個處於active狀態,另外一個處於standby狀態。Active NameNode對外提供服務,而Standby NameNode則不對外提供服務,僅同步active namenode的狀態,以便可以在它失敗時快速進行切換。
hadoop2.0官方提供了兩種HDFS HA的解決方案,一種是NFS,另外一種是QJM。這裏咱們使用簡單的QJM。在該方案中,主備NameNode之間經過一組JournalNode同步元數據信息,一條數據只要成功寫入多數JournalNode即認爲寫入成功。一般配置奇數個JournalNode
這裏還配置了一個zookeeper集羣,用於ZKFC(DFSZKFailoverController)故障轉移,當Active NameNode掛掉了,會自動切換Standby NameNode爲standby狀態
2.hadoop-2.2.0中依然存在一個問題,就是ResourceManager只有一個,存在單點故障,hadoop-2.4.1解決了這個問題,有兩個ResourceManager,一個是Active,一個是Standby,狀態由zookeeper進行協調apache
2.安裝配置hadoop集羣
2.1解壓bootstrap
[root@localhost Desktop]# tar -zxvf hadoop-2.6.0.tar.gz -C /home/hadoop #解壓到目錄/home/hadoopvim
[root@localhost Desktop]# cd /home/hadoopapp
2.2配置HDFS(hadoop2.0全部的配置文件都在$HADOOP_HOME/etc/hadoop目錄下)
#將hadoop添加到環境變量中
vim /etc/profile
框架
export JAVA_HOME=/usr/lib/java/java-7-sun
export HADOOP_HOME=/home/hadoop/hadoop-2.6.0
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/binssh
[root@localhost hadoop-2.6.0]# cd etc
[root@localhost etc]# ls
hadoop
[root@localhost etc]# cd hadoop
2.2.1修改hadoop-env.sh
export JAVA_HOME=/usr/lib/java/java-7-sun
2.2.2修改core-site.xml
<!-- 指定hdfs的nameservice爲ns1 -->
<property>
<name>fs.defaultFS</name>
<value>hdfs://ns1</value>
</property>
<!-- 指定hadoop臨時目錄 -->
<property>
<name>hadoop.tmp.dir</name>
<value>/home/hadoop/hadoop-2.6.0/tmp</value>
</property>
<!-- 指定zookeeper地址 -->
<property>
<name>ha.zookeeper.quorum</name>
<value>hadoop01:2181,hadoop02:2181,hadoop03:2181</value>
</property>
2.2.3修改hdfs-site.xml
<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>hadoop04:9000</value>
</property>
<!-- nn1的http通訊地址 -->
<property>
<name>dfs.namenode.http-address.ns1.nn1</name>
<value>hadoop04:50070</value>
</property>
<!-- nn2的RPC通訊地址 -->
<property>
<name>dfs.namenode.rpc-address.ns1.nn2</name>
<value>hadoop05:9000</value>
</property>
<!-- nn2的http通訊地址 -->
<property>
<name>dfs.namenode.http-address.ns1.nn2</name>
<value>hadoop05:50070</value>
</property>
<!-- 指定NameNode的元數據在JournalNode上的存放位置 -->
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://hadoop01:8485;hadoop02:8485;hadoop03:8485/ns1</value>
</property>
<!-- 指定JournalNode在本地磁盤存放數據的位置 -->
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/home/hadoop/hadoop-2.6.0/journaldata</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>/home/hadoop/.ssh/id_rsa</value>
</property>
<!-- 配置sshfence隔離機制超時時間 -->
<property>
<name>dfs.ha.fencing.ssh.connect-timeout</name>
<value>30000</value>
</property>
</configuration>
2.2.4修改mapred-site.xml
<configuration>
<!-- 指定mr框架爲yarn方式 -->
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
2.2.5修改yarn-site.xml
<configuration>
<!-- 指定resourcemanager地址 -->
<property>
<name>yarn.resourcemanager.hostname</name>
<value>hadoop06/value>
</property>
<!-- 指定nodemanager啓動時加載server的方式爲shuffle server -->
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
2.2.6修改slaves(slaves是指定子節點的位置,由於要在hadoop04上啓動HDFS、在hadoop06啓動yarn,因此hadoop04上的slaves文件指定的是datanode的位置,hadoop06上的slaves文件指定的是nodemanager的位置)(最好六個都這樣配)
hadoop01
hadoop02
hadoop03
2.2.7配置免密碼登錄
#首先要配置hadoop04到hadoop0一、hadoop0二、hadoop0三、hadoop0四、hadoop0五、hadoop06 hadoop07的免密碼登錄
#在whadoop04上生產一對鑰匙
ssh-keygen -t rsa
#將公鑰拷貝到其餘節點,包括本身
ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop01
ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop02
ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop03
ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop04
ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop05
ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop06
ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop07
#配置hadoop06到hadoop0一、hadoop0二、hadoop0三、hadoop07的免密碼登錄
#在hadoop03上生產一對鑰匙
ssh-keygen -t rsa
#將公鑰拷貝到其餘節點
ssh-coyp-id hadoop01
ssh-coyp-id hadoop02
ssh-coyp-id hadoop03
ssh-coyp-id hadoop07
#注意:兩個namenode之間要配置ssh免密碼登錄,別忘了配置hadoop05到hadoop04的免登錄
在hadoop05上生產一對鑰匙
ssh-keygen -t rsa
sh-coyp-id -i hadoop04
2.4將配置好的hadoop04拷貝到其餘節點
[root@hadoop01 hadoop]# scp -r hadoop-2.6.0/ root@hadoop01:/home/hadoop/
[root@hadoop01 hadoop]# scp -r hadoop-2.6.0/ root@hadoop02:/home/hadoop/
[root@hadoop01 hadoop]# scp -r hadoop-2.6.0/ root@hadoop03:/home/hadoop/
[root@hadoop01 hadoop]# scp -r hadoop-2.6.0/ root@hadoop05:/home/hadoop/
[root@hadoop01 hadoop]# scp -r hadoop-2.6.0/ root@hadoop06:/home/hadoop/
[root@hadoop01 hadoop]# scp -r hadoop-2.6.0/ root@hadoop07:/home/hadoop/
###注意:嚴格按照下面的步驟
2.5啓動zookeeper集羣(分別在hadoop0一、hadoop0二、hadoop03上啓動zk)
cd /root/Desktop/app/zookeeper-3.4.5/bin
./zkServer.sh start
#查看狀態:一個leader,兩個follower
./zkServer.sh status
2.6啓動journalnode(分別在在hadoop0一、hadoop0二、hadoop03上執行)
[root@hadoop02 bin]# cd /home/hadoop/hadoop-2.6.0
[root@hadoop01 hadoop-2.6.0]# sbin/hadoop-daemon.sh start journalnode
starting journalnode, logging to /home/hadoop/hadoop-2.6.0/logs/hadoop-root-journalnode-hadoop01.out
[root@hadoop01 hadoop-2.6.0]# jps
4539 QuorumPeerMain
4929 Jps
4893 JournalNode
必定要肯定三臺datenode啓動起來若沒啓動看「home/hadoop/hadoop-2.6.0/logs/hadoop-root-journalnode-hadoop01.out」日誌
#運行jps命令檢驗,hadoop0一、hadoop0二、hadoop03上多了JournalNode進程
2.7格式化HDFS
#在hadoop04上執行命令:
hdfs namenode -format
15/12/17 04:17:19 INFO namenode.FSImage: Allocated new BlockPoolId: BP-853305614-192.168.88.162-1450354639048
15/12/17 04:17:19 INFO common.Storage: Storage directory /home/hadoop/hadoop-2.6.0/tmp/dfs/name has been successfully formatted.
15/12/17 04:17:20 INFO namenode.NNStorageRetentionManager: Going to retain 1 images with txid >= 0
15/12/17 04:17:20 INFO util.ExitUtil: Exiting with status 0
15/12/17 04:17:20 INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at hadoop04/192.168.88.162
************************************************************/
#格式化後會在根據core-site.xml中的hadoop.tmp.dir配置生成個文件,這裏我配置的是/home/hadoop/hadoop-2.6.0/tmp,而後將/home/hadoop/hadoop-2.6.0/tmp拷貝到hadoop05的/hadoop/hadoop-2.6.0/下。[root@hadoop04 hadoop-2.6.0]# scp -r tmp/ hadoop05:/home/hadoop/hadoop-2.6.0
[root@hadoop04 hadoop-2.6.0]# scp -r tmp/ hadoop05:/home/hadoop/hadoop-2.6.0
seen_txid 100% 2 0.0KB/s 00:00
fsimage_0000000000000000000 100% 351 0.3KB/s 00:00
VERSION 100% 206 0.2KB/s 00:00
fsimage_0000000000000000000.md5 100% 62 0.1KB/s 00:00
##也能夠這樣,建議hdfs namenode -bootstrapStandby
2.8格式化ZKFC(在hadoop04上執行便可)
hdfs zkfc -formatZK
5/12/17 04:44:46 INFO ha.ActiveStandbyElector: Session connected.
15/12/17 04:44:46 INFO ha.ActiveStandbyElector: Successfully created /hadoop-ha/ns1 in ZK.
15/12/17 04:44:46 INFO zookeeper.ZooKeeper: Session: 0x351aff1d8980000 closed
15/12/17 04:44:46 INFO zookeeper.ClientCnxn: EventThread shut down、
2.9啓動HDFS(在hadoop04上執行)
[root@hadoop04 hadoop-2.6.0]# sbin/hadoop-daemon.sh start zkfc(不啓動這個就會兩臺standby)
[root@hadoop04 hadoop-2.6.0]# sbin/start-dfs.sh
[root@hadoop05 hadoop-2.6.0]# sbin/hadoop-daemon.sh start zkfc(另外一臺namenode 啓用zkfc)
這時候配置裏面得datanode和name node所有都啓動起來了
http://192.168.88.162:50070/dfshealth.html#tab-overview
Started: | Sat Dec 19 04:35:20 PST 2015 |
---|---|
Version: | 2.6.0, re3496499ecb8d220fba99dc5ed4c99c8f9e33bb1 |
Compiled: | 2014-11-13T21:10Z by jenkins from (detached from e349649) |
Cluster ID: | CID-4cb4b3a6-09a5-49c8-a88a-40248886089b |
Block Pool ID: | BP-915542458-192.168.88.162-1450526096844 |
另外一臺namenode
http://192.168.88.166:50070/dfshealth.html#tab-overview
Started: | Sat Dec 19 04:35:20 PST 2015 |
---|---|
Version: | 2.6.0, re3496499ecb8d220fba99dc5ed4c99c8f9e33bb1 |
Compiled: | 2014-11-13T21:10Z by jenkins from (detached from e349649) |
Cluster ID: | CID-4cb4b3a6-09a5-49c8-a88a-40248886089b |
Block Pool ID: | BP-915542458-192.168.88.162-1450526096844 |
如hadoop01
[root@hadoop01 hadoop-2.6.0]# jps
4539 QuorumPeerMain
1502 DataNode
1616 Jps
621 JournalNode
[root@hadoop04 hadoop-2.6.0]# sbin/hadoop-daemon.sh start namenode
hadoop04
[root@hadoop04 hadoop-2.6.0]# jps
4282 NameNode
4674 Jps
hadoop01,2,3
[root@hadoop02 hadoop-2.6.0]# jps
32417 JournalNode
28495 Jps
28175 DataNode
28366 NodeManager
4561 QuorumPeerMain
2.10啓動YARN(#####注意#####:是在hadoop6上執行start-yarn.sh,把namenode和resourcemanager分開是由於性能問題,由於他們都要佔用大量資源,因此把他們分開了,他們分開了就要分別在不一樣的機器上啓動)
[root@hadoop06 hadoop-2.6.0]# sbin/start-yarn.sh
[root@hadoop07 ~]# jps
27582 Jps
28583 ResourceManager
[root@hadoop06 ~]# jps
27582 Jps
28583 ResourceManager
hadoop04上上傳文件
[root@hadoop04 Desktop]# hadoop fs -put test.sh /
http://192.168.88.162:50070/explorer.html#/的
Permission | Owner | Group | Size | Replication | Block Size | Name |
---|---|---|---|---|---|---|
drwxr-xr-x | root | supergroup | 0 B | 0 | 0 B | test.sh |
測試yarn http://192.168.88.167:8088/cluster
Apps Submitted | Apps Pending | Apps Running | Apps Completed | Containers Running | Memory Used | Memory Total | Memory Reserved | VCores Used | VCores Total | VCores Reserved | Active Nodes | Decommissioned Nodes | Lost Nodes | Unhealthy Nodes | Rebooted Nodes |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0 B | 24 GB | 0 B | 0 | 24 | 0 | 3 | 0 | 3 | 0 | 0 |
Show
entries
Search:
ID |
User |
Name |
Application Type |
Queue |
StartTime |
FinishTime |
State |
FinalStatus |
Progress |
Tracking UI |
---|---|---|---|---|---|---|---|---|---|---|
No data available in table |
[root@hadoop06 mapreduce]# cd /home/hadoop/hadoop-2.6.0/share/hadoop/mapreduce
[root@hadoop06 mapreduce]# hadoop jar hadoop-mapreduce-examples-2.6.0.jar pi 5 5
[root@hadoop03 hadoop-2.6.0]# jps(任務調度)
1049 MRAppMaster
32407 DataNode
4729 JournalNode
32629 NodeManager
4549 QuorumPeerMain
1166 Jps
測試yarn http://192.168.88.168:8088/cluster
This is standby RM. Redirecting to the current active RM: http://hadoop06:8088/cluster
在hadoop04上測試
[root@hadoop04 Desktop]# hdfs haadmin -getServiceState nn1
active
[root@hadoop04 Desktop]# hdfs haadmin -getServiceState nn2
standby
[root@hadoop04 Desktop]#
測試集羣工做狀態的一些指令 :bin/hdfs dfsadmin -report 查看hdfs的各節點狀態信息bin/hdfs haadmin -getServiceState nn1 獲取一個namenode節點的HA狀態sbin/hadoop-daemon.sh start namenode 單獨啓動一個namenode進程./hadoop-daemon.sh start zkfc 單獨啓動一個zkfc進程