Hbase初步入門(Mac OS 10.12.5)

單節點獨立的HBase實例上運行——>僞分佈式單機實例——>完全分佈式的集羣

1.下載壓縮包

wget http://mirror.bit.edu.cn/apache/hbase/1.3.1/hbase-1.3.1-bin.tar.gz

2.解壓(我是解壓到~/hadoop目錄下的,哪裏都無所謂)
3.cd ~/hadoop/hbase-1.3.1/
ls -al可以看到,此目錄下有如下內容,

drwxr-xr-x 14 mingleizhen staff 476 8 5 12:45 .
drwxr-xr-x 4 mingleizhen staff 136 8 5 12:37 ..
-rw-r–r–@ 1 mingleizhen staff 12292 8 5 14:10 .DS_Store
-rw-r–r– 1 mingleizhen staff 148959 4 7 09:45 CHANGES.txt
-rw-r–r– 1 mingleizhen staff 261 4 7 10:37 LEGAL
-rw-r–r– 1 mingleizhen staff 130696 4 7 10:37 LICENSE.txt
-rw-r–r– 1 mingleizhen staff 43258 4 7 10:37 NOTICE.txt
-rw-r–r– 1 mingleizhen staff 1477 9 21 2016 README.txt
drwxr-xr-x 31 mingleizhen staff 1054 4 5 11:02 bin
drwxr-xr-x 9 mingleizhen staff 306 4 5 11:02 conf
drwxr-xr-x 51 mingleizhen staff 1734 4 7 10:35 docs
drwxr-xr-x 7 mingleizhen staff 238 4 7 10:26 hbase-webapps
drwxr-xr-x 114 mingleizhen staff 3876 8 5 12:36 lib
drwxr-xr-x 6 mingleizhen staff 204 8 5 12:49 logs

進入docs目錄,瀏覽器打開book.html,發現是很詳細的文檔資料,不過是全英文的,有興趣可以慢慢看。

4.vim conf/hbase-site.xml,修改配置文件如下:

<configuration>
  <property>
    <name>hbase.rootdir</name>
    <value>file:///Users/mingleizhen/hadoop/hbase-1.3.1</value>
  </property>

  <property>
    <name>hbase.zookeeper.property.dataDir</name>
    <value>/Users/mingleizhen/hadoop/hbase-1.3.1/zookeeper</value>
  </property>

  <property>
    <name>hbase.master.info.port</name>
    <value>60011</value>
  </property>
</configuration>

5.cd ../bin/
執行啓動腳本

./start-hbase.sh

查看日誌文件:

tail -f ../logs/hbase-mingleizhen-master-mingleizhendeMacBook-Pro.local.log

有如下輸出,說明啓動成功。

2017-08-07 14:01:15,203 INFO [172.18.5.164:52497.activeMasterManager] master.HMaster: Master has completed initialization

6.jps
可看到 HMaster的進程

1597 Launcher
7197 HMaster
7789 Jps

瀏覽器訪問
http://localhost:60011
會自動跳轉到
http://localhost:60011/master-status

7.基礎命令
當前仍舊在bin目錄
執行./hbase shell
等待幾秒。有如下輸出:

2017-08-07 14:35:50,392 WARN  [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 1.3.1, r930b9a55528fe45d8edce7af42fef2d35e77677a, Thu Apr  6 19:36:54 PDT 2017

hbase(main):001:0>

然後,可以開始輸入命令做增刪改查的操作了
①創建表
使用create命令創建一個新表。必須指定表名和ColumnFamily名稱。

hbase(main):001:0> create 'test_table','test_cf'
0 row(s) in 1.4930 seconds

=> Hbase::Table - test_table

②使用list命令列出有關的表的信息

=> Hbase::Table - test_table
hbase(main):002:0> list 'test_table'
TABLE
test_table
1 row(s) in 0.0280 seconds

=> ["test_table"]

③put命令插入數據(或修改)

hbase(main):003:0> put 'test_table', 'row1', 'test_cf:a','value11'
0 row(s) in 10.1840 seconds

hbase(main):004:0> put 'test_table', 'row1', 'test_cf:a','value12'
0 row(s) in 0.0030 seconds

hbase(main):005:0> put 'test_table', 'row2', 'test_cf:b','value13'
0 row(s) in 0.0090 seconds

④scan命令瀏覽數據(爲什麼是2條?因爲以上有一條put是更新的數據)

hbase(main):006:0> scan 'test_table'
ROW                                           COLUMN+CELL
 row1                                         column=test_cf:a, timestamp=1502088093966, value=value12
 row2                                         column=test_cf:b, timestamp=1502088119751, value=value13
2 row(s) in 0.0190 seconds

⑤disable一張表

hbase(main):010:0> disable 'test_table'
0 row(s) in 2.2640 seconds

然後,去scan這張表,會發現不行了。
⑥enable一張表

hbase(main):011:0> enable 'test_table'
0 row(s) in 1.2470 seconds

然後,又可以scan這張表了。

⑦drop命令刪除表

hbase(main):012:0> drop 'test_table'

ERROR: Table test_table is enabled. Disable it first.

Here is some help for this command:
Drop the named table. Table must first be disabled:
  hbase> drop 't1'
  hbase> drop 'ns1:t1'

發現,需要先disbale纔可以刪除

hbase(main):014:0> disable 'test_table';drop 'test_table'
0 row(s) in 2.2700 seconds

0 row(s) in 1.2680 seconds

然後scan表test_table

hbase(main):015:0> scan 'test_table'
ROW                                           COLUMN+CELL

ERROR: Unknown table test_table!

⑧退出HBase Shell。

要退出HBase Shell並斷開與羣集的連接,請使用quit命令。HBase仍然在後臺運行。

hbase(main):016:0> quit

8.停止hbase服務
進入bin目錄
執行 ./stop-hbase.sh

mingleizhendeMacBook-Pro:bin mingleizhen$ ./stop-hbase.sh
stopping hbase............................

使用jps命令確保已經停止服務

mingleizhendeMacBook-Pro:bin mingleizhen$ jps
9014 Jps
1597 Launcher
1247
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章