HBase快速入門
1. HBase安裝部署
-
Zookeeper 正常部署
[codecat@hadoop102 zookeeper-3.5.9]$ bin/zkServer.sh start [codecat@hadoop103 zookeeper-3.5.9]$ bin/zkServer.sh start [codecat@hadoop104 zookeeper-3.5.9]$ bin/zkServer.sh start -
Hadoop 正常部署
[codecat@hadoop102 hadoop-3.1.3]$ sbin/start-dfs.sh [codecat@hadoop103 hadoop-3.1.3]$ sbin/start-yarn.sh -
HBase 的解壓
[codecat@hadoop102 software]$ tar -zxvf hbase-1.3.1-bin.tar.gz -C /opt/module -
HBase 的組態檔
hbase-env.sh修改內容如下:export JAVA_HOME=/opt/module/jdk1.8.0_212 export HBASE_MANAGES_ZK=falsehbase-site.xml修改內容如下:<configuration> <property> <name>hbase.rootdir</name> <value>hdfs://hadoop102:8020/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.5.9/zkData</value> </property> </configuration>regionservers修改內容如下:hadoop102 hadoop103 hadoop104- 軟連接
hadoop組態檔到HBase[codecat@hadoop102 module]$ ln -s /opt/module/hadoop-3.1.3/etc/hadoop/core-site.xml /opt/module/hbase-1.3.1/conf/core-site.xml [codecat@hadoop102 module]$ ln -s /opt/module/hadoop-3.1.3/etc/hadoop/hdfs-site.xml /opt/module/hbase-1.3.1/conf/hdfs-site.xml
-
HBase 遠程發送到其他集群
[codecat@hadoop102 hbase-1.3.1]$ xsync hbase-1.3.1/ -
HBase 服務的啟動與關閉
- 單節點啟動
注意: 如果集群之間的節點時間不同步,會導致[codecat@hadoop102 hbase-1.3.1]$ bin/hbase-daemon.sh start master [codecat@hadoop102 hbase-1.3.1]$ bin/hbase-daemon.sh start regionserverregionserver無法啟動,拋出ClockOutOfSyncException例外, - 群起
[codecat@hadoop102 hbase-1.3.1]$ bin/start-hbase.sh - 服務停止
[codecat@hadoop102 hbase-1.3.1]$ bin/stop-hbase.sh
- 單節點啟動
-
查看 Hbase 頁面
啟動成功后,可以通過
host:port的方式來訪問HBase管理頁面,例如:http://hadoop102:16010

2. HBase Shell 操作
2.1 基本操作
-
進入 HBase 客戶端命令列
[codecat@hadoop102 hbase-1.3.1]$ hbase shell -
查看幫助命令
hbase(main):001:0> help -
查看當前資料庫中有哪些表
hbase(main):002:0> list
2.2 表的操作
-
創建表
# 創建表名為student,列簇為info的表 hbase(main):003:0> create 'student', 'info' -
插入資料到表
# rowkey 為 1001;列為sex和age hbase(main):004:0> put 'student','1001','info:sex','male' hbase(main):005:0> put 'student','1001','info:age','18' # rowkey 為 1002;列為name、sex和age hbase(main):006:0> put 'student','1002','info:name','Janna' hbase(main):007:0> put 'student','1002','info:sex','female' hbase(main):008:0> put 'student','1002','info:age','20' -
掃描查看表資料
# 掃描整個表 hbase(main):001:0> scan 'student'
# rowkey從1001到1002掃描表 hbase(main):002:0> scan 'student',{STARTROW=>'1001',STOPROW=>'1002'}
可以看出區間是左閉右開
-
查看表結構
hbase(main):003:0> describe 'student'
-
更新指定欄位的資料
# 向rowkey為1001中的列簇info增加name列,并設定值為Nick hbase(main):004:0> put 'student','1001','info:name','Nick' # 修改rowkey為1001中列簇為info列為age的值 hbase(main):005:0> put 'student','1001','info:age','100' -
查看指定行或指定列族:列的資料
hbase(main):006:0> get 'student','1001'
hbase(main):007:0> get 'student','1001','info:name'
-
統計表資料行數
hbase(main):008:0> count 'student' -
變更表資訊
# 查看rowkey為1001,列簇為info,列為age,版本為2的資訊 hbase(main):009:0> get 'student','1001',{COLUMN=>'info:age',VERSIONS=>2}
由于創建info列族時,默認資料存放1個版本,所以這里只顯示了一條資料,現將info列族中的資料存放設定為2個版本,再次執行上述查詢
hbase(main):010:0> alter 'student',{NAME=>'info',VERSIONS=>2} hbase(main):012:0> put 'student','1001','info:age','98' hbase(main):013:0> get 'student','1001',{COLUMN=>'info:age',VERSIONS=>2}
-
洗掉資料
# 洗掉rowkey為1001的全部資料 hbase(main):014:0> deleteall 'student','1001' # 洗掉rowkey為1002,列族為info,列為sex的資料 hbase(main):016:0> delete 'student','1002','info:sex'
-
清空表資料
hbase(main):020:0> truncate 'student'
清空表的操作順序為先
disable,然后再truncate -
洗掉表
hbase(main):024:0> disable 'student' hbase(main):025:0> drop 'student'
如果直接
drop表,會報錯
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/347089.html
標籤:其他
