首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> C >> 關於C

HBase單機模式快速入門:從安裝到Shell操作實戰

     編輯:關於C

Apache HBase是Hadoop生態系統中面向列的分布式NoSQL數據庫。本文記錄在Ubuntu單機環境下部署HBase 0.92.1的完整流程,解決常見啟動故障,掌握基礎Shell命令操作。

環境準備

  • OS:Ubuntu 11.10
  • JDK:1.6.0_30
  • HBase:hbase-0.92.1.tar.gz
  • 用戶:cl,主機名:thinkpad-zh

安裝步驟

1. 解壓並部署


$ tar xzf /home/cl/Downloads/hbase-0.92.1.tar.gz
$ mv hbase-0.92.1 /home/hbase-0.92.1

2. 配置JAVA_HOME

編輯conf/hbase-env.sh:


export JAVA_HOME=/usr/local/java/jdk1.6.0_30

3. 配置數據存儲路徑

編輯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)。

啟動與驗證

1. 啟動HBase


$ cd /home/hbase-0.92.1/bin
$ ./start-hbase.sh

2. 常見故障:無法創建表(卡在create命令)

現象:日志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 基礎操作

1. 進入Shell


$ ./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>

2. 創建表


hbase(main):001:0> create 'my_first_table', 'col1', 'col2'
0 row(s) in 1.6050 seconds

語法:create '表名', '列族1', '列族2', ...。HBase按列族存儲,建表時必須指定至少一個列族。

3. 列表表


hbase(main):002:0> list 'my_first_table'
TABLE
my_first_table
1 row(s) in 0.0150 seconds

4. 退出Shell


hbase(main):003:0> exit

5. 停止HBase


$ ./stop-hbase.sh
stopping hbase............

核心概念速覽

  • Row Key:行鍵,表的主鍵,按字典序排序
  • Column Family:列族,物理存儲單元,建表時定義,列族下可動態添加列
  • Column Qualifier:列限定符,列族具體的列名
  • Timestamp:時間戳,版本控制,默認保留最新3版本
  • Region:區域,表水平切分單元,由RegionServer管理

單機模式局限與生產部署提示

  • 單機模式所有服務(Master、RegionServer、ZooKeeper)運行在同一JVM,無高可用
  • 數據存儲本地文件系統,非分布式,不適合生產
  • 生產環境需:HDFS集群、ZooKeeper集群、多RegionServer、備份Master
  • 版本建議:使用HBase 2.x+(對應Hadoop 3.x),0.92版本過於古老(2012年發布)

本文提供的單機部署流程適合學習HBase基本架構與Shell操作,為後續分布式集群部署打基礎。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved