集群启动及HBase相关命令

启动集群

  1. /opt/hadoop-2.6.0/sbin/start-all.sh

分别启动三台节点上的zookeeper

  1. ./zkServer.sh start

启动hbase

  1. ./start-hbase.sh

image.png image.png image.png

进入hbase shell工具

  1. hbase shell

image.png

status查看状态
image.png

help查看帮助
image.png
image.png

  1. Group name: ddl(对表进行操作的指令)
  2. 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(查看用户空间里当前所有的表), show_filters
  3. Group name: dml(对单元格的操作指令)
  4. Commands: append, count, delete(删除一个单元格), deleteall, get(查询), get_counter, incr, put(新增或修改), scan(查询), truncate, truncate_preserve

使用list查看(用户空间)当前拥有的表
image.png

表的创建和删

创建表

格式1:create ‘ NameSpace : TableName ‘ { NAME=>’liezuName’,VERSONS=>5 }

  • NameSpace :命名空间(相当于数据库)
  • TableName :表名
  • NAME=>’liezuName’:列族的名称
  • VERSONS=>5:列族中每个单元格的(保留)版本,出现新版本的数据时,自动删除最旧版本

    格式2:create ‘ TableName ‘ { NAME=>’f1’ } , { NAME=>’f2’ } , { NAME=>’f2’ }

  • 使用默认的命名空间创建表

  • 拥有三个列族:f1,f2,f3
  • 简写:create 'TableName','f1','f2','f3'

添加自定义的命名空间hadoop(在自定义的名字空间创建新的表,得先添加自定义的命名空间)

  1. create_namespace 'hadoop'

查看当前命名空间

  1. list_namespace

image.png

hadoop名字空间下创建一个名为student的表 (有stu_info、sel_course两个列族)

  1. create 'hadoop:student','stu_info','sel_course'

image.png

在默认的名字空间下创建一个名为student的表

  1. create 'student','stu_info','sel_course'

image.png
list查看
image.png
(在相同的名字空间不能有同名的表,在不同的名字空间,表可以同名)

disable将表禁用

  1. disable 'student'

image.png
drop删除表

  1. drop 'student'

image.png
(在删除表之前要先将表禁用)

数据的增加、删除以及查询

put(增加一个单元格数据)

  1. put 'hadoop:student'(表名) , '1001'(学号) , 'stu_info:name'(列族:列名) , 'Tom'

image.png

get(获取一行数据或一行中某个单元格的内容)

  1. get 'hadoop:student' ,'1001'

image.png

插入stature列(身高)180

  1. put 'hadoop:student' , '1001' , 'stu_info:stature', '180'

image.png
image.png

scan(获取整张表的数据)

  1. scan 'hadoop:student'

image.png

继续添加新数据Lily

  1. put 'hadoop:student' , '1002' , 'stu_info:name', 'Lily'

put几行新数据,Tom的英语分数,Lily的数学分数

  1. put 'hadoop:student' , '1001' , 'sel_course:en', '85'
  1. put 'hadoop:student' , '1002' , 'sel_course:ma', '90'

使用scan,取出列族sel_course下所有单元格的值

  1. scan 'hadoop:student' , {COLUMNS=>['sel_course']}

image.png

使用scan,取出列族sel_course下所有学生的英语成绩

  1. scan 'hadoop:student' , {COLUMNS=>['sel_course:en']}

image.png

添加Lily的身高

  1. put 'hadoop:student' , '1002' , 'stu_info:stature', '165'

使用scan,列出列族sel_course下所有学生的身高

  1. scan 'hadoop:student' , {COLUMNS=>['stu_info:stature']}

image.png

随便添加一个数据

  1. put 'hadoop:student' , '1003' , 'stu_info:name', 'abc'

scan全表数据
image.png

delete删除数据(删除1003下name单元格的数据)

  1. delete 'hadoop:student' , '1003' , 'stu_info:name'

image.png

插入图表中的数据

HBase - 图25

姓名

  1. put 'hadoop:student' , '1001' , 'stu_info:name' , 'Tom'
  2. put 'hadoop:student' , '1002' , 'stu_info:name' , 'Lily'
  3. put 'hadoop:student' , '1003' , 'stu_info:name' , 'Mary'
  4. put 'hadoop:student' , '1004' , 'stu_info:name' , 'Jack'
  5. put 'hadoop:student' , '1005' , 'stu_info:name' , 'Rob'
  6. put 'hadoop:student' , '1006' , 'stu_info:name' , 'John'
  7. put 'hadoop:student' , '1007' , 'stu_info:name' , 'Alice'
  8. put 'hadoop:student' , '1008' , 'stu_info:name' , 'Kate'
  1. scan 'hadoop:student',{COLUMNS=>['stu_info:name']}

image.png

身高

  1. put 'hadoop:student' , '1001' , 'stu_info:stature' , '180'
  2. put 'hadoop:student' , '1002' , 'stu_info:stature' , '165'
  3. put 'hadoop:student' , '1003' , 'stu_info:stature' , '172'
  4. put 'hadoop:student' , '1004' , 'stu_info:stature' , '175'
  5. put 'hadoop:student' , '1005' , 'stu_info:stature' , '177'
  6. put 'hadoop:student' , '1006' , 'stu_info:stature' , '192'
  7. put 'hadoop:student' , '1007' , 'stu_info:stature' , '163'
  8. put 'hadoop:student' , '1008' , 'stu_info:stature' , '168'
  1. scan 'hadoop:student',{COLUMNS=>['stu_info:stature']}

image.png

英语成绩

  1. put 'hadoop:student' , '1001' , 'sel_course:en', '85'
  2. put 'hadoop:student' , '1002' , 'sel_course:en', '72'
  3. put 'hadoop:student' , '1003' , 'sel_course:en', '60'
  4. put 'hadoop:student' , '1004' , 'sel_course:en', '95'
  5. put 'hadoop:student' , '1005' , 'sel_course:en', '88'
  6. put 'hadoop:student' , '1006' , 'sel_course:en', '78'
  7. put 'hadoop:student' , '1007' , 'sel_course:en', '81'
  8. put 'hadoop:student' , '1008' , 'sel_course:en', '68'
  1. scan 'hadoop:student',{COLUMNS=>['sel_course:en']}

image.png

数学成绩

  1. put 'hadoop:student' , '1001' , 'sel_course:ma', '100'
  2. put 'hadoop:student' , '1002' , 'sel_course:ma', '90'
  3. put 'hadoop:student' , '1003' , 'sel_course:ma', '85'
  4. put 'hadoop:student' , '1004' , 'sel_course:ma', '80'
  5. put 'hadoop:student' , '1005' , 'sel_course:ma', '70'
  6. put 'hadoop:student' , '1006' , 'sel_course:ma', '86'
  7. put 'hadoop:student' , '1007' , 'sel_course:ma', '60'
  8. put 'hadoop:student' , '1008' , 'sel_course:ma', '85'
  1. scan 'hadoop:student',{COLUMNS=>['sel_course:ma']}

image.png