1. 程式人生 > 實用技巧 >Hbase基礎(二):HBase 快速入門

Hbase基礎(二):HBase 快速入門

1 HBase 安裝部署

1.1 Zookeeper 正常部署 首先保證 Zookeeper 叢集的正常部署,並啟動之:
[atguigu@hadoop102 zookeeper-3.4.10]$ bin/zkServer.sh start
[atguigu@hadoop103 zookeeper-3.4.10]$ bin/zkServer.sh start
[atguigu@hadoop104 zookeeper-3.4.10]$ bin/zkServer.sh start
1.2 Hadoop 正常部署 Hadoop 叢集的正常部署並啟動:
[atguigu@hadoop102 hadoop-2.7.2]$ sbin/start-dfs.sh
[atguigu@hadoop103 hadoop
-2.7.2]$ sbin/start-yarn.sh
1.3 HBase 的解壓 解壓 Hbase 到指定目錄:
[atguigu@hadoop102 software]$ tar -zxvf hbase-1.3.1-bin.tar.gz -C /opt/module
1.4 HBase 的配置檔案 修改 HBase 對應的配置檔案。 1)hbase-env.sh 修改內容:
export JAVA_HOME=/opt/module/jdk1.6.0_144
export HBASE_MANAGES_ZK=false
2)hbase-site.xml 修改內容:
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://
hadoop102:9000/HBase</value> </property> <property> <name>hbase.cluster.distributed</name> <value>true</value> </property> <!-- 0.98 後的新變動,之前版本沒有.port,預設埠為 60000 --> <property> <name>hbase.master.port</name> <value>16000</value> </property> <property> <name>hbase.zookeeper.quorum</name> <value>hadoop102,hadoop103,hadoop104</value> </property> <property> <name>hbase.zookeeper.property.dataDir</name> <value>/opt/module/zookeeper-3.4.10/zkData</value> </property> </configuration>
View Code 3)regionservers:
hadoop102
hadoop103
hadoop104
4)軟連線 hadoop 配置檔案到 HBase:
[atguigu@hadoop102 module]$ ln -s /opt/module/hadoop-2.7.2/etc/hadoop/core-site.xml /opt/module/hbase/conf/core-site.xml
[atguigu@hadoop102 module]$ ln -s /opt/module/hadoop-2.7.2/etc/hadoop/hdfs-site.xml /opt/module/hbase/conf/hdfs-site.xml
1.5 HBase 遠端傳送到其他叢集
[atguigu@hadoop102 module]$ xsync hbase/
1.6 HBase 服務的啟動 1.啟動方式
[atguigu@hadoop102 hbase]$ bin/hbase-daemon.sh start master
[atguigu@hadoop102 hbase]$ bin/hbase-daemon.sh start regionserver
提示:如果叢集之間的節點時間不同步,會導致 regionserver 無法啟動,丟擲ClockOutOfSyncException 異常。 修復提示: a、同步時間服務 請參看幫助文件:《尚矽谷大資料技術之 Hadoop 入門》 b、屬性:hbase.master.maxclockskew 設定更大的值
<property>
 <name>hbase.master.maxclockskew</name>
 <value>180000</value>
 <description>Time difference of regionserver from 
master</description>
</property>
2.啟動方式 2
[atguigu@hadoop102 hbase]$ bin/start-hbase.sh
對應的停止服務:
[atguigu@hadoop102 hbase]$ bin/stop-hbase.sh
1.7 檢視 HBase 頁面 啟動成功後,可以通過“host:port”的方式來訪問 HBase 管理頁面,例如: http://hadoop102:16010

2 HBase Shell 操作

2.1 基本操作 1.進入 HBase 客戶端命令列
[atguigu@hadoop102 hbase]$ bin/hbase shell
2.檢視幫助命令
hbase(main):001:0> help
3.檢視當前資料庫中有哪些表
hbase(main):002:0> list
2.2 表的操作 1.建立表
hbase(main):002:0> create 'student','info'
2.插入資料到表
hbase(main):003:0> put 'student','1001','info:sex','male'
hbase(main):004:0> put 'student','1001','info:age','18'
hbase(main):005:0> put 'student','1002','info:name','Janna'
hbase(main):006:0> put 'student','1002','info:sex','female'
hbase(main):007:0> put 'student','1002','info:age','20'
3.掃描查看錶資料
hbase(main):008:0> scan 'student'
hbase(main):009:0> scan 'student',{STARTROW => '1001', STOPROW => 
'1001'}
hbase(main):010:0> scan 'student',{STARTROW => '1001'}
4.查看錶結構
hbase(main):011:0> describe ‘student’
5.更新指定欄位的資料
hbase(main):012:0> put 'student','1001','info:name','Nick'
hbase(main):013:0> put 'student','1001','info:age','100'
6.檢視“指定行”或“指定列族:列”的資料
hbase(main):014:0> get 'student','1001'
hbase(main):015:0> get 'student','1001','info:name'
7.統計表資料行數
hbase(main):021:0> count 'student'
8.刪除資料 刪除某 rowkey 的全部資料:
hbase(main):016:0> deleteall 'student','1001'
刪除某 rowkey 的某一列資料:
hbase(main):017:0> delete 'student','1002','info:sex'
9.清空表資料
hbase(main):018:0> truncate 'student'
提示:清空表的操作順序為先 disable,然後再 truncate。 10.刪除表 首先需要先讓該表為 disable 狀態:
hbase(main):019:0> disable 'student'
然後才能 drop 這個表:
hbase(main):020:0> drop 'student'
提示:如果直接 drop 表,會報錯:ERROR: Table student is enabled. Disable it first. 11.變更表資訊 將 info 列族中的資料存放 3 個版本:
hbase(main):022:0> alter 'student',{NAME=>'info',VERSIONS=>3}
hbase(main):022:0> get 
'student','1001',{COLUMN=>'info:name',VERSIONS=>3}