大数据运维HBase

HBase 题:

  1. 启动先电大数据平台的 Hbase 数据库,其中要求使用 master 节点的RegionServer。在 Linux Shell 中启动 Hbase shell,查看 HBase 的版本信息。(相关数据库命令语言请全部使用小写格式)
    [root@master ~]# hbase shell
    HBase Shell; enter ‘help’ for list of supported commands.
    Type “exit” to leave the HBase Shell
    Version 1.1.2.2.6.1.0-129, r718c773662346de98a8ce6fd3b5f64e279cb87d4, Wed May 31 03:27:31 UTC 2017

    hbase(main):001:0> version
    1.1.2.2.6.1.0-129, r718c773662346de98a8ce6fd3b5f64e279cb87d4, Wed May 31 03:27:31 UTC 2017

  2. 启动先电大数据平台的 Hbase 数据库,其中要求使用 master 节点的RegionServer。在 Linux Shell 中启动 Hbase shell,查看 HBase 的状态信息。(相关数据库命令语言请全部使用小写格式)
    [root@master ~]# hbase shell
    HBase Shell; enter ‘help’ for list of supported commands.
    Type “exit” to leave the HBase Shell
    Version 1.1.2.2.6.1.0-129, r718c773662346de98a8ce6fd3b5f64e279cb87d4, Wed May 31 03:27:31 UTC 2017

    hbase(main):002:0> status
    1 active master, 0 backup masters, 2 servers, 0 dead, 1.0000 average load

  3. 启动先电大数据平台的 Hbase 数据库,其中要求使用 master 节点的RegionServer。在 Linux Shell 中启动 Hbase shell,查看进入 HBase shell 的当前系统用户。(相关数据库命令语言请全部使用小写格式)
    [root@master ~]# hbase shell
    HBase Shell; enter ‘help’ for list of supported commands.
    Type “exit” to leave the HBase Shell
    Version 1.1.2.2.6.1.0-129, r718c773662346de98a8ce6fd3b5f64e279cb87d4, Wed May 31 03:27:31 UTC 2017

    hbase(main):001:0> whoami
    root (auth:SIMPLE)
    groups: root

  4. 在 HBase 数据库中创建表 xiandian_user,列族为 info,创建完成后查看xiandian_user 表的描述信息。(相关数据库命令语言请全部使用小写格式)
    [root@master ~]# hbase shell
    HBase Shell; enter ‘help’ for list of supported commands.
    Type “exit” to leave the HBase Shell
    Version 1.1.2.2.6.1.0-129, r718c773662346de98a8ce6fd3b5f64e279cb87d4, Wed May 31 03:27:31 UTC 2017

    hbase(main):002:0> create 'xiandian_user','info'
    0 row(s) in 5.0880 seconds

    => Hbase::Table - xiandian_user
    hbase(main):006:0> desc '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’, DATA_BLOCK_ENCODING => ‘NONE’, TT
    L => ‘FOREVER’, COMPRESSION => ‘NONE’, MIN_VERSIONS => ‘0’, BLOCKCACHE => ‘true’, BLOCKSIZE => ‘65536’, REPLICATION_SCOPE => ‘0’}
    1 row(s) in 0.0410 seconds

  5. 在 HBase Shell 创建表 xiandian_user,列族为 info,并 list 查询,之后删除这个表,并 list 查询。
    [root@master ~]# hbase shell
    HBase Shell; enter ‘help’ for list of supported commands.
    Type “exit” to leave the HBase Shell
    Version 1.1.2.2.6.1.0-129, r718c773662346de98a8ce6fd3b5f64e279cb87d4, Wed May 31 03:27:31 UTC 2017

    hbase(main):002:0> create 'xiandian_user','info'
    0 row(s) in 5.0880 seconds

    => Hbase::Table - xiandian_user

    hbase(main):009:0> disable 'xiandian_user'
    0 row(s) in 4.4040 seconds
    hbase(main):011:0> drop 'xiandian_user'
    0 row(s) in 2.4780 seconds

    hbase(main):012:0> list
    TABLE
    0 row(s) in 0.0070 seconds

    => []

  6. 开启 HBase 的安全认证功能,在 HBase Shell 中设置 root 用户拥有表xiandian_user 的读写与执行的权限,设置完成后,使用相关命令查看其权限信息。(相关数据库命令语言请全部使用小写格式)
    参数 hbase.security.authorization
    参数值 true
    [root@master ~]# su hbase
    [hbase@master ~]# hbase shell
    HBase Shell; enter ‘help’ for list of supported commands.
    Type “exit” to leave the HBase Shell
    Version 1.1.2.2.6.1.0-129, r718c773662346de98a8ce6fd3b5f64e279cb87d4, Wed May 31 03:27:31 UTC 2017
    hbase(main):002:0> grant 'root','RWX','xiandian_user'
    0 row(s) in 1.1550 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.0870 seconds

  7. 在Hbase Shell 中创建表xiandian,向表 xiandian 中插入一组数据为 xiandian,row1,info:name,xiaoming,插入后查询表 xiandian 中 rowkey 为 row1 的记录。
    [root@master ~]# su hbase
    [hbase@master root]$ hbase shell
    HBase Shell; enter ‘help’ for list of supported commands.
    Type “exit” to leave the HBase Shell
    Version 1.1.2.2.6.1.0-129, r718c773662346de98a8ce6fd3b5f64e279cb87d4, Wed May 31 03:27:31 UTC 2017

    hbase(main):001:0> create 'xiandian','info'
    0 row(s) in 4.8830 seconds

    => Hbase::Table - xiandian
    hbase(main):002:0> put 'xiandian','row1','info:name','xiaoming'
    0 row(s) in 0.1610 seconds

    hbase(main):003:0> scan 'xiandian'
    ROW COLUMN+CELL
    row1 column=info:name, timestamp=1557058474382, value=xiaoming
    1 row(s) in 0.0370 seconds

  8. 在 Hbase Shell 中创建表 xiandian,列族为“info”然后查询表中所有的记录。
    [root@master ~]# su hbase
    [hbase@master root]$ hbase shell
    HBase Shell; enter ‘help’ for list of supported commands.
    Type “exit” to leave the HBase Shell
    Version 1.1.2.2.6.1.0-129, r718c773662346de98a8ce6fd3b5f64e279cb87d4, Wed May 31 03:27:31 UTC 2017

    hbase(main):006:0> create 'xiandian','info'
    0 row(s) in 2.5460 seconds

    => Hbase::Table - xiandian
    hbase(main):007:0> scan 'xiandian'
    ROW COLUMN+CELL
    0 row(s) in 0.0130 seconds

  9. 登录 hbase 数据库,使用命令创建一张表,列族为 member_id’,‘address’,‘info’,创建完毕后查看该表的详细信息,后来发现列族’member_id’这个列族是多余的,需要删除,使用命令将该列族删除并查看详细信息,最后查看该表是否是 enabled 的。
    [root@master ~]# su hbase
    [hbase@master root]$ hbase shell
    HBase Shell; enter ‘help’ for list of supported commands.
    Type “exit” to leave the HBase Shell
    Version 1.1.2.2.6.1.0-129, r718c773662346de98a8ce6fd3b5f64e279cb87d4, Wed May 31 03:27:31 UTC 2017

    hbase(main):027:0> create 'xiandian','member_id','address','info'
    0 row(s) in 2.2860 seconds

    => Hbase::Table – xiandian
    hbase(main):028:0> disable ‘xiandian’
    0 row(s) in 4.3800 seconds

    hbase(main):029:0> alter 'xiandian','delete' => 'member_id'
    Updating all regions with the new schema…
    1/1 regions updated.
    Done.
    0 row(s) in 3.2900 seconds
    hbase(main):030:0> desc 'xiandian'
    Table xiandian is DISABLED
    xiandian
    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’, DATA_BLOCK_ENCODING => ‘NONE’, TT
    L => ‘FOREVER’, COMPRESSION => ‘NONE’, MIN_VERSIONS => ‘0’, BLOCKCACHE => ‘true’, BLOCKSIZE => ‘65536’, REPLICATION_SCOPE => ‘0’}
    2 row(s) in 0.0170 seconds
    hbase(main):033:0> is_enable 'xiandian'
    false
    0 row(s) in 0.0140 seconds

  10. 登录 hbase 数据库,创建一张表,列族为’address’,‘info’,创建完之后,向该表插入数据,插入完毕后,使用命令按照要求查询所需信息。
    [root@master ~]# su hbase
    [hbase@master root]$ hbase shell
    HBase Shell; enter ‘help’ for list of supported commands.
    Type “exit” to leave the HBase Shell
    Version 1.1.2.2.6.1.0-129, r718c773662346de98a8ce6fd3b5f64e279cb87d4, Wed May 31 03:27:31 UTC 2017

    hbase(main):001:0> create 'xiandian', 'adress','info'
    0 row(s) in 2.5070 seconds

    => Hbase::Table - xiandian
    hbase(main):018:0> put 'xiandian','row1','address','cq'
    0 row(s) in 0.0130 seconds

    hbase(main):019:0> put 'xiandian','row1','info:name','tp'
    0 row(s) in 0.0160 seconds

    hbase(main):020:0> scan 'xiandian'
    ROW COLUMN+CELL
    row1 column=address:, timestamp=1557141328204, value=cq
    row1 column=info:name, timestamp=1557141482938, value=tp
    1 row(s) in 0.0220 seconds

  11. 登录 hbase 数据库,新建一张表,列族为’address’,‘info’,创建完之后,向该表插入数据,插入之后查询这条信息,并修改信息,改完后,查询修改前和修改后的信息。
    [root@master ~]# su hbase
    [hbase@master root]$ hbase shell
    HBase Shell; enter ‘help’ for list of supported commands.
    Type “exit” to leave the HBase Shell
    Version 1.1.2.2.6.1.0-129, r718c773662346de98a8ce6fd3b5f64e279cb87d4, Wed May 31 03:27:31 UTC 2017

    hbase(main):001:0> create 'xiandian', 'adress','info'
    0 row(s) in 2.5070 seconds

    => Hbase::Table – xiandian
    hbase(main):018:0> put 'xiandian','row1','address','cq'
    0 row(s) in 0.0130 seconds

    hbase(main):019:0> put 'xiandian','row1','info:name','tp'
    0 row(s) in 0.0160 seconds

    hbase(main):020:0> scan 'xiandian'
    ROW COLUMN+CELL
    row1 column=address:, timestamp=1557141328204, value=cq
    row1 column=info:name, timestamp=1557141482938, value=tp
    1 row(s) in 0.0220 seconds
    hbase(main):021:0> put 'xiandian','row1','info:name','tp'
    0 row(s) in 0.0080 seconds

    hbase(main):022:0> scan 'xiandian'
    ROW COLUMN+CELL
    row1 column=address:, timestamp=1557141328204, value=cq
    row1 column=info:name, timestamp=1557141689559, value=tp
    1 row(s) in 0.0180 seconds

  12. 登录 hbase 数据库,创建一张表,列族为’address’,‘info’,创建完之后,向该表插入数据,插入完毕后,使用 scan 命令查询该表指定 startrow 的信息。
    [root@master ~]# su hbase
    [hbase@master root]$ hbase shell
    HBase Shell; enter ‘help’ for list of supported commands.
    Type “exit” to leave the HBase Shell
    Version 1.1.2.2.6.1.0-129, r718c773662346de98a8ce6fd3b5f64e279cb87d4, Wed May 31 03:27:31 UTC 2017

    hbase(main):001:0> create 'xiandian', 'adress','info'
    0 row(s) in 2.5070 seconds

    => Hbase::Table – xiandian
    hbase(main):018:0> put 'xiandian','row1','address','cq'
    0 row(s) in 0.0130 seconds

    hbase(main):019:0> put 'xiandian','row1','info:name','tp'
    0 row(s) in 0.0160 seconds
    hbase(main):023:0> scan 'xiandian',{LIMIT=>1}
    ROW COLUMN+CELL
    row1 column=address:, timestamp=1557141328204, value=cq
    row1 column=info:name, timestamp=1557141689559, value=tp
    1 row(s) in 0.0080 seconds

  13. 在关系数据库系统中,命名空间 namespace 是表的逻辑分组,同一组中的表有类似的用途。登录 hbase 数据库,新建一个命名空间叫 newspace 并用 list 查询,然后在这个命名空间中创建表,列族为’address’,‘info’,创建完之后,向该表插入数据,插入完毕后,使用 scan 命令只查询表中特定的信息。
    [root@master ~]# su hbase
    [hbase@master root]$ hbase shell
    HBase Shell; enter ‘help’ for list of supported commands.
    Type “exit” to leave the HBase Shell
    Version 1.1.2.2.6.1.0-129, r718c773662346de98a8ce6fd3b5f64e279cb87d4, Wed May 31 03:27:31 UTC 2017

    hbase(main):001:0> create_namespace 'newspace'
    0 row(s) in 0.3830 seconds
    hbase(main):002:0> list_namespace
    NAMESPACE
    default
    hbase
    newspace
    3 row(s) in 0.0240 seconds

    hbase(main):012:0> create 'newspace:xiandian','address','info'
    0 row(s) in 2.3070 seconds

    => Hbase::Table - newspace:xiandian
    hbase(main):014:0> put 'newspace:xiandian','row1','address:home','chongqing'
    0 row(s) in 0.1410 seconds

    hbase(main):015:0> put 'newspace:xiandian','row1','info:name','lisi'
    0 row(s) in 0.0120 seconds
    hbase(main):016:0> scan 'newspace:xiandian'
    ROW COLUMN+CELL
    row1 column=address:home, timestamp=1557162220928, value=chongq
    ing
    row1 column=info:name, timestamp=1557162576266, value=lisi
    1 row(s) in 0.2120 seconds

14.登录 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。
hbase(main):001:0> create 'test','cf'
0 row(s) in 2.6240 seconds

=> Hbase::Table – test
[hbase@master ~]$ cat hbasetest.txt
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
[hbase@master ~]$ hbase shell hbasetest.txt
0 row(s) in 0.3310 seconds

0 row(s) in 0.0070 seconds

0 row(s) in 0.0460 seconds

0 row(s) in 0.0600 seconds

ROW COLUMN+CELL
row1 column=cf:a, timestamp=1558924005629, value=value1
row2 column=cf:b, timestamp=1558924005661, value=value2
row3 column=cf:c, timestamp=1558924005694, value=value3
row4 column=cf:d, timestamp=1558924005732, value=value4
4 row(s) in 0.0300 seconds

COLUMN CELL
cf:a timestamp=1558924005629, value=value1
1 row(s) in 0.0510 seconds

猜你喜欢

转载自blog.csdn.net/mn525520/article/details/93776427