原文:http://www.jianshu.com/p/510e1d599123html
本博客采用创做共用版权协议, 要求署名、非商业用途和保持一致. 转载本博客文章必须也遵循署名-非商业用途-保持一致的创做共用协议.java
我的博客地址: http://andrewliu.tk, 欢迎持续关注和友联.node
HBase是Hadoop的数据库, 而Hive数据库的管理工具, HBase具备分布式, 可扩展及面向列存储
的特色(基于谷歌BigTable). HBase可使用本地文件系统和HDFS文件存储系统, 存储的是松散的数据(key-value的映射关系).sql
HBase位于HDFS的上层, 向下提供存储, 向上提供运算shell
HBase有单机, 伪分布式, 全分布式运行模式数据库
依赖:apache
安装vim
$ brew install hbase # 安装在/usr/local/Cellar/hbase/1.0.0
配置HBase服务器
在conf/hbase-env.sh
设置JAVA_HOME架构
$ cd /usr/local/Cellar/hbase/1.0.0/libexec/conf $ vim hbase-env.sh export JAVA_HOME="/usr/bin/java"
在conf/hbase-site.xml
设置HBase的核心配置
$ vim hbase-site.xml
<configuration> <property> <name>hbase.rootdir</name> //这里设置让HBase存储文件的地方 <value>file:///Users/andrew_liu/Downloads/hbase</value> </property> <property> <name>hbase.zookeeper.property.dataDir</name> //这里设置让HBase存储内建zookeeper文件的地方 <value>/Users/andrew_liu/Downloads/zookeeper</value> </property> </configuration>
/usr/local/Cellar/hbase/1.0.0/bin/start-hbase.sh
提供HBase的启动
$ ./start-hbase.sh starting master, logging to /usr/local/Cellar/hbase/1.0.0/libexec/bin/../logs/hbase-andrew_liu-master-Andrew-liudeMacBook-Pro.local.out
验证是否安装成功
$ jps
3440 Jps 3362 HMaster # 有HMaster则说明安装成功 1885
启动HBase Shell
$ ./bin/hbase shell HBase Shell; enter 'help<RETURN>' for list of supported commands. Type "exit<RETURN>" to leave the HBase Shell Version 1.0.0, r6c98bff7b719efdb16f71606f3b7d8229445eb81, Sat Feb 14 19:49:22 PST 2015 1.8.7-p357 :001 > 1.8.7-p357 :001 > exit #退出shell
中止HBase运行
$ ./bin/stop-hbase.sh stopping hbase....................
必须关闭HBase
修改hbase-env.sh
HBASE_MANAGE_XK = true
修改hbase-site.xml, 设置HBase使用分布式模式运行
<configuration> <property> <name>hbase.rootdir</name> //Here you have to set the path where you want HBase to store its files. <value>hdfs://localhost:8020/hbase</value> </property> <property> <name>hbase.cluster.distributed</name> <value>true</value> </property> </configuration>
hbase.rootdir
路径必定要跟hadoop中core-site.xml
中fs.default.name相同change the hbase.rootdir from the local filesystem to the address of your HDFS instance ---offical quick start
如何两处设置不一样会引发ERROR: Can't get master address from ZooKeeper; znode data == null错误错误
在启动HBase以前, 请先启动Hadoop, 使之运行
启动HBase
$ ./start-hbase.sh
$ jps #验证是否启动成功, 包含HMaster和HRegionServer说明启动成功
6400 DataNode 7872 Jps 7702 HMaster 7624 HQuorumPeer 6315 NameNode 6508 SecondaryNameNode 6716 NodeManager 7804 HRegionServerHBase 6623 ResourceManager
若是在启动HBase后, 提示以下
regionserver running as process 4667. Stop it first. #请执行如下操做 $ kill -9 4667 #这里4667是要杀掉的进程号
启动成功HBase会在HDFS下建立/hbase目录
$ hdfs dfs -ls /hbase
$ hbase shell #启动HBase Shell #建立表 > create 'student', 'description', 'course' #建立表名为student的表, 指明两个列名, 分别为description和course #信息明细 > list 'student' #列出list表信息 #插入数据 > put 'student', 'row1', 'description:age', '18' #意思为在student表row1处插入description:age的数据为18 > put 'student', 'row1', 'description:name', 'liu' put 'student', 'row1', 'course:chinese', '100' #一次扫描全部数据 > scan 'student #使表失效 / 有效 > disable 'student' > enable 'student' #删除表(要先disable) > drop 'student' #退出shell > quit
HBase是一个稀疏的长期存储的, 多维度的, 排序的映射表, 经过行键, 行键 + 时间戳 或 行键 + 列(列族: 列修饰符)就能够定位特殊的数据
HBase的服务器体系听从简单的主从服务器架构, 由HRegion服务器群
和HBase服务器构成
, Master服务器负责管理全部的HRegion服务器, 而HBase中全部的服务器经过ZooKeeper来进行协调并处理HBase服务器运行期间可能遇到的错误.
HBase逻辑上的表可能会被划分为多个HRegion, 而后存储在HRegion服务器上.
元数据子表采用三级索引结构: 根子表->用户表的元数据表->用户表
使表有效或无效
, 以及添加或删除列族成员