0


HBase

简单架构

部分架构

HBase开启

1、启动hadoop

start-all.sh

验证
http://master:50070

2、启动zookeeper
需要在在三台中分别启动
zkServer.sh start
zkServer.sh status

3、启动hbase集群 , 需要在master上执行

start-hbase.sh
stop-hbase.sh
4、验证hbase
http://master:16010
通过 hbase shell 进入到hbase的命令行

NoSQL:
理解: NOT ONLY SQL non-relational(非关系型数据库)

HBASE SHELL 学习:

  1. 1、进入HBASE
  2. 命令: hbase shell
  3. 2help 查看Hbase shell 支持命令:

Group name: general
Commands: processlist, status, table_help, version, whoami

Group name: ddl
Commands: alter, alter_async, alter_status, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, list_regions, locate_region, show_filters

Group name: namespace
Commands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables

Group name: dml
Commands: append, count, delete, deleteall, get, get_counter, get_splits, incr, put, scan, truncate, truncate_preserve

  1. 3general
  2. 查看版本:
  3. version
  4. 查看HBASE当前状态:
  5. status

4、ddl

  1. 5namespace
  2. 1.create_namespace 创建命名空间
  3. hbase> create_namespace 'ns1'
  4. hbase> create_namespace 'ns1', {'PROPERTY_NAME'=>'PROPERTY_VALUE'}
  5. create_namespace 'mydb1'
  6. create_namespace 'mydb2',{'create_time' => '2022-04-25'}
  7. 2.list_namespace 查看当前命名空间
  8. 样例:list_namespace
  9. 结果:
  10. default -- 用户默认使用的命名空间
  11. hbase -- hbase中存放的是HBase内置的表
  12. 3.describe_namespace 查看命名空间的详细信息
  13. hbase> describe_namespace 'ns1'
  14. describe_namespace 'mydb1'
  15. 4.alter_namespace 修改命名空间
  16. To add/modify a property:
  17. hbase> alter_namespace 'ns1', {METHOD => 'set', 'PROPERTY_NAME' => 'PROPERTY_VALUE'}
  18. To delete a property:
  19. hbase> alter_namespace 'ns1', {METHOD => 'unset', NAME=>'PROPERTY_NAME'}
  20. 样例:
  21. 增加author配置并且修改create_time配置
  22. alter_namespace 'mydb2',{METHOD => 'set', 'author'=> 'act', 'create_time' => '2022-4-26'}
  23. alter_namespace 'mydb2',{'METHOD' => 'set', 'author'=> 'act', 'create_time' => '2022-4-27'}
  24. 删除create_time配置
  25. alter_namespace 'mydb2',{METHOD => 'unset', NAME=>'create_time'}
  26. 5.drop_namespace 删除空的命名空间
  27. drop_namespace 'mydb2'
  28. 6.list_namespace_tables 查看指定命名空间下的表
  29. list_namespace_tables 'default'

