大資料系列之運維(自主搭建的大資料平台)
(3)HBase運維
- 啟動Hbase 資料庫,其中要求使用相關節點的RegionServer。在 Linux Shell 中啟動 Hbase shell,檢視 HBase 的版本資訊;檢視 HBase 的狀态資訊;檢視進入HBase shell 的目前系統使用者
hbase(main):002:0> version
1.2.4, r67592f3d062743907f8c5ae00dbbe1ae4f69e5af, Tue Oct 25 18:10:20 CDT 2016
hbase(main):003:0> status
1 active master, 0 backup masters, 2 servers, 0 dead, 1.0000 average load
hbase(main):004:0> whoami
root (auth:SIMPLE)
groups: root
建議先使用幫助指令:
hbase(main):001:0> help
- 在 HBase 資料庫中建立表 xiandian_user,列族為 info,建立完成後檢視xiandian_user 表的描述資訊;開啟 HBase 的安全認證功能,在 HBase Shell 中設定 root 使用者擁有表xiandian_user 的讀寫與執行的權限,設定完成後,使用相關指令檢視其權限資訊;并 list 查詢,之後删除這個表,并 list 查詢。
hbase(main):006:0> create 'xiandian_user', 'info'
0 row(s) in 1.5650 seconds
=> Hbase::Table - xiandian_user
hbase(main):008:0> describe 'xiandian_user'
Table xiandian_user is ENABLED
xiandian_user
COLUMN FAMILIES DESCRIPTION
{NAME => 'info', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DAT
A_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true',
BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
1 row(s) in 0.1750 seconds
要啟用hbase授權,必須在hbase-site.xml中配置以下屬性:
<property>
<name>hbase.superuser</name>
<value>root,hadoop</value>
</property>
<property>
<name>hbase.coprocessor.region.classes</name>
<value>org.apache.hadoop.hbase.security.access.AccessController</value>
</property>
<property>
<name>hbase.coprocessor.master.classes</name>
<value>org.apache.hadoop.hbase.security.access.AccessController</value>
</property>
<property>
<name>hbase.rpc.engine</name>
<value>org.apache.hadoop.hbase.ipc.SecureRpcEngine</value>
</property>
<property>
<name>hbase.security.authorization</name>
<value>true</value>
</property>
将修改後的hbase-site.xml檔案分發到其他節點。
然後重新開機HBase。
由于本人自己搭建的大資料平台,不是用先電版的,會存在差異。先電版的開啟安全認證功能隻需要改上述最後一項的值為true。
hbase(main):001:0> grant 'root','RWX','xiandian_user'
0 row(s) in 1.0210 seconds
hbase(main):003:0> user_permission 'xiandian_user'
User Namespace,Table,Family,Qualifier:Permission
root default,xiandian_user,,: [Permission: actions=READ,WRITE,EXEC]
1 row(s) in 0.1430 seconds
hbase(main):004:0> list
TABLE
xiandian_user
1 row(s) in 0.0340 seconds
=> ["xiandian_user"]
hbase(main):008:0> help "drop"
Drop the named table. Table must first be disabled #删除命名表。必須首先禁用表
hbase(main):009:0> disable 'xiandian_user'
0 row(s) in 2.3820 seconds
hbase(main):010:0> drop 'xiandian_user'
0 row(s) in 1.4640 seconds
hbase(main):011:0> list
TABLE
0 row(s) in 0.0130 seconds
=> []
- 在 Hbase Shell 中建立表 xiandian,列族為“info”,向表 xiandian 中插入一組資料為xiandian,row1,info:name,xiaoming,插入後查詢表 xiandian 中 rowkey 為 row1 的記錄。查詢表中所有的記錄
解釋一下這個題目:
向表 xiandian 中插入一組資料為xiandian,row1,info:name,xiaoming
上述的xiandian是要插入資料的表名,row1是row key, info:name是列,info是列族,xiaoming
是值。下面是檢視put 的幫助資訊得到的。
hbase> put 't1', 'r1', 'c1', 'value'
hbase(main):015:0> put 'xiandian', 'row1', 'info:name', 'xiaoming'
0 row(s) in 0.1340 seconds
檢視get的幫助資訊如下:
hbase> t.get 'r1'
結合題目我們的文法如下:
hbase(main):017:0> get 'xiandian','row1'
COLUMN CELL
info:name timestamp=1585561948806, value=xiaoming
1 row(s) in 0.0460 seconds
hbase(main):019:0> scan 'xiandian'
ROW COLUMN+CELL
row1 column=info:name, timestamp=1585561948806, value=xiaoming
1 row(s) in 0.0260 seconds
- 登入 hbase 資料庫,使用指令建立一張表,列族為 ‘member_id’,‘address’,‘info’,建立完畢後檢視該表的詳細資訊,後來發現列族’member_id’這個列族是多餘的,需要删除,使用指令将該列族删除并檢視詳細資訊,最後檢視該表是否是 enabled 的。
hbase(main):020:0> create 'xiandian1','member_id','address','info'
0 row(s) in 2.2840 seconds
=> Hbase::Table - xiandian1
hbase(main):021:0> describe 'xiandian1'
Table xiandian1 is ENABLED
xiandian1
COLUMN FAMILIES DESCRIPTION
{NAME => 'address', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE',
DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true
', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
{NAME => 'info', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DAT
A_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true',
BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
{NAME => 'member_id', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE'
, DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'tr
ue', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
3 row(s) in 0.0490 seconds
#Xiandian1表建了3個列族,但是發現member_id這個列族是多餘的,因為他就是主鍵,是以我們要将其删除。
hbase(main):023:0> alter 'xiandian1','delete'=>'member_id'
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 2.7280 seconds
hbase(main):024:0> describe 'xiandian1'
Table xiandian1 is ENABLED
xiandian1
COLUMN FAMILIES DESCRIPTION
{NAME => 'address', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE',
DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true
', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
{NAME => 'info', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DAT
A_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true',
BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
2 row(s) in 0.0510 seconds
hbase(main):025:0> is_enabled 'xiandian1'
true
-
在關系資料庫系統中,命名空間 namespace 是表的邏輯分組,同一組中的表有類似的用途。hbase 非關系型資料庫也有命名空間。登入 hbase資料庫,建立一個命名空間叫 newspace 并用 list 查詢,然後在這個命名空間中建立表member,列族為’address’,’info’。向該表插入的資料為:
‘xiandianA’,‘info:age’,‘29’
‘xiandianA’,‘info:birthday’,‘1990-07-17’
‘xiandianA’,‘info:company’,‘qirui’
‘xiandianA’,‘address:contry’,‘china’
‘xiandianA’,‘address:province’,‘anhui’
‘xiandianA’,‘address:city’,‘wuhu’
使用scan指令隻查詢表中’info:age’的資訊,指定startrow為xiandianA。 #兩個條件
hbase(main):003:0> create_namespace 'newspace'
hbase(main):004:0> list_namespace
NAMESPACE
default
hbase
newspace
hbase(main):006:0> create 'newspace:member','address','info'
=> Hbase::Table - newspace:member
hbase(main):007:0> put 'newspace:member','xiandianA','info:age','29'
hbase(main):008:0> put 'newspace:member','xiandianA','info:birthday','1990-07-17'
hbase(main):009:0> put 'newspace:member','xiandianA','info:company','qirui'
hbase(main):010:0> put 'newspace:member','xiandianA','address:contry','china'
hbase(main):011:0> put 'newspace:member','xiandianA','address:province','anhui'
hbase(main):012:0> put 'newspace:member','xiandianA','address:city','wuhu'
hbase(main):014:0> scan 'newspace:member',{COLUMNS => ['info:age'],STARTROW => 'xiandianA'}
ROW COLUMN+CELL
xiandianA column=info:age, timestamp=1585573632167, value=29
- 将表member中的’info:age’的值改為99,改完後,查詢修改前和修改後的資訊。
hbase(main):019:0> get 'newspace:member','xiandianA','info:age'
COLUMN CELL
info:age timestamp=1585573632167, value=29
hbase(main):020:0> put 'newspace:member','xiandianA','info:age','99'
hbase(main):021:0> get 'newspace:member','xiandianA','info:age'
COLUMN CELL
info:age timestamp=1585574884524, value=99
hbase(main):023:0> get 'newspace:member','xiandianA',{COLUMNS => ['info:age'],TIMESTAMP => 1585573632167}
COLUMN CELL
info:age timestamp=1585573632167, value=29
hbase(main):022:0> get 'newspace:member','xiandianA',{COLUMNS => ['info:age'],TIMESTAMP => 1585574884524}
COLUMN CELL
info:age timestamp=1585574884524, value=99
-
登入 master 節點,在本地建立一個檔案叫 hbasetest.txt 檔案,編寫内容,要求建立一張表為’test’, 列族為’cf’,然後向這張表批量插入資料,資料如下所示:
‘row1’, ‘cf:a’, ‘value1’
‘row2’, ‘cf:b’, ‘value2’
‘row3’, ‘cf:c’, ‘value3’
‘row4’, ‘cf:d’, ‘value4’
在插入資料完畢後用 scan 指令查詢表内容,然後用 get 指令隻查詢 row1 的内容,最後退出 hbase shell。
[[email protected] ~]# vi hbasetest.txt
create 'test','cf'
list 'test'
put 'test','row1','cf:a','value1'
put 'test','row2','cf:b','value2'
put 'test','row3','cf:c','value3'
put 'test','row4','cf:d','value4'
scan 'test'
get 'test','row1'
exit
[[email protected] ~]# hbase shell hbasetest.txt
HBase運維遇到的問題
hbase(main):002:0> grant 'root','RWX','xiandian_user'
ERROR: DISABLED: Security features are not available
原因:
在hbase-2.x之後,預設的“hbase.security.authorization”發生了變化。
在hbase-2.x之前,它預設為true,在後來的HBase版本中,預設值變為false。
是以,要啟用hbase授權,必須在hbase-site.xml中配置以下屬性:
<property>
<name>hbase.superuser</name>
<value>root,hadoop</value>
</property>
<property>
<name>hbase.coprocessor.region.classes</name>
<value>org.apache.hadoop.hbase.security.access.AccessController</value>
</property>
<property>
<name>hbase.coprocessor.master.classes</name>
<value>org.apache.hadoop.hbase.security.access.AccessController</value>
</property>
<property>
<name>hbase.rpc.engine</name>
<value>org.apache.hadoop.hbase.ipc.SecureRpcEngine</value>
</property>
<property>
<name>hbase.security.authorization</name>
<value>true</value>
</property>
在此感謝先電雲提供的題庫。
感謝Apache開源技術服務支援
感謝抛物線、mn525520、菜鳥一枚2019三位部落客的相關部落格。