赞
踩
一.安装
1.创建docker-compose.yml文件
version: '3.1' services: hbase: image: harisekhon/hbase:1.4.7 container_name: hbase restart: always ports: - 8880:8080 - 8885:8085 - 9990:9090 - 9995:9095 - 16000:16000 - 16010:16010 - 16020:16020 - 16030:16030 - 16201:16201 - 16301:16301 - 2381:2181 environment: # SERVICE_PRECONDITION: "namenode:50070 datanode:50075" - TZ="Asia/Shanghai" - LANG=en_US.UTF-8 volumes: - ./hbase_data:/hbase-data - ./hbase_zookeeper_data:/zookeeper-data networks: default: driver: bridge
使用docker-compose命令运行:
docker-compose up -d
2.修改配置文件
(1).修改hbase-site.xml配置文件
hbase.rootdir 修改成 hbase.root.dir
(2).在hbase-env.sh里面添加
export HBASE_DISABLE_HADOOP_CLASSPATH_LOOKUP=true
(3).重启hbase即可
二.使用
1.建表
- //创建命名空间
- create_namespace 'user'
- //创建表
- create 'user:sac','student','course1','course2','course3'
2.插入数据
- //第一条
- put 'user:sac','2015001','student:S_Name','zhangsan'
- put 'user:sac','2015001','student:S_Sex','male'
- put 'user:sac','2015001','student:S_Age','23'
- put 'user:sac','2015001','course1:C_No','123001'
- put 'user:sac','2015001','course1:C_Name','Math'
- put 'user:sac','2015001','course1:C_Credit','2.0'
- put 'user:sac','2015001','course1:Score','86'
- put 'user:sac' ,'2015001','course3:C_No','123003'
- put 'user:sac' ,'2015001','course3:C_Name','English'
- put 'user:sac' ,'2015001','course3:C_Credit','3.0'
- put 'user:sac' ,'2015001','course3:Score','69'
- //第二条
- put 'user:sac' ,'2015002','student:S_Name','lisi'
- put 'user:sac' ,'2015002','student:S_Sex','female'
- put 'user:sac' ,'2015002','student:S_Age','22'
- put 'user:sac' ,'2015002','course2:C_No','123002'
- put 'user:sac' ,'2015002','course2:C_Name','Conputer Science'
- put 'user:sac' ,'2015002','course2:Credit','5.0'
- put "user:sac" ,'2015002','course2:Score','77'
- put 'user:sac' ,'2015002','course3:C_No','123003'
- put 'user:sac' ,'2015002','course3:C_Name','English'
- put 'user:sac' ,'2015002','course3:Credit','3.0'
- put 'user:sac' ,'2015002','course3:Score','99'
- //第三条
- put 'user:sac' ,'2015003','student:S_Name','wanger'
- put 'user:sac' ,'2015003','student:S_Sex','male'
- put 'user:sac' ,'2015003','student:S_Age','24'
- put 'user:sac' ,'2015003','course1:C_No','123001'
- put 'user:sac' ,'2015003','course1:C_Name','Math'
- put 'user:sac' ,'2015003','course1:C_Credit','2.0'
- put 'user:sac' ,'2015003','course1:Score','98'
- put 'user:sac' ,'2015003','course2:C_No','123002'
- put 'user:sac' ,'2015003','course2:C_Name','Computer Science'
- put 'user:sac' ,'2015003','course2:C_Credit','5.0'
- put 'user:sac' ,'2015003','course2:Score','95'
3.查询
(1).查询命名空间列表
- //show databases;
- list_namespace
(2).查询命名空间(database)下的表
- //show tables;
- list_namespace_tables 'namespace'
(3).全表查询
- //select * from tableName
- scan 'namespace:table'
(4).全表扫面指定的族(根据表下的某个族查询)
在nosql中存储数据是将某个对象所有的属性全部存储
例如关系型数据库中的用户,权限,角色是分表存储,但是nosql中,将某个用户的权限角色都一起存在用户表中;
其中用户,角色,权限分别属于用户表中的三个族
scan 'namespace:table',COLUMn=>'用户族'
(5).查询某个族下的指定列的数据
- //查询唯一一条 get
- //根据条件查询某条数据
- get 'namespace:table','rowkey','族:列'
- //批量查询 scan
- //查询从rowkeyStart到rowkeyStop的数据
- scan 'namespace:table',
- {COLUMN=>'族',STARTROW=>'rowkeyStart',STOPROW=>'rowkeySTOP+1'}
- //查询10条数据
- scan 'namespace:table',{COLUMN=>'族',LIMIT=>10}
(6).根据条件过滤查询
- scan 'namespace:table',FILTER=>"ColumnPrefixFilter('字段条件') AND ValueFilter(=,'substring:内容条件')"
- 例:
-
- //在user库中查询,学生姓名列S_Name包含‘张’的数据
- scan 'user:sac',FILTER=>"ColumnPrefixFilter('S_Name') AND ValueFilter(=,'substring:zhang')"
4.删除数据
- (1).根据rowkey删除指定的行 //deleteall rowkey
- deleteall '2015003'
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。