阿里雲ECS服務器部署HADOOP集群(二):HBase完全分布式集群搭建(使用外置ZooKeeper)


本篇將在阿里雲ECS服務器部署HADOOP集群(一):Hadoop完全分布式集群環境搭建的基礎上搭建,多添加了一個 datanode 節點 。

 

1 節點環境介紹:

1.1 環境介紹:

1.2 各節點角色分配

  • master: NameNode、SecondaryNameNode、HMaster、QuorumPeerMain
  • slave1: DataNode、HMaster(候補節點)、HRegionServer、QuorumPeerMain
  • slave2: DataNode、HRegionServer、QuorumPeerMain

2 HBase 下載

下載 hbase-1.2.6-bin.tar.gz 並在合適的位置解壓縮,筆者這里解壓縮的路徑為:

/usr/local

將解壓得到的目錄改名為 hbase 

1 cd /usr/local
2 mv hbase-1.2.6/ hbase/

3 添加 HBase 環境變量

在"/etc/profile"中添加內容:

1 export HBASE_HOME=/usr/local/hbase
2 export PATH=$PATH:$HBASE_HOME/bin

重新加載環境:

source /etc/profile

4 修改 HBase 配置信息

4.1 修改 hbase 環境變量 (hbase-env.sh)

編輯文件:

vim $HBASE_HOME/conf/hbase-env.sh

添加內容:

1 export JAVA_HOME=/usr/local/jdk1.8
2 export HBASE_CLASSPATH=/usr/local/hadoop/etc/hadoop3 export HBASE_MANAGES_ZK=false

關於 HBASE_CLASSPATH , 官方文檔解釋如下:Of note, if you have made HDFS client configuration changes on your Hadoop cluster, such as configuration directives for HDFS clients, as opposed to server-side configurations, you must use one of the following methods to enable HBase to see and use these configuration changes:

  • Add a pointer to your HADOOP_CONF_DIR to the HBASE_CLASSPATH environment variable in hbase-env.sh.
  • Add a copy of hdfs-site.xml (or hadoop-site.xml) or, better, symlinks, under ${HBASE_HOME}/conf, or 
  • if only a small set of HDFS client configurations, add them to hbase-site.xml.

An example of such an HDFS client configuration is dfs.replication. If for example, you want to run with a replication factor of 5, HBase will create files with the default of 3 unless you do the above to make the configuration available to HBase.

HBASE_MANAGES_ZK 設置是否使用內置 ZooKeeper ,默認為 true 也就是使用內置 ZooKeeper 筆者這里使用外置 ZooKeeper 。(生產環境建議使用外置ZooKeeper,維護起來比較方便,可參考到底要不要用hbase自帶的zookeeper

4.2 修改 hbase 默認配置(hbase-site.xml)

編輯文件:

vim $HBASE_HOME/conf/hbase-site.xml

配置可參考如下代碼:

 1 <configuration>
 2   <!--HBase 的數據保存在 HDFS 對應的目錄下-->
 3   <property>
 4     <name>hbase.rootdir</name>
 5     <value>hdfs://master:9000/hbase</value>
 6   </property>
 7   <!--是否分布式環境-->  
 8   <property>
 9     <name>hbase.cluster.distributed</name>
10     <value>true</value>
11   </property>
12   <!--配置 ZK 的地址, 三個節點都啟用 ZooKeeper-->
13   <property>
14     <name>hbase.zookeeper.quorum</name>
15     <value>master,slave1,slave2</value>
16   </property>
17   <!--內置 ZooKeeper 的數據目錄-->  
18   <property>
19     <name>hbase.zookeeper.property.dataDir</name>
20     <value>/usr/local/hbase/zookeeper</value>
21   </property>
22 </configuration>

4.3 指定 regionservers (regionservers)

編輯文件:

vim $HBASE_HOME/conf/regionservers

添加內容:

1 slave1
2 slave2

4.4 指定候補節點(backup-masters)

這個文件需要自己創建。

編輯文件:

vim $HBASE_HOME/conf/backup-masters

添加內容:

slave1

為了保證HBase集群的高可靠性,HBase支持多Backup Master 設置。當Active Master掛掉后,Backup Master可以自動接管整個HBase的集群。

5 分發 hbase 和 profile 給 slave1,slave2(建議將 hbase 壓縮后分發)

1 scp -r /usr/local/hbase slave1:/usr/local
2 scp -r /usr/local/hbase slave2:/usr/local
1 scp /etc/profile slave1:/etc/
2 scp /etc/profile slave2:/etc/

分發后分別在各節點重新加載環境並測試,可使用 hbase version 測試。

6 安裝 ZooKeeper

參考 阿里雲ECS服務器部署HADOOP集群(三):ZooKeeper 完全分布式集群搭建

7 開放相關端口(坑!!!!!!

注:服務器端口全部開放的可以直接跳過這一步,不想看筆者BB的也可以直接跳到該小結的最后。

 

可能是由於計算機網絡沒學好,從搭建Hadoop開始大半的時間都被浪費到這個端口問題上,各種 Error 全都是因為這個問題。😭😭😭

至此發誓一定要認真重新學習一遍計算機網絡!!!

回到正題:阿里雲服務器默認只開放三個端口,如下

所以Hadoop集群搭建的各種所需端口都需要自己手動開放。

看到一些例如一些廢棄的端口如 yarn 的 web ui 舊端口 8088 會被黑客用來挖礦的關於端口開放安全性的問題,筆者嘗試一個個的參照配置文件一個個的添加端口,結果遇到各種問題。例如 

  • web UI 打不開
  • web UI 顯示內容有問題
  • 各節點的通訊問題
  • hbase 報錯

起初在 Hadoop 配置的時候還好,問題還比較容易發現,但是隨着從底層的向上延伸到了 Hadoop 的組件問題就變的很神秘了, 例如在 hbase 中遇到的

  • ERROR: org.apache.hadoop.hbase.PleaseHoldException: Master is initializing;
  • ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet;
  • master.ServerManager: Waiting for region servers count to settle;
  • The Load Balancer is not enabled which will eventually cause performance degradation in HBase as Regions will not be distributed across all RegionServers. The balancer is only expected to be disabled during rolling upgrade scenarios.
  • zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect

    java.net.SocketException: Network is unreachable;

  • Caused by: org.apache.hadoop.hbase.ipc.RemoteWithExtrasException(org.apache.hadoop.hbase.exceptions.OutOfOrderScannerNextException): org.apache.hadoop.hbase.exceptions.OutOfOrderScannerNextException: Expected nextCallSeq: 1 But the nextCallSeq got from client: 0; request=scanner_id: 5643550422109494702 number_of_rows: 100 close_scanner: false next_call_seq: 0

  •  

    master.SplitLogManager: finished splitting (more than or equal to) 0 bytes 

  • hbase:meta,,1.1588230740 state=PENDING_OPEN, ts=Tue Nov 24 08:26:45 UTC 2015 (1098s ago), server=amb2.service.consul,16020,1448353564099

  • 17/11/12 22:44:10 INFO hdfs.DFSClient: Exception in createBlockOutputStream
    java.io.IOException: Bad connect ack with firstBadLink as 192.168.0.101:50010
    at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.createBlockOutputStream(DFSOutputStream.java:1456)
    at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.nextBlockOutputStream(DFSOutputStream.java:1357)
    at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.run(DFSOutputStream.java:587)

注:這次沒有記錄Error所以以上都是從瀏覽器歷史記錄中找到的,有些不完整的用網上的相似的Error替代了。

這些問題在網上找到的所有解決方法大致歸結為以下幾點:

  • 關閉防火牆
  • 禁用 selinux
  • 退出 hdfs 安全模式
  • 配置時間同步
  • hosts 文件的各節點 IP 內外網配置
  • 重新格式化 hdfs 
  • 修復 hbase
  • 存在節點未啟動或非正常關閉

但是:

所以試了這么多方法我的這么多Error一個都沒解決。。。

認真看了官方文檔嘗試了各種配置甚至嘗試了各個版本的hbase,在老師的開導下先換了HMaster的放置的節點失敗了,嘗試偽分布式也失敗,但這時的 Error 已經不像剛開始的又少又難懂,網上匹配的結果也很少,范圍越來越小,Error越來越明顯了。然后就發現了原來是 hdfs 之間的連接問題,但是因為菜還不太明確問題,所以便嘗試將 hdfs 設置成偽分布式,終於成功了!然后又嘗試配置兩個節點的 hdfs 集群,這時終於從 log 中確定了問題所在,原來是節點的 50010 50020 端口沒開放,導致節點間無法通訊。於是一氣之下打開了服務器的所有端口,重新配置了一遍便成功了。

總結:log 一定要認真仔細查看並去理解,如果遇到報錯很少並且各種方法都無效的情況時,應該嘗試更換思路,比如簡單化當前的配置,縮小范圍,獲得一些新的、更多的Error,絕對不能放棄,只要是個錯誤,就一定可以得到解決,除非它本身就是個Error。。。學會變換不同的思路去解決問題,方法肯定嘗試不完~

所以對於端口問題有兩種解決辦法:

  • 根據官方文檔將默認配置需要的端口一個個的開放。
  • 直接 1/65535, 將所有端口開放,可能會出現安全問題。

8 啟動使用外置 ZooKeeper 的 HBase

8.1 啟動各組件

啟動順序:hdfs-->zookeeper-->hbase

1 # master
2 start-dfs.sh
3 zkServer.sh start
4 # slave1, slave2
5 zkServer.sh start
6 # master 
7 start-base.sh

8.2 檢查各節點的所有進程是否已啟動

[root@master ~]# jps
17136 HMaster
14532 QuorumPeerMain
16885 SecondaryNameNode
16695 NameNode
17324 Jps
[root@slave1 ~]# jps
11138 HRegionServer
11475 Jps
9479 QuorumPeerMain
11015 DataNode
11225 HMaster
[root@slave2 ~]# jps
5923 DataNode
6216 Jps
5288 QuorumPeerMain
6040 HRegionServer

9 訪問HBase

9.1 通過 HBase Shell 訪問

進入 hbase shell

hbase shell

在 hbase shell 中輸入 list 結果如下

hbase(main):001:0> list
TABLE
0 row(s) in 0.3050 seconds

=> []

9.2 通過 Web 訪問

打開網頁 http://master:16010(IP根據實際情況修改),可以看到如下頁面:

10 搭建完成

至此,基於阿里雲三台服務器的HBASE完全分布式集群搭建就完成了!

 

阿里雲ECS服務器部署HADOOP集群系列:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM