环境说明
10.176.2.101(10.176.2.121) master
10.176.2.103 zjx03
10.176.2.105 zjx05
cent-os6.5
zookeeper cdh 3.4.5
hadoop apache 2.7.7
jdk 1.8.191
hbase 1.2.7
解决ip冲突
修改冲突机器中的ip
vim /etc/sysconfig/network-scripts/ifcfg-eth0
修改ip与主机名映射(集群中均修改)
vim /etc/hosts
修改后重启网络
service network restart
hbase官网
hbase下载安装
此处考虑与zookeeper及hadoop兼容性和版本稳定性,选择1.2.10或1.2.7版本,如果是cdh版本(推荐cdh版本),应保证各组件cdh版本一致。
下载地址:
http://archive.apache.org/dist/hbase/1.2.7/
http://mirror.bit.edu.cn/apache/hbase/hbase-1.2.10/
直接下述下载安装部署:
本机安装与hadoop主节点同一节点上10.176.2.101master机器
wget http://mirror.bit.edu.cn/apache/hbase/hbase-1.2.10/hbase-1.2.10-bin.tar.gz -c /opt/softwares
cd /opt/softwares
tar -zxvf hbase-1.2.10-bin.tar.gz
rm -rf hbase-1.2.10-bin.tar.gz
cd hbase-1.2.10/
rm -rf docs/
cd conf/
echo $JAVA_HOME
vim hbase-env.sh
export JAVA_HOME=/usr/lib/java/jdk1.8.0_191
#去掉export HBASE_MANAGES_ZK注释并将其置为false
export HBASE_MANAGES_ZK=false
#配置环境变量
vim /etc/profile
export HBASE_HOME=/opt/softwares/hbase-1.2.10
export PATH=$HBASE_HOME/bin:$PATH
source /etc/profile
vim hbase-site.xml
<property>
<name>hbase.rootdir</name> <!-- hbase存放数据目录 -->
<value>hdfs://master:9000/opt/data/hbase_db</value>
<!-- 端口要和Hadoop的fs.defaultFS端口一致-->
</property>
<property>
<name>hbase.cluster.distributed</name> <!-- 是否分布式部署 -->
<value>true</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name> <!-- list of zookooper -->
<value>master,zjx03,zjx05</value>
</property>
<!--指定hbase集群主控节点 -->
<!--
<property>
<name>hbase.master</name>
<value>master:60000</value>
</property>
-->
<property><!--zookooper配置、日志等的存储位置 -->
<name>hbase.zookeeper.property.dataDir</name>
<value>/opt/softwares/hbase-1.2.10/data/zookeeper</value>
</property>
<property>
<name>hbase.tmp.dir</name>
<value>/opt/softwares/hbase-1.2.10/data/tmp</value>
</property>
vim regionservers
master
zjx03
zjx05
[root@master softwares]# scp -r ./hbase-1.2.10 zjx03:/opt/softwares/
[root@master softwares]# scp -r ./hbase-1.2.10 zjx05:/opt/softwares/
启动测试
[root@master conf]# start-hbase.sh
starting master, logging to /opt/softwares/hbase-1.2.10/logs/hbase-root-master-master.out
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
zjx05: starting regionserver, logging to /opt/softwares/hbase-1.2.10/bin/../logs/hbase-root-regionserver-zjx05.out
master: starting regionserver, logging to /opt/softwares/hbase-1.2.10/bin/../logs/hbase-root-regionserver-master.out
zjx05: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
zjx05: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
master: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
master: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
zjx03: starting regionserver, logging to /opt/softwares/hbase-1.2.10/bin/../logs/hbase-root-regionserver-zjx03.out
# jps查看进程
# master:HMaster HRegionServer
# slaves: HRegionServer HQuorumPeer
[root@master conf]# jps
8240 NodeManager
7587 DataNode
12934 HRegionServer
13416 Jps
7480 NameNode
7322 DFSZKFailoverController
7242 JournalNode
12796 HMaster
7164 QuorumPeerMain
[root@zjx03 conf]# jps
4049 NameNode
4500 NodeManager
6406 Jps
4392 ResourceManager
4121 DataNode
4298 DFSZKFailoverController
3915 QuorumPeerMain
3965 JournalNode
[root@zjx05 conf]# jps
3170 DataNode
3026 QuorumPeerMain
3314 NodeManager
4053 Jps
3086 JournalNode
hbase操作练习
[root@master conf]# hbase shell
hbase(main):003:0> status
1 active master, 0 backup masters, 1 servers, 0 dead, 2.0000 average load
hbase(main):004:0> version
1.2.10, r18f428abb64b405de24d164425e470512e82f287, Mon Jan 7 16:53:30 CST 2019
hbase(main):003:0> help
#创建表
hbase(main):005:0> create 'resume','binfo','edu','work'
0 row(s) in 11.4040 seconds
=> Hbase::Table - resume
# 列出表
hbase(main):006:0> list
TABLE
resume
1 row(s) in 0.0450 seconds
# 查看表结构
hbase(main):007:0> describe 'resume'
Table resume is ENABLED
resume
COLUMN FAMILIES DESCRIPTION
# 添加列族
hbase(main):008:0> disable 'resume'
hbase(main):009:0> alter 'resume',name='f1'
# 删除列族
hbase(main):010:0> alter 'resume',{NAME=>'f1',METHOD=>'delete'}
# 或是
hbase(main):010:0> alter 'resume','delete' => 'f1'
hbase(main):011:0> enable 'resume'
# 注意:
ddl命令是区分大小写的,像ddl中的alter,create, drop, enable等都必需用小写。而{}中的属性名都必需用大写。
alter、drop表之前必需在先禁用(disabel)表,修改完后再启用表(enable)表,否则会报错。
# 查询禁用状态
hbase(main):012:0> is_disabled 'resume'
false
hbase(main):013:0> is_enabled 'resume'
true
# 删除表
hbase(main):014:0> create 't1','f1'
hbase(main):015:0> disable 't1'
hbase(main):016:0> drop 't1'
# 查询表是否存在
hbase(main):017:0> exists 'resume'
Table resume does exist
hbase(main):018:0> exists 't1'
Table t1 does not exist
# 插入数据
put 'resume','lichangzai','binfo:age','1980-1-1';
put 'resume','lichangzai','binfo:sex','man';
put 'resume','lichangzai','edu:mschool','rq no.1';
put 'resume','lichangzai','edu:university','qhddx';
put 'resume','lichangzai','work:company1','12580';
put 'resume','changfei','binfo:age','1986-2-1';
put 'resume','changfei','edu:university','bjdx';
put 'resume','changfei','work:company1','LG';
put 'resume','changfei','binfo:mobile','13598765401';
put 'resume','changfei','binfo:site','hi.baidu/lichangzai';
# 获取一行键的所有数据
# 必须通过行键Row Key来查询数据
hbase(main):002:0> get 'resume','lichangzai'
COLUMN CELL
binfo:age timestamp=1548337016141, value=1980-1-1
binfo:sex timestamp=1548337022702, value=man
edu:mschool timestamp=1548337168818, value=rq no.1
edu:university timestamp=1548337168859, value=qhddx
# 获取一个行键,一个列族的所有数据
hbase(main):003:0> get 'resume','lichangzai','binfo'
COLUMN CELL
binfo:age timestamp=1548337016141, value=1980-1-1
binfo:sex timestamp=1548337022702, value=man
# 获取一个行键,一个列族中一个列的所有数据
hbase(main):004:0> get 'resume','lichangzai','binfo:sex'
COLUMN CELL
binfo:sex timestamp=1548337022702, value=man
# 更新一条记录
# 更新实质就是插入一条带有时间戳的记录,get查询时只显示最新时间的记录
hbase(main):005:0> put 'resume','lichangzai','binfo:mobile','13899999999'
hbase(main):006:0> get 'resume','lichangzai','binfo:mobile'
COLUMN CELL
binfo:mobile timestamp=1548337503341, value=13899999999
# 通过timestamp来获取数据
hbase(main):007:0> get 'resume','lichangzai',{COLUMN=>'binfo:mobile',TIMESTAMP=>1548337503341}
COLUMN CELL
binfo:mobile timestamp=1548337503341, value=13899999999
# 查之前(即删除)时间戳的数据
# 全表扫描
hbase(main):010:0> scan 'resume'
ROW COLUMN+CELL
lichangzai column=binfo:age, timestamp=1548337016141, value=1980-1-1
lichangzai column=binfo:mobile, timestamp=1548337503341, value=13899999999
lichangzai column=binfo:sex, timestamp=1548337022702, value=man
lichangzai column=edu:mschool, timestamp=1548337168818, value=rq no.1
lichangzai column=edu:university, timestamp=1548337168859, value=qhddx
# 删除指定行键的列族字段
hbase(main):011:0> put 'resume','changfei','binfo:sex','man'
hbase(main):012:0> delete 'resume','changfei','binfo:sex'
0 row(s) in 0.0880 seconds
hbase(main):013:0> get 'resume','changfei','binfo:sex'
COLUMN CELL
# 删除整行
hbase(main):014:0> create 't1','f1','f2'
0 row(s) in 2.5950 seconds
hbase(main):015:0> put 't1','a','f1:col1','xxxxx'
0 row(s) in 0.0470 seconds
hbase(main):016:0> put 't1','a','f1:col2','xyxyx'
0 row(s) in 0.0270 seconds
hbase(main):017:0> put 't1','b','f2:cl1','ppppp'
0 row(s) in 0.0530 seconds
hbase(main):018:0> deleteall 't1','a'
0 row(s) in 0.0320 seconds
hbase(main):019:0> get 't1','a'
COLUMN CELL
0 row(s) in 0.0730 seconds
# 查询表中有多少行
hbase(main):020:0> count 'resume'
1 row(s) in 0.0760 seconds
hbase(main):021:0> count 't1'
1 row(s) in 0.0280 seconds
# 清空表
Truncate表的处理过程:
由于Hadoop的HDFS文件系统不允许直接修改,所以只能先删除表在重新创建已达到清空表的目的
hbase(main):022:0> truncate 't1'
Truncating 't1' table (it may take a while):
- Disabling table...
- Truncating table...
0 row(s) in 4.6170 seconds
# 退出hbase shell
exit
# 查看日志 也可以去其它节点查看日志
[root@master conf]# cd ../logs
[root@master logs]# tail -100f hbase-root-master-master.log
停止hbase
[root@master logs]# stop-hbase.sh
stopping hbase.....................
参考链接:
https://www.cnblogs.com/lzxlfly/p/7221890.html
https://blog.csdn.net/achuo/article/details/51170946
网友评论