6、DDL-表操作

  1. 1.create 创建表
  2. t1:表示表名称
  3. f1:表示列族bersion
  4. ns1:表示命名空间
  5. Create a table with namespace=ns1 and table qualifier=t1
  6. hbase> create 'ns1:t1', {NAME => 'f1', VERSIONS => 5}
  7. Create a table with namespace=default and table qualifier=t1
  8. hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}
  9. hbase> # The above in shorthand would be the following:
  10. hbase> create 't1', 'f1', 'f2', 'f3'
  11. hbase> create 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true}
  12. hbase> create 't1', {NAME => 'f1', CONFIGURATION => {'hbase.hstore.blockingStoreFiles' => '10'}}
  13. Table configuration options can be put at the end.
  14. Examples:
  15. hbase> create 'ns1:t1', 'f1', SPLITS => ['10', '20', '30', '40']
  16. hbase> create 't1', 'f1', SPLITS => ['10', '20', '30', '40']
  17. hbase> create 't1', 'f1', SPLITS_FILE => 'splits.txt', OWNER => 'johndoe'
  18. hbase> create 't1', {NAME => 'f1', VERSIONS => 5}, METADATA => { 'mykey' => 'myvalue' }
  19. hbase> # Optionally pre-split the table into NUMREGIONS, using
  20. hbase> # SPLITALGO ("HexStringSplit", "UniformSplit" or classname)
  21. hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit'}
  22. hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit', REGION_REPLICATION => 2, CONFIGURATION => {'hbase.hregion.scan.loadColumnFamiliesOnDemand' => 'true'}}
  23. hbase> create 't1', {NAME => 'f1', DFS_REPLICATION => 1}
  24. You can also keep around a reference to the created table:
  25. hbase> t1 = create 't1', 'f1'
  26. 样例:
  27. 默认命名空间下创建mytb1表,列族为info
  28. create 'mytb1', 'info'
  29. db1命名空间下创建表
  30. create_namespace 'db1'
  31. create 'db1:mytb1', 'info1'
  32. 创建表时指定多个列族
  33. create 'db1:mytb2', 'info1', 'info2', 'info3'
  34. 创建表并指定列族版本
  35. create 'db1:mytb4',{NAME => 'info1',VERSIONS => 3}
  36. 2.describe 查看表的具体信息
  37. 样例:
  38. describe 'db1:mytb2'
  39. 表中的列族信息中可以看出,每个列族都维护自己的一个版本信息,一个列族对应一个store
  40. describe 'db1:mytb4'
  41. desc 'db1:mytb4'
  42. 3.alter 修改表
  43. help 'alter'
  44. 样例:
  45. 1.修改列族版本号
  46. alter 't1', NAME => 'f1', VERSIONS => 5
  47. alter 'db1:mytb4', NAME => 'info1', VERSIONS => 4
  48. 2.删除列族
  49. alter 'ns1:t1', 'delete' => 'f1'
  50. alter 'db1:mytb2','delete' => 'info3'
  51. alter 'ns1:t1', NAME => 'f1', METHOD => 'delete'
  52. alter 'db1:mytb2', NAME => 'info2', METHOD => 'delete'
  53. 4.删除表
  54. help 'drop'
  55. 注意: 使用drop操作时先需要执行disable
  56. 样例:
  57. 1.disable 'db1:mytb2'
  58. 2.drop 'db1:mytb2'
  59. 5.关闭及启用表
  60. 1.关闭表操作:
  61. disable 'db1:mytb1'
  62. desc 'db1:mytb1'
  63. 2.启用表操作:
  64. enable 'db1:mytb1'
  65. desc 'db1:mytb1'

7、DML

  1. r1 表示 rowKey
  2. c1 表示 列名称
  3. 1.put 上传及修改数据操作
  4. help 'put'
  5. hbase> put 'ns1:t1', 'r1', 'c1', 'value'
  6. hbase> put 't1', 'r1', 'c1', 'value'
  7. hbase> put 't1', 'r1', 'c1', 'value', ts1
  8. hbase> put 't1', 'r1', 'c1', 'value', {ATTRIBUTES=>{'mykey'=>'myvalue'}}
  9. hbase> put 't1', 'r1', 'c1', 'value', ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
  10. hbase> put 't1', 'r1', 'c1', 'value', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
  11. 样例:
  12. create 'db1:stu', 'info'
  13. put 'db1:stu', '1001', 'info:name', 'zhangsan'
  14. 注:修改数据可以直接用put上传最新数据进行替换
  15. 2.get 获取一行数据操作
  16. hbase> t.get 'r1'
  17. hbase> t.get 'r1', {TIMERANGE => [ts1, ts2]}
  18. hbase> t.get 'r1', {COLUMN => 'c1'}
  19. hbase> t.get 'r1', {COLUMN => ['c1', 'c2', 'c3']}
  20. hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1}
  21. hbase> t.get 'r1', {COLUMN => 'c1', TIMERANGE => [ts1, ts2], VERSIONS => 4}
  22. hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, VERSIONS => 4}
  23. hbase> t.get 'r1', {FILTER => "ValueFilter(=, 'binary:abc')"}
  24. hbase> t.get 'r1', 'c1'
  25. hbase> t.get 'r1', 'c1', 'c2'
  26. hbase> t.get 'r1', ['c1', 'c2']
  27. hbase> t.get 'r1', {CONSISTENCY => 'TIMELINE'}
  28. hbase> t.get 'r1', {CONSISTENCY => 'TIMELINE', REGION_REPLICA_ID => 1}
  29. get 'db1:stu', '1001'
  30. put 'db1:stu', '1001', 'info:age', '12'
  31. get 'db1:stu', '1001'
  32. put 'db1:stu', '1001', 'info:age', '13'
  33. 获取指定ROWKEY中某一列数据
  34. get 'db1:stu', '1001', 'info:age'
  35. 获取指定RowKey下的多列数据
  36. get 'db1:stu', '1001', 'info:age','info:name'
  37. 3.scan 获取表中所有数据

put 'db1:stu', '1001', 'info:name', 'zhangsan'
put 'db1:stu', '1001', 'info:age', '13'
put 'db1:stu', '1001', 'info:clazz', 'clazz1'

put 'db1:stu', '1002', 'info:name', 'lisi'
put 'db1:stu', '1002', 'info:age', '13'
put 'db1:stu', '1002', 'info:clazz', 'clazz2'

put 'db1:stu', '1003', 'info:name', 'wangwu'
put 'db1:stu', '1003', 'info:age', '13'
put 'db1:stu', '1003', 'info:clazz', 'clazz3'

  1. -- scan 'db1:stu'

put 'db1:stu', '1011', 'info:name', 'lisi'
put 'db1:stu', '1011', 'info:age', '13'
put 'db1:stu', '1011', 'info:clazz', 'clazz2'

put 'db1:stu', '1004', 'info:name', 'zhaoliu'
put 'db1:stu', '1004', 'info:age', '13'
put 'db1:stu', '1004', 'info:clazz', 'clazz2'

put 'db1:stu', '1020', 'info:name', 'zhaoliu'
put 'db1:stu', '1020', 'info:age', '13'
put 'db1:stu', '1020', 'info:clazz', 'clazz2'

put 'db1:stu', '10010', 'info:name', 'zhaoliu'
put 'db1:stu', '10010', 'info:age', '13'
put 'db1:stu', '10010', 'info:clazz', 'clazz2'

put 'db1:stu', '1001$', 'info:name', 'zhaoliu'
put 'db1:stu', '1001$', 'info:age', '13'
put 'db1:stu', '1001$', 'info:clazz', 'clazz2'

  1. ROWKEY是根据字典排序,并且排序的依据是按位比较ASCII码表
  2. scan 'ns1:t1', {COLUMNS => ['c1', 'c2'], LIMIT => 10, STARTROW => 'xyz'}
  3. scan 'db1:stu', {limit => 3}
  4. ROWKEY范围进行取值 左闭右开 取值包含STARTROW 不包含 STOPROW
  5. scan 'db1:stu', {STARTROW => '1001',STOPROW => '1004'}
  6. 根据ASCII码表取
  7. scan 'db1:stu', {STARTROW => '1001!',STOPROW => '1001~'}
  8. 查看表中所有数据并展示所有版本信息
  9. scan 'db1:stu' ,{RAW=>true,VERSIONS=>10}
  10. 4.list 查看所有表
  11. 5.count 统计表中数据量
  12. count 'db1:stu'
  13. 6.删除列
  14. delete 'db1:stu','1001','info:age','1650941469177'
  15. 7.删除一个rowkey
  16. deleteall 'db1:stu','1001'
  17. 8.清空表
  18. truncate 'db1:stu'

本文转载自: https://blog.csdn.net/a_black03/article/details/140924595
版权归原作者 小黑03 所有, 如有侵权,请联系我们删除。

“HBase”的评论:

还没有评论