hbase-2.1.0搭建过程
下载
wget http://mirrors.tuna.tsinghua.edu.cn/apache/hbase/2.1.0/hbase-2.1.0-bin.tar.gz
解压
tar -zxf hbase-2.1.0-bin.tar.gz -C /opt
修改文件/opt/hbase-2.1.0/conf/hbase-env.sh
# 此文件配置jdk路径即可
# The java implementation to use. Java 1.8+ required.
export JAVA_HOME=/opt/jdk1.8.0_172
修改文件/opt/hbase-2.1.0/conf/hbase-site.xml
<configuration>
<!--配置hdfs地址,它会通过Hadoop的core-site.xml找到对应的namenode,所以需要Hadoop的环境遍历得配好 -->
<property>
<name>hbase.rootdir</name>
<value>hdfs://ns/hbase</value>
</property>
<!--开启分布式,默认是本地模式 -->
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<!--配置zookeeper的地址 -->
<property>
<name>hbase.zookeeper.quorum</name>
<value>s1.jevoncode.com:2181,s2.jevoncode.com:2181,s3.jevoncode.com:2181</value>
</property>
<!--hbase有内置zookeeper,如果使用外置的zookeeper,则这个dataDir则无需配置-->
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/usr/local/zookeeper</value>
</property>
</configuration>
修改文件/opt/hbase-2.1.0/conf/regionservers
s2.jevoncode.com
s3.jevoncode.com
s4.jevoncode.com
新增文件/opt/hbase-2.1.0/conf/backup-masters
s2.jevoncode.com
配置环境变量~/.bashrc
export HBASE_HOME=/opt/hbase-2.1.0
export HBASE_CONF_DIR=/opt/hbase-2.1.0/conf
export PATH=$PATH:$HBASE_HOME/bin
生效配置文件
source ~/.bashrc
在s2.jevoncode.com,s3.jevoncode.com,s4.jevoncode.com节点启动slave
hbase-daemon.sh start regionserver
在s1.jevoncode.com启动master
hbase-daemon.sh start master
进入hbase shell命令行验证并操作表数据
进入shell
[jevoncode@s1 hbase-2.1.0]$ hbase shell
HBase Shell
Use "help" to get list of supported commands.
Use "exit" to quit this interactive shell.
Version 2.1.0, re1673bb0bbfea21d6e5dba73e013b09b8b49b89b, Tue Jul 10 17:26:48 CST 2018
Took 0.0067 seconds
hbase(main):001:0>
建立表t_user
# 语法:create <table>, {NAME => <family>, VERSIONS => <VERSIONS>}
# 例如:创建表t_user,有两个列族(column family),分别是 username,role,且保存历史版本数为3
hbase(main):001:0> create 't_user',{NAME => 'user', VERSIONS => 3},{NAME => 'role', VERSIONS => 3}
Created table t_user
Took 2.4220 seconds
=> Hbase::Table - t_user
查看有哪些表
hbase(main):001:0> list
TABLE
t_user
1 row(s)
Took 0.6946 seconds
=> ["t_user"]
新增(更新)记录
# 语法:put <table>,<rowkey>,<family:column>,<value>,<timestamp>
# 例如:给表t_user的添加一行记录(两个cell):rowkey是u001,family name:user,column name:username,value:jevoncode,timestamp:系统默认
# rowkey是u001,family name:role,column name:rolename,value:admin,timestamp:系统默认
hbase(main):007:0> put 't_user','u001','user:username','jevoncode'
Took 0.1921 seconds
hbase(main):008:0> put 't_user','u001','role:rolename','admin'
Took 0.0084 seconds
查看记录
# 语法:get <table>,<rowkey>,[<family:column>,....]
# 例如:查询表t_user, u001中的下的所有列值
hbase(main):012:0> get 't_user','u001'
COLUMN CELL
role:rolename timestamp=1535886076749, value=admin
user:username timestamp=1535886021314, value=jevoncode
1 row(s)
Took 0.0525 seconds
查看表的前几行数据
# 语法:scan <table>, {COLUMNS => [ <family:column>,.... ], LIMIT => num}
# 另外,还可以添加STARTROW、TIMERANGE和FITLER等高级功能
# 例如:扫描表t_user的前5条数据
hbase(main):017:0* scan 't_user',{LIMIT=>5}
ROW COLUMN+CELL
u001 column=role:rolename, timestamp=1535886076749, value=admin
u001 column=user:username, timestamp=1535886021314, value=jevoncode
u002 column=role:rolename, timestamp=1535886335540, value=manager
u002 column=user:username, timestamp=1535886324817, value=steve
2 row(s)
Took 0.0244 seconds
删除记录
# 语法:delete <table>, <rowkey>, <family:column> , <timestamp>,必须指定列名
# 例如:删除表t_user,u001中的user:username的数据
hbase(main):018:0> delete 't_user','u001','user:username'
Took 0.0461 seconds
hbase(main):019:0> scan 't_user',{LIMIT=>5}
ROW COLUMN+CELL
u001 column=role:rolename, timestamp=1535886076749, value=admin
u002 column=role:rolename, timestamp=1535886335540, value=manager
u002 column=user:username, timestamp=1535886324817, value=steve
2 row(s)
Took 0.0172 seconds
删除表
#分两步:首先disable,然后drop
#例如:删除表t_user
hbase(main):021:0> disable 't_user'
Took 0.7969 seconds
hbase(main):022:0> drop 't_user'
Took 0.2293 seconds
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。