1、常用链接
1 2 3 4 5 |
下载地址: 稳定版本:http://archive.apache.org/dist/hbase/stable/ 其他版本:http://archive.apache.org/dist/hbase/ 官方说明文档:http://hbase.apache.org/book.html#quickstart |
2、解压下载的包
1 2 |
[root@imzcy ~]# tar zxvf hbase-1.1.4-bin.tar.gz -C /opt/ [root@imzcy ~]# cd /opt/hbase-1.1.4/ |
3、修改conf/hbase-env.sh两处配置(此版本位于第27行和第129行)
1 2 3 |
[root@imzcy hbase-1.1.4]# vi conf/hbase-env.sh 27 export JAVA_HOME=/opt/jdk1.8.0_121 129 export HBASE_MANAGES_ZK=true |
27行:指明JAVA_HOME位置,hbase需要1.7及以上版本的jdk支持(如果系统已经配置过jdk,此行可以不做配置)
129行配置:为true表示指明hbase使用自带的zookeeper
4、配置hbase的root目录,并配置zookeeper地址、端口号及data目录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
[root@imzcy hbase-1.1.4]# vi conf/hbase-site.xml <configuration> <property> <name>hbase.rootdir</name> <value>../data/rootdir</value> </property> <property> <name>hbase.zookeeper.quorum</name> <value>127.0.0.1</value> </property> <property> <name>hbase.zookeeper.property.clientPort</name> <value>2181</value> </property> <property> <name>hbase.zookeeper.property.dataDir</name> <value>../data/zk</value> </property> </configuration> |
5、启动及停止hbase
5.1、启动hbase
1 2 3 4 5 |
[root@imzcy hbase-1.1.4]# ./bin/start-hbase.sh starting master, logging to /opt/hbase-1.1.4/bin/../logs/hbase-root-master-imzcy.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 [root@imzcy hbase-1.1.4]# |
5.2、查看是否正常启动
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@imzcy hbase-1.1.4]# ps -ef |grep hbase |grep -v grep root 2841 1 0 20:25 pts/0 00:00:00 bash /opt/hbase-1.1.4/bin/hbase-daemon.sh --config /opt/hbase-1.1.4/bin/../conf foreground_start master root 2855 2841 6 20:25 pts/0 00:00:12 /opt/jdk1.8.0_121/bin/java -Dproc_master -XX:OnOutOfMemoryError=kill -9 %p -XX:+UseConcMarkSweepGC -XX:PermSize=128m -XX:MaxPermSize=128m -Dhbase.log.dir=/opt/hbase-1.1.4/bin/../logs -Dhbase.log.file=hbase-root-master-imzcy.log -Dhbase.home.dir=/opt/hbase-1.1.4/bin/.. -Dhbase.id.str=root -Dhbase.root.logger=INFO,RFA -Dhbase.security.logger=INFO,RFAS org.apache.hadoop.hbase.master.HMaster start [root@imzcy hbase-1.1.4]# [root@imzcy ~]# jps -m 3467 HMaster start [root@imzcy ~]# [root@imzcy ~]# ss -tnl |grep 2181 LISTEN 0 50 :::2181 :::* [root@imzcy ~]# |
5.3、停止hbase
1 2 3 |
[root@imzcy hbase-1.1.4]# ./bin/stop-hbase.sh stopping hbase................. [root@imzcy hbase-1.1.4]# |
6、使用CLI对hbase进行一些简单操作
6.1、进入hbase CLI界面
1 2 3 4 5 6 7 |
[root@imzcy hbase-1.1.4]# ./bin/hbase shell 2018-09-19 21:02:33,274 WARN [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable HBase Shell; enter 'help<RETURN>' for list of supported commands. Type "exit<RETURN>" to leave the HBase Shell Version 1.1.4, r14c0e77956f9bb4c6edf0378474264843e4a82c3, Wed Mar 16 21:18:26 PDT 2016 hbase(main):001:0> |
6.2、使用help
命令列出hbase一些基本的使用信息
1 |
hbase(main):015:0> help |
6.3、使用create
命令创建一个表
1 2 3 4 5 |
hbase(main):001:0> create 'test', 'cf' 0 row(s) in 2.8620 seconds => Hbase::Table - test hbase(main):002:0> |
6.4、使用list
命令列出所有表,后面跟上表明列出指定表信息
1 2 3 4 5 6 7 |
hbase(main):003:0> list 'test' TABLE test 1 row(s) in 0.0400 seconds => ["test"] hbase(main):004:0> |
6.5、使用put
命令向表中插入两条数据
1 2 3 4 5 6 7 |
hbase(main):004:0> put 'test', 'row1', 'cf:a', 'value1' 0 row(s) in 0.3110 seconds hbase(main):005:0> put 'test', 'row2', 'cf:b', 'value12' 0 row(s) in 0.0290 seconds hbase(main):006:0> |
6.6、使用scan
命令查看表中所有数据
1 2 3 4 5 6 7 |
hbase(main):006:0> scan 'test' ROW COLUMN+CELL row1 column=cf:a, timestamp=1537363958346, value=value1 row2 column=cf:b, timestamp=1537364088634, value=value2 2 row(s) in 0.0480 seconds hbase(main):007:0> |
6.7、使用get
命令查看指定行数据
1 2 3 4 5 6 |
hbase(main):007:0> get 'test', 'row1' COLUMN CELL cf:a timestamp=1537363958346, value=value1 1 row(s) in 0.0590 seconds hbase(main):008:0> |
6.8、使用disable
命令禁用指定表(hbase删除表或修改表设置时需要先将表禁用)
1 2 3 4 |
hbase(main):008:0> disable 'test' 0 row(s) in 2.3450 seconds hbase(main):009:0> |
6.9、使用enable
命令启用被禁用的表
1 2 3 4 |
hbase(main):009:0> enable 'test' 0 row(s) in 2.5540 seconds hbase(main):010:0> |
6.10、删除指定的表(需要先禁用表,不然会有以下报错)
1 2 3 4 |
hbase(main):013:0> drop 'test' 0 row(s) in 1.3290 seconds hbase(main):014:0> |
6.11、使用exit
退出CLI界面
1 2 |
hbase(main):014:0> exit [root@imzcy hbase-1.1.4]# |
7、常见问题
7.1、如果没有配置好JAVA_HOME,那么启动和停止hbase的时候会报以下错误:
1 2 3 4 5 6 7 8 9 10 |
[root@imzcy hbase-1.1.4]# ./bin/start-hbase.sh +======================================================================+ | Error: JAVA_HOME is not set | +----------------------------------------------------------------------+ | Please download the latest Sun JDK from the Sun Java web site | | > http://www.oracle.com/technetwork/java/javase/downloads | | | | HBase requires Java 1.7 or later. | +======================================================================+ [root@imzcy hbase-1.1.4]# |
7.2 、hbase删除指定表时,如果没有事先禁用该表,则会报以下错误:
1 2 3 4 5 6 7 8 9 10 11 |
hbase(main):010:0> drop 'test' ERROR: Table test is enabled. Disable it first. Here is some help for this command: Drop the named table. Table must first be disabled: hbase> drop 't1' hbase> drop 'ns1:t1' hbase(main):011:0> |