Skip to content

Instantly share code, notes, and snippets.

@greenqy
Created September 22, 2015 02:30
Show Gist options
  • Save greenqy/5a3758d2c84a85c69172 to your computer and use it in GitHub Desktop.
Save greenqy/5a3758d2c84a85c69172 to your computer and use it in GitHub Desktop.
install-hbase.md

hbase 安装文档

下载

hbase 1.1.2

解压并移动到 /hadoop/hbase

配置环境变量:

$ vim ~/.bashrc

# Set HBase environment
export HBASE_HOME=/hadoop/hbase
export PATH=$HBASE_HOME/bin:$PATH

$ source ~/.bashrc

配置文件

hbase 的配置文件所在目录为 $HBASE_HOME/conf.

配置 hbase-env.sh, 设置环境变量 JAVA_HOME:

export JAVA_HOME=/usr/lib/jdk1.7.0_67

配置 hbase-site.xml:

hbase.cluster.distributed 设为 true, 采用真分布式; hbase.rootdir 使用 hdfs://namenode:9000/hbase 来存放 hbase 的数据, 注意此处的 9000 端口应当与 hadoop 中 core-site.xml 中的 fs.defaultFS 的值一致; hbase.zookeeper.quorum 用来配置 zookeeper, 将所有的节点都放入其中即可.

<configuration>
  <property>
    <name>hbase.cluster.distributed</name>
    <value>true</value>
  </property>
  <property>
    <name>hbase.rootdir</name>
    <value>hdfs://namenode:9000/hbase</value>
  </property>
  <property>
    <name>hbase.zookeeper.property.dataDir</name>
    <value>/hadoop/hbase/zookeeper</value>
  </property>
  <property>
    <name>hbase.zookeeper.quorum</name>
    <value>namenode,datanode01,datanode02,datanode03,datanode04</value>
  </property>
</configuration>

配置 regionservers:

datanode01
datanode02
datanode03
datanode04

配置 backup-masters:

datanode01

集群间同步 hbase

将 $HBASE_HOME 目录同步到所有的节点上, 并配置相应的环境变量.

启动/关闭

启动:

$ start-hbase.sh

查看进程:

## namenode
$ jps
20355 Jps
20071 HQuorumPeer
20137 HMaster


## datanode01
$ jps
15930 HRegionServer
16194 Jps
15838 HQuorumPeer
16010 HMaster

## datanode02-04
$ jps
13901 Jps
13639 HQuorumPeer
13737 HRegionServer

关闭:

$ stop-hbase.sh

基本操作

启动 habse shell:

$ ./bin/hbase shell
hbase(main):001:0>

创建表:

hbase(main):001:0> create 'test', 'cf'
0 row(s) in 0.4170 seconds

=> Hbase::Table - test

查看表的信息:

hbase(main):002:0> list 'test'
TABLE
test
1 row(s) in 0.0180 seconds

=> ["test"]

插入数据:

hbase(main):003:0> put 'test', 'row1', 'cf:a', 'value1'
0 row(s) in 0.0850 seconds

hbase(main):004:0> put 'test', 'row2', 'cf:b', 'value2'
0 row(s) in 0.0110 seconds

hbase(main):005:0> put 'test', 'row3', 'cf:c', 'value3'
0 row(s) in 0.0100 seconds

查看表中的数据:

hbase(main):006:0> scan 'test'
ROW                                      COLUMN+CELL
 row1                                    column=cf:a, timestamp=1421762485768, value=value1
 row2                                    column=cf:b, timestamp=1421762491785, value=value2
 row3                                    column=cf:c, timestamp=1421762496210, value=value3
3 row(s) in 0.0230 seconds

退出 hbase shell:

hbase(main):007:0> quit

如果中间没有报错, 则可以说明 hbase 安装成功.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment