测试环境
centos 6.5 三台
master
slave1
slave2
(用户统一名称为hadoop,已配置好/home/hadoop/hadoop-2.4.0, /home/hadoop/zookeeper-3.4.6 , SSH 并且使用正常)
下载hbase-1.0.0
进入官网下载地址:http://archive.apache.org/dist/hbase/hbase-1.0.0/,下载 hbase-1.0.0-bin.tar.gz.
后面需要安装集群,整合到hadoop,所以注意选择与hadoop对应的版本:
1、单机版安装:
1.1. 安装配置HBase
$ tar xfz hbase-1.0.0-bin.tar.gz
$ cd hbase-1.0.0
指定Hbase数据写到哪个目录,单机配置,只需要如下配置hbase-site.xml:
vim conf/hbase-site.xml
<configuration> <property>
<name>hbase.rootdir</name>
<value>file:///home/hadoop/hbase-1.0.0/hbase</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/home/hadoop/zookeeper-3.4.6</value>
</property>
</configuration>
目录/home/hadoop/hbase-1.0.0/hbase 会自动创建
1.2. 启动 HBase
现在启动Hbase:
$ ./bin/start-hbase.sh
starting Master, logging to logs/hbase-user-master-example.org.out
现在你运行的是单机模式的Hbaes。所以的服务都运行在一个JVM上,包括Hbase和Zookeeper。Hbase的日志放在logs目录,当你启动出问题的时候,可以检查这个日志。
1.3. Hbase Shell 练习
用shell连接你的Hbase: bin/hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hadoop/hbase-1.0.0/lib/slf4j-log4j12-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/hadoop-2.4.0/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]
2015-03-27 12:11:12,739 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.0.0, r6c98bff7b719efdb16f71606f3b7d8229445eb81, Sat Feb 14 19:49:22 PST 2015
hbase(main):001:0> (启动成功!)
输入 help 然后 <RETURN> 可以看到一列shell命令。这里的帮助很详细,要注意的是表名,行和列需要加引号。
创建一个名为 test 的表,这个表只有一个column family 为 cf。可以列出所有的表来检查创建情况,然后插入些值。
hbase(main):002:0> create 'test','cf'
0 row(s) in 0.4490 seconds
=> Hbase::Table - test
hbase(main):003:0> list 'table'
TABLE
0 row(s) in 0.0620 seconds
=> []
hbase(main):004:0> put 'test', 'row1', 'cf:a', 'value1'
0 row(s) in 0.1010 seconds
hbase(main):005:0> put 'test', 'row2', 'cf:b', 'value2'
0 row(s) in 0.0260 seconds
hbase(main):006:0> put 'test', 'row3', 'cf:c', 'value3'
0 row(s) in 0.0050 seconds
以上我们分别插入了3行。第一个行key为row1, 列为 cf:a, 值是 value1。Hbase中的列是由 column family前缀和列的名字组成的,以冒号间隔。例如这一行的列名就是a.
检查插入情况.
Scan这个表,操作如下
hbase(main):007:0> scan 'test'
ROW COLUMN+CELL
row1 column=cf:a, timestamp=1427430303770, value=value1
row2 column=cf:b, timestamp=1427430314151, value=value2
row3 column=cf:c, timestamp=1427430323452, value=value3
3 row(s) in 0.0710 seconds
Get一行,操作如下
hbase(main):008:0> get 'test', 'row1'
COLUMN CELL
cf:a timestamp=1427430303770, value=value1
1 row(s) in 0.0440 seconds
disable 再 drop 这张表,可以清除你刚刚的操作
hbase(main):012:0> disable 'test'
0 row(s) in 1.0930 seconds
hbase(main):013:0> drop 'test'
0 row(s) in 0.0770 seconds
关闭shell
hbase(main):014:0> exit
1.4. 停止 HBase
运行停止脚本来停止HBase.
$ ./bin/stop-hbase.sh
stopping hbase...............
2. Hbase集群安装配置
2.1. 修改配置文件
配置hdfs目录、ZooKeeper等,命令:vim conf/hbase-site.xml
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://master:9000/hbase</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>master,slave1,slave2</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/home/hadoop/zookeeper-3.4.6</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
</configuration>
配置JDK,命令:vim conf/hbase-env.sh
export JAVA_HOME=/usr/java/jdk
配置regionservers,命令:vim conf/regionservers
删除localhost添加以下2行
slave1
slave2
配置备份节点,命令:vim conf/backup-masters
写入一行
slave1
2.2. 将lib下面hadoop jar文件用hadoop-2.4.0版本的替换掉
这些文件在hadoop-2.4.0/share下面不同的目录内,要一个一个的找出来,不能省
(其中hadoop-client-2.4.0.jar半天找不到,后来发现在源码包hadoop-2.4.0-src/hadoop-client/target下面,复制过去OK)
2.3. 复制hbase到其它节点
scp -r ./hbase-1.0.0 hadoop@slave1:/home/hadoop/
scp -r ./hbase-1.0.0 hadoop@slave2:/home/hadoop/
2.3. 启动
命令:bin/start-hbase.sh
启动前需先启动hadoop,并kill掉HMaster
, HRegionServer
, and HQuorumPeer等进程,如果有的话(先用jps查看,然后用命令:kill 进程号)
[hadoop@master hbase-1.0.0]$ bin/start-hbase.sh
slave1: starting zookeeper, logging to /home/hadoop/hbase-1.0.0/bin/../logs/hbase-hadoop-zookeeper-slave1.out
slave2: starting zookeeper, logging to /home/hadoop/hbase-1.0.0/bin/../logs/hbase-hadoop-zookeeper-slave2.out
master: starting zookeeper, logging to /home/hadoop/hbase-1.0.0/bin/../logs/hbase-hadoop-zookeeper-master.out
starting master, logging to /home/hadoop/hbase-1.0.0/logs/hbase-hadoop-master-master.out
slave1: starting regionserver, logging to /home/hadoop/hbase-1.0.0/bin/../logs/hbase-hadoop-regionserver-slave1.out
slave2: starting regionserver, logging to /home/hadoop/hbase-1.0.0/bin/../logs/hbase-hadoop-regionserver-slave2.out
slave1: starting master, logging to /home/hadoop/hbase-1.0.0/bin/../logs/hbase-hadoop-master-slave1.out
查看各节点进程
[hadoop@master hbase-1.0.0]$ jps
8982 Jps
8245 ResourceManager
8794 HMaster
7928 NameNode
8106 SecondaryNameNode
8729 HQuorumPeer
[hadoop@slave1 ~]$ jps
3112 HRegionServer
2324 NodeManager
2231 DataNode
3335 Jps
[hadoop@slave2 ~]$ jps
3302 NodeManager
3200 DataNode
3412 Jps
2.3. 测试--和单机版一样
[hadoop@master hbase-1.0.0]$ bin/hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hadoop/hbase-1.0.0/lib/slf4j-log4j12-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/hadoop-2.4.0/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]
2015-03-27 16:17:32,322 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.0.0, r6c98bff7b719efdb16f71606f3b7d8229445eb81, Sat Feb 14 19:49:22 PST 2015
hbase(main):001:0> create 'test','cf'
0 row(s) in 1.6070 seconds
=> Hbase::Table - test
hbase(main):002:0>