A: 先配置Hadoop2.4.1的集群环境
参考:http://blog.csdn.net/wind520/article/details/38317937
B:配置HBase
参考:http://abloz.com/hbase/book.html#quickstart
1:下载 wget http://mirrors.hust.edu.cn/apache/hbase/stable/hbase-0.98.6.1-hadoop2-bin.tar.gz
2: 解压 tar zxf hbase-0.98.6.1-hadoop2-bin.tar.gz
3:配置vi hbase-site.xml
[jifeng@feng01 conf]$ cat hbase-site.xml
hbase.rootdir
hdfs://feng01:9000/hbase
hbase.cluster.distributed
true
hbase.master
feng01:60000
hbase.zookeeper.quorum
feng01,feng02,feng03
4:配置cat hbase-env.sh
修改的地方
#JDK的安装目录
export JAVA_HOME=$HOME/jdk1.7.0_45
#hadoop的配置目录
export HBASE_CLASSPATH=$HOME/hadoop/hadoop-2.4.1/etc/hadoop/
和最后一行
export HBASE_MANAGES_ZK=true
#true:表示zookeeper交给hbase管理,启动hbase时,会自动启动hbase-site.xml里的hbase.zookeeper.quorum属性中的所有zookeeper实例 #false:表示启动hbase时,要手动启动所有zookeeper实例 |
5:配置regionservers
[jifeng@feng01 conf]$ cat regionservers
feng01
feng02
feng03
6:替换lib下jar
替换hbase安装目录下的lib中使用的hadoop2.2的jar包,改成2.4.1的
写一个copy.sh,自动完成这个步骤
[jifeng@feng01 hbase-0.98.6.1-hadoop2]$ cd lib
[jifeng@feng01 lib]$ vi copy.sh
#! /bin/bash
find -name "hadoop*jar" | sed 's/2.2.0/2.4.1/g' | sed 's/.\///g' > f.log
rm ./hadoop*jar
cat ./f.log | while read Line
do
find /home/jifeng/hadoop/hadoop-2.4.1/share/hadoop -name "$Line" | xargs -i cp {} ./
done
rm ./f.log
[jifeng@feng01 lib]$ chmod 700 copy.sh
[jifeng@feng01 lib]$ ./copy.sh
/home/jifeng/hadoop/hadoop-2.4.1 是hadoop 2.4.1 的安装路径,记得修改为自己的安装目录
scp -r hbase-0.98.6.1-hadoop2 jifeng@feng02:/home/jifeng
scp -r hbase-0.98.6.1-hadoop2 jifeng@feng03:/home/jifeng
8:启动HBase
[jifeng@feng01 hbase-0.98.6.1-hadoop2]$ bin/start-hbase.sh
feng01: zookeeper running as process 4266. Stop it first.
feng03: starting zookeeper, logging to /home/jifeng/hbase-0.98.6.1-hadoop2/bin/../logs/hbase-jifeng-zookeeper-feng03.out
feng02: starting zookeeper, logging to /home/jifeng/hbase-0.98.6.1-hadoop2/bin/../logs/hbase-jifeng-zookeeper-feng02.out
starting master, logging to /home/jifeng/hbase-0.98.6.1-hadoop2/bin/../logs/hbase-jifeng-master-feng01.out
feng01: starting regionserver, logging to /home/jifeng/hbase-0.98.6.1-hadoop2/bin/../logs/hbase-jifeng-regionserver-feng01.out
feng03: starting regionserver, logging to /home/jifeng/hbase-0.98.6.1-hadoop2/bin/../logs/hbase-jifeng-regionserver-feng03.out
feng02: starting regionserver, logging to /home/jifeng/hbase-0.98.6.1-hadoop2/bin/../logs/hbase-jifeng-regionserver-feng02.out
[jifeng@feng01 hbase-0.98.6.1-hadoop2]$ bin/hbase shell
2014-10-07 18:18:38,213 INFO [main] Configuration.deprecation: hadoop.native.lib is deprecated. Instead, use io.native.lib.available
HBase Shell; enter 'help' for list of supported commands.
Type "exit" to leave the HBase Shell
Version 0.98.6.1-hadoop2, r96a1af660b33879f19a47e9113bf802ad59c7146, Sun Sep 14 21:27:25 PDT 2014
hbase(main):001:0> status
2014-10-07 18:18:57,578 WARN [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
3 servers, 0 dead, 0.3333 average load
hbase(main):002:0>
hadoop.native.lib 有个提示,先别管这个,后面在解决
C:测试
创建一个名为 test
的表,这个表只有一个 列族 为 cf
。可以列出所有的表来检查创建情况,然后插入些值。
hbase(main):001:0> create 'test', 'cf'
0 row(s) in 1.9310 seconds
=> Hbase::Table - test
hbase(main):002:0> list
TABLE
test
1 row(s) in 0.0540 seconds
=> ["test"]
hbase(main):004:0> put 'test', 'row1', 'cf:a', 'value1'
0 row(s) in 0.1120 seconds
hbase(main):005:0> put 'test', 'row2', 'cf:b', 'value2'
0 row(s) in 0.0100 seconds
hbase(main):006:0> put 'test', 'row3', 'cf:c', 'value3'
0 row(s) in 0.0080 seconds
以上我们分别插入了3行。第一个行key为row1
, 列为 cf:a
, 值是 value1
。HBase中的列是由 列族前缀和列的名字组成的,以冒号间隔。例如这一行的列名就是a
.
检查插入情况.
Scan这个表,操作如下
hbase(main):007:0> scan 'test'
ROW COLUMN+CELL
row1 column=cf:a, timestamp=1412690657950, value=value1
row2 column=cf:b, timestamp=1412690667298, value=value2
row3 column=cf:c, timestamp=1412690676484, value=value3
3 row(s) in 0.0500 seconds
hbase(main):008:0> get 'test', 'row1'
COLUMN CELL
cf:a timestamp=1412690657950, value=value1
1 row(s) in 0.0200 seconds
hbase(main):010:0> disable 'test'
0 row(s) in 3.4790 seconds
hbase(main):004:0> drop 'test'
0 row(s) in 0.2680 seconds
关闭shell
hbase(main):005:0> exit
D:停止 HBase
[jifeng@feng01 hbase-0.98.6.1-hadoop2]$ ./bin/stop-hbase.sh
stopping hbase..............
feng01: stopping zookeeper.
feng03: stopping zookeeper.
feng02: stopping zookeeper.