HBase最新穩(wěn)定版本是2017年7月份的1.2.6版本。很多用戶還是0.92.x 。
盡管版本不同,原理確是相似的。若覺得長,可挑重點(diǎn)看。
下載地址:hbase-1.2.6-bin.tar.gz
說明
本文主要講在本地測試環(huán)境的HBASE的安裝配置,可以安裝VMWare虛擬機(jī),
CDH版本會在另外文章發(fā)表。
1.簡介
以下簡單理解,有個感性認(rèn)識,面試時(shí)可忽悠。
- 一種類似KV的NoSql數(shù)據(jù)庫。
- 一種“強(qiáng)一致性”讀寫,而非“最終一致性”的數(shù)據(jù)存儲,很適合快速實(shí)時(shí)聚合統(tǒng)計(jì)的計(jì)算任務(wù)。
- 隨著你的數(shù)據(jù)增長,Hbase會自動分片sharding,重新分布數(shù)據(jù)。
- RegionServer 可以自動fallover檢測。
- 可以用HDFS作為文件存儲系統(tǒng)
- 支持作為大規(guī)模MR并行計(jì)算的數(shù)據(jù)源和存儲地。
- 可以用Java Client API 操作HBASE
- 可以用Thrift和Restful 非JAVA語言操作
- 海量數(shù)據(jù)查詢時(shí),可以用Block Cache和Bloom Filter作為優(yōu)化
2.使用場景
首先,你要有足夠的數(shù)據(jù),有億級別和數(shù)十億級別時(shí)候比較適合,百萬,千萬級別的用傳統(tǒng)的RDBMS數(shù)據(jù)庫是更好的選擇。
其次,你可以容忍沒有RDBMS那種字段類型,二級索引,事務(wù),高級查詢語法等功能.
第三,你要確保有足夠的硬件資源,HDFS的datanode最有有5個(副本因子為3,NameNode,SecondNameNode 2個)。
有HDFS了,為何還需要HBase?
HDFS只是非常適合存儲大規(guī)模files而已,并沒有提供record的快速檢索和更新功能,而HBASE則提供。
3. 安裝
重點(diǎn)注意事項(xiàng)
3.1 JAVA_HOME 配置
JAVA_HOME=/usr/jdk (注,必須在JDK7以上)
在HBASE集群中的每個節(jié)點(diǎn) hbase-env.sh里配置
HBASE&JDK版本的支持
| Base Version | JDK7 | JDK 8 |
|---|---|---|
| 2.0 | Not Supported | yes |
| 1.3 | yes | yes |
| 1.2 | yes | yes |
| 1.1 | yes | Running with JDK 8 will work but is not well tested. |
3.2 NTP設(shè)置
保證cluster集群里各個節(jié)點(diǎn)的時(shí)間一致。(自己去度娘)
3.3 設(shè)置ulimit (要學(xué)會估算)
Hbase 可能要求一次打開大量的文件,而系統(tǒng)個默認(rèn)可能1024.最好是1024的整數(shù)備,如102400.
ulimit -n
估算示例:
1.一個RegionServer含100個region
2.一個region有3個ColumnFamily列簇
3.一個ColumnFamily平均3個StoreFiles
那么,JVM會open 100*3*3=900個 file descriptors
3.1單機(jī) Standalone HABE
$ tar xzvf hbase-3.0.0-SNAPSHOT-bin.tar.gz
$ cd hbase-3.0.0-SNAPSHOT/
若果你在本地電腦安裝,那么一個Instance就包行了所有的守護(hù)線程如Master, RegionServers, and ZooKeeper。他們運(yùn)行在一個JVM虛擬機(jī)上。
如果你的Hbase是 0.94.x之前版本,需要配置
vi /ets/host127.0.0.1 localhost
否則可能會報(bào)錯。
不需要自己手動配置hbase data目錄,在base-site.xml配置可自動生成
<configuration>
<property>
<name>hbase.rootdir</name>
<value>file:///home/testuser/hbase</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/home/testuser/zookeeper</value>
</property>
</configuration>
啟動HBASE
bin/start-hbase.sh
Hbase WEB UI訪問
Hbase 啟動和停止
./bin/hbase shell
$ ./bin/stop-hbase.sh
3.2 偽分布式
vi hbase-site.xml
增加,如下
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
同時(shí),修改hbase.root ,在HDFS里也也不需要手動創(chuàng)建目錄
<property>
<name>hbase.rootdir</name>
<value>hdfs://localhost:8020/hbase</value>
</property>
重啟hbase服務(wù)后,可用hadoop命令看到結(jié)果
$ ./bin/hadoop fs -ls /hbase
Found 7 items
drwxr-xr-x - hbase users 0 2014-06-25 18:58 /hbase/.tmp
drwxr-xr-x - hbase users 0 2014-06-25 21:49 /hbase/WALs
drwxr-xr-x - hbase users 0 2014-06-25 18:48 /hbase/corrupt
drwxr-xr-x - hbase users 0 2014-06-25 18:58 /hbase/data
-rw-r--r-- 3 hbase users 42 2014-06-25 18:41 /hbase/hbase.id
-rw-r--r-- 3 hbase users 7 2014-06-25 18:41 /hbase/hbase.version
drwxr-xr-x - hbase users 0 2014-06-25 21:49 /hbase/oldWALs
3.3 Full 分布式 HBASE
三個節(jié)點(diǎn):node-a ,node-b,node-c
- 保證各個節(jié)點(diǎn)可以相互訪問,關(guān)閉防火墻(否則,可能會出現(xiàn) no route to host)
- node-a 必須可以登錄 node-b 和 node-c (包括自身) ,如此以來,可以啟動各個節(jié)點(diǎn)的守護(hù)進(jìn)程。
在 node-a 上 生成SSH access
$ ssh-keygen -t rsa
$ cat id_rsa.pub >> ~/.ssh/authorized_keys
使用下面命令,將公鑰拷貝到其它節(jié)點(diǎn)上
ssh-copy-id -i ~/.ssh/id_rsa.pub node-a
ssh-copy-id -i ~/.ssh/id_rsa.pub node-b
ssh-copy-id -i ~/.ssh/id_rsa.pub node-c
chmod 600 authorized_keys
3.若backup角色的master啟動了,也需要按2操作來一遍,讓node-b可以訪問其它節(jié)點(diǎn)。 注意,別覆蓋了,使用>> 而不是>
| Node Name | Master | ZooKeeper | RegionServer |
|---|---|---|---|
| node-a.example.com | yes | yes | no |
| node-b.example.com | backup | yes | yes |
| node-c.example.com | yes | yes | yes |
vi hbase-site.xml
增加zk配置
<property>
<name>hbase.zookeeper.quorum</name>
<value>node-a.example.com,node-b.example.com,node-c.example.com</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/usr/local/zookeeper</value>
</property>
當(dāng)Node-a的hbase配置好后,打包scp到node-b和node-c節(jié)點(diǎn)。
在node-a節(jié)點(diǎn)啟動
start-hbase.sh
啟動的順序一般是:
1.ZooKeeper starts first,
2.followed by the master,
3.then the RegionServers,
- finally the backup masters.
接下來驗(yàn)證下是否啟動成功,使用Jps命令
node-a:
$ jps
20355 Jps
20071 HQuorumPeer (zk)
20137 HMaster
node-b:
$ jps
15930 HRegionServer
16194 Jps
15838 HQuorumPeer (zk)
16010 HMaster (backup)
node-c :
$ jps
13901 Jps
13639 HQuorumPeer (zk)
13737 HRegionServer
HQuorumPeer是由HBase控制和啟動的,這里的zookeeper是HBASE自帶的,一般適用于測試環(huán)境,生成環(huán)境建議用外部獨(dú)立的ZK集群。
自帶和外部獨(dú)立的zk進(jìn)程區(qū)別:
HQuorumPeer :自帶
QuorumPeer :獨(dú)立
HBase WEI UI 訪問
http://node-a.example.com:16010/ 主master
http://node-b.example.com:16010/ 備master
3個節(jié)點(diǎn)的hbase集群,其實(shí)并不是非常有彈性,你可以試試kill掉master進(jìn)程或RegionServer進(jìn)程 觀察日志看看。