環境:
操作系統:ubuntu 12.10 64bit
jdk:sun jdk 1.6 64bit
hadoop:apache hadoop 1.02
hbase:apache hbase 0.92
先決條件:配置apache hadoop append,默認這個屬性是false,需要設置為true
1)下載hbase
解壓到每台服務器的/data/soft
解壓
root@master:/data/soft# tar zxvf hbase-0.92.0.tar.gz
建立軟連
root@master:/data/soft# ln -s hbase-0.92.0 hbase
2)配置hbase
前提是安裝完成hadoop,默認在namenode上進行
1.修改conf/hbase-env.sh,添加jdk支持
export JAVA_HOME=/usr/local/jdk export HBASE_MANAGES_ZK=true export HBASE_LOG_DIR=/data/logs/hbase
2. 修改conf/hbase-site.xml,
<property> <name>hbase.rootdir</name> <value>hdfs://master:9000/hbase</value> </property> <property> <name>hbase.cluster.distributed</name> <value>true</value> </property> <property> <name>hbase.master</name> <value>hdfs://master:60000</value> </property> <property> <name>hbase.zookeeper.quorum</name> <value>slave-001,slave-002,slave-003</value> <description>Comma separated list of servers in the ZooKeeper Quorum. For example, "host1.mydomain.com,host2.mydomain.com,host3.mydomain.com". By default this is set to localhost for local and pseudo-distributed modes of operation. For a fully-distributed setup, this should be set to a full list of ZooKeeper quorum servers. If HBASE_MANAGES_ZK is set in hbase-env.sh this is the list of servers which we will start/stop ZooKeeper on. </description> </property> <property> <name>hbase.zookeeper.property.dataDir</name> <value>/data/work/zookeeper</value> <description>Property from ZooKeeper's config zoo.cfg. The directory where the snapshot is stored. </description> </property>
hbase.rootdir設置hbase在hdfs上的目錄,主機名為hdfs的namenode節點所在的主機
hbase.cluster.distributed設置為true,表明是完全分布式的hbase集群
hbase.master設置hbase的master主機名和端口
hbase.zookeeper.quorum設置zookeeper的主機,建議使用單數
3.修改hadoop的目錄下的conf/hdfs-site.xml
<property> <name>dfs.datanode.max.xcievers</name> <value>4096</value> </property>
4.修改conf/regionservers
將所有的datanode添加到這個文件,類似與hadoop中slaves文件
5.拷貝hbase到所有的節點
6. 啟動hbase
$ ./bin/start-hbase.sh
7 hbase自帶的web界面
http://master:60010/
8 測試
1).登錄hbase客戶端
./bin/hbase shell
2).新建數據表,並插入3條記錄
hbase(main):003:0> create 'test', 'cf' 0 row(s) in 1.2200 seconds hbase(main):003:0> list 'table' test 1 row(s) in 0.0550 seconds hbase(main):004:0> put 'test', 'row1', 'cf:a', 'value1' 0 row(s) in 0.0560 seconds hbase(main):005:0> put 'test', 'row2', 'cf:b', 'value2' 0 row(s) in 0.0370 seconds hbase(main):006:0> put 'test', 'row3', 'cf:c', 'value3' 0 row(s) in 0.0450 seconds
3).查看插入的數據
hbase(main):007:0> scan 'test' ROW COLUMN+CELL row1 column=cf:a, timestamp=1288380727188, value=value1 row2 column=cf:b, timestamp=1288380738440, value=value2 row3 column=cf:c, timestamp=1288380747365, value=value3 3 row(s) in 0.0590 seconds
4).讀取單條記錄
hbase(main):008:0> get 'test', 'row1' COLUMN CELL cf:a timestamp=1288380727188, value=value1 1 row(s) in 0.0400 seconds
5).停用並刪除數據表
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
6).退出
hbase(main):014:0> exit