HBase的安装有两种种模式:单机模式和分布式模式,其中分布式模式又分为伪分布模式和完全分布式模式。
单机模式适合初学者了解hbase的命令行使用,无需hadoop就可以运行:参考 http://blog.csdn.net/god_wot/article/details/6829427
分布式模式依赖hdfs,因此需提前安装好hadoop。
伪分布模式,和hadoop的伪分布式模式一样,指在一台主机上运行所有进程的模式,这种方式用来熟悉hbase或做开发、测试用。
完全分布式模式,在生产环境中使用这种模式。
下面为如何在单机上配置hbase伪分布式模式:
1.提前准备好hadoop,并运行起来,我机器上配置了hadoop的伪分布式环境
2.打开hbase.site.xml
hbase.rootdir
hdfs://localhost:9000/hbase
dfs.replication
1
3.在hbase-env.sh配置JAVA_HOME
也可以根据自己的需要配置下面的的选项
# HBASE_LOG_DIR Where log files are stored. PWD by default.
# HBASE_PID_DIR The pid files are stored. /tmp by default.
# HBASE_CLASSPATH
4.把HBASE_HOME以及bin目录配置到系统环境变量中(可选)
5.然后就可以启动了hbase了
hadoop@ubuntu:~/hbase-1.2.2/conf$ ../bin/start-hbase.sh
starting master, logging to /home/hadoop/hbase-1.2.2/bin/../logs/hbase-hadoop-master-ubuntu.out
hadoop@ubuntu:~/hbase-1.2.2/conf$ ../bin/hbase shell
2017-01-16 22:39:42,301 WARN [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hadoop/hbase-1.2.2/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
HBase Shell; enter 'help' for list of supported commands.
Type "exit" to leave the HBase Shell
Version 1.2.2, r3f671c1ead70d249ea4598f1bbcc5151322b3a13, Fri Jul 1 08:28:55 CDT 2016
hbase(main):001:0> list
TABLE
0 row(s) in 0.4610 seconds
=> []
hbase(main):003:0>
在hdfs中也有了hbase文件夹:
hadoop@ubuntu:~/hbase-1.2.2/bin$ hdfs dfs -ls /
17/01/16 23:08:35 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Found 5 items
drwxr-xr-x - hadoop supergroup 0 2016-08-01 19:17 /data
drwxr-xr-x - hadoop supergroup 0 2017-01-16 22:39 /hbase
drwxr-xr-x - hadoop supergroup 0 2017-01-16 19:48 /tmp
drwxr-xr-x - hadoop supergroup 0 2016-07-06 00:12 /user
hadoop@ubuntu:~/hbase-1.2.2/bin$
或通过浏览器查看:http://192.168.134.136:50070/explorer.html#/hbase/
6.备注:
若出现:ERROR [main] zookeeper.RecoverableZooKeeper: ZooKeeper exists failed after 4 attempts
或ERROR: Can't get master address from ZooKeeper; znode data == null
检查下 是不是不小心配置成了完全分布式
hbase-env.sh 里把# export HBASE_MANAGES_ZK=true 注释掉
hbase-site.xml 里把hbase.cluster.distributed、base.master、hbase.zookeeper.property.dataDir、hbase.zookeeper.quorum等去掉即可
或者其他配置错误,比如:把dfs.replication别写成了hbase.replication等