原理啥的稍候再说,先体验一下hbase。
从官网上下载hbase hbase-0.92.1.tar.gz,然后复制wenbo00这个虚拟机上,然后使用tar命令解压,解压后在本机的位置为/home/hbase-0.92.1,进入conf目录下,编辑hbase-site文件
<configuration> <property> <name>hbase.rootdir</name> <value>hdfs://wenbo00:9000/hbase</value> </property> <property> <name>hbase.cluster.distributed</name> <value>true</value> </property> <property> <name>hbase.zookeeper.quorum</name> <value>wenbo01</value> </property> <property> <name>hbase.tmp.dir</name> <value>/home/hadoop/hbase-tmp</value> </property> </configuration>
注意hbase.rootdir中hdfs://wenbo00:9000/这个地址必须与hadoop相同,hbase.zookeeper.quorum配置的数量必须为奇数。
修改hbase-env.sh文件。配置jdk home
export JAVA_HOME=/home/java/jdk1.6.0_31
修改/etc/profile文件,添加hbase的环境变量
export HBASE_HOME=/home/hbase-0.92.1 export PATH=$HBASE_HOME/bin:$PATH
将所有的dataNode配置在regionservers中
wenbo01 wenbo02
最后利用scp命令将hbase目录复制到各个dataNode之上。
完成后启动hbase
root@wenbo00:/home/hbase-0.92.1/conf# start-hbase.sh wenbo01: starting zookeeper, logging to /home/hbase-0.92.1/bin/../logs/hbase-root-zookeeper-wenbo01.out starting master, logging to /home/hbase-0.92.1/logs/hbase-root-master-wenbo00.out wenbo01: starting regionserver, logging to /home/hbase-0.92.1/bin/../logs/hbase-root-regionserver-wenbo01.out wenbo02: starting regionserver, logging to /home/hbase-0.92.1/bin/../logs/hbase-root-regionserver-wenbo02.out
使用JPS命令查看NameNode,可以看到新加入的HMaster
root@wenbo00:/home/hbase-0.92.1/conf# jps 2886 Jps 1431 SecondaryNameNode 2698 HMaster 1503 JobTracker 1287 NameNode
使用JPS命令查看wenbo01的DataNode,可以看到除了启动 HRegionServer外,还启动了 HQuorumPeer
root@wenbo01:~# jps 1367 DataNode 1434 TaskTracker 1724 HQuorumPeer 1947 Jps 1808 HRegionServer
使用JPS命令查看wenbo02的DataNode,只增加了HRegionServer的启动
root@wenbo02:~# jps 1744 HRegionServer 1897 Jps 1369 DataNode 1437 TaskTracker
成功启动hbase后,使用命令进入hbase的命令行
root@wenbo00:/home/hbase-0.92.1/conf# hbase shell HBase Shell; enter 'help<RETURN>' for list of supported commands. Type "exit<RETURN>" to leave the HBase Shell Version 0.92.1, r1298924, Fri Mar 9 16:58:34 UTC 2012 hbase(main):001:0>
创建一个名为test,只有一列的表
hbase(main):001:0> create 'test','cf' 0 row(s) in 36.3930 seconds
查看刚才创建的表
hbase(main):003:0> list TABLE test 1 row(s) in 0.0410 seconds
往test表里插入三条数据
hbase(main):004:0> put 'test','row1','cf:a','valueA' 0 row(s) in 0.4260 seconds hbase(main):005:0> put 'test','row2','cf:b','valueB' 0 row(s) in 0.0460 seconds hbase(main):006:0> put 'test','row3','cf:c','valueC' 0 row(s) in 0.0680 seconds
查看刚刚插入的数据
hbase(main):007:0> scan 'test' ROW COLUMN+CELL row1 column=cf:a, timestamp=1332151134694, value=valueA row2 column=cf:b, timestamp=1332151172105, value=valueB row3 column=cf:c, timestamp=1332151197886, value=valueC 3 row(s) in 0.0570 seconds
查看指定的某一行
hbase(main):009:0> get 'test','row1' COLUMN CELL cf:a timestamp=1332151134694, value=valueA 1 row(s) in 0.0770 seconds
禁用表
hbase(main):010:0> disable 'test' 0 row(s) in 2.1980 seconds
删除表
hbase(main):012:0> drop 'test' 0 row(s) in 1.9930 seconds hbase(main):013:0> list TABLE 0 row(s) in 0.0510 seconds