Apache HBase是Hadoop生態系統中面向列的分布式NoSQL數據庫。本文記錄在Ubuntu單機環境下部署HBase 0.92.1的完整流程,解決常見啟動故障,掌握基礎Shell命令操作。
$ tar xzf /home/cl/Downloads/hbase-0.92.1.tar.gz
$ mv hbase-0.92.1 /home/hbase-0.92.1
編輯conf/hbase-env.sh:
export JAVA_HOME=/usr/local/java/jdk1.6.0_30
編輯conf/hbase-site.xml(注意:原文為hbasev-site.xml,實際為hbase-site.xml):
<configuration>
<property>
<name>hbase.rootdir</name>
<value>file:///home/cl/hbase_data</value>
</property>
</configuration>
使用file://協議表示單機本地文件系統模式,生產環境應配置HDFS路徑(如hdfs://namenode:9000/hbase)。
$ cd /home/hbase-0.92.1/bin
$ ./start-hbase.sh
現象:日志logs/hbase-cl-master-thinkpad-zh.log出現:
WARN org.apache.hadoop.hbase.master.AssignmentManager:
Unable to find a viable location to assign region -ROOT-,,0.70236052
原因:/etc/hosts中主機名解析至127.0.1.1,HBase無法正確綁定地址。
修復:編輯/etc/hosts:
127.0.0.1 localhost
#127.0.1.1 thinkpad-zh ← 註釋掉這行
127.0.0.1 thinkpad-zh ← 添加這行
重啟HBase:
$ kill # 如有殘留進程
$ ./start-hbase.sh
$ ./hbase shell
HBase Shell; enter 'help' for list of supported commands.
Version 0.92.1, r1298924, Fri Mar 9 16:58:34 UTC 2012
hbase(main):001:0>
hbase(main):001:0> create 'my_first_table', 'col1', 'col2'
0 row(s) in 1.6050 seconds
語法:create '表名', '列族1', '列族2', ...。HBase按列族存儲,建表時必須指定至少一個列族。
hbase(main):002:0> list 'my_first_table'
TABLE
my_first_table
1 row(s) in 0.0150 seconds
hbase(main):003:0> exit
$ ./stop-hbase.sh
stopping hbase............
本文提供的單機部署流程適合學習HBase基本架構與Shell操作,為後續分布式集群部署打基礎。