大数据系列之运维(自主搭建的大数据平台)
(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三位博主的相关博客。