0%

hbase-安装与配置

介绍hbase的安装与简单使用

准备

我的版本:

hadoop 2.7.7

zookeeper 3.5.5

hbase 1.3.5

先装好 hadoop 和 zookeeper

配置 HBase

修改 hbase-env.sh

修改hbase-1.3.5/conf下的hbase-env.sh

export JAVA_HOME=$(/usr/libexec/java_home)
# 使用自己安装的ZK
export HBASE_MANAGES_ZK=false

修改 hbase-site.xml

修改hbase-1.3.5/conf下的hbase-site.xml

<configuration>
<property>
<name>hbase.rootdir</name>
        <value>hdfs://localhost:9000/hbase</value>
    </property>
    <property>
<name>hbase.cluster.distributed</name>
        <value>true</value>
    </property>
    <property>
    <name>hbase.master</name>
        <value>master:60000</value>
    </property>
    <property>
        <name>hbase.zookeeper.quorum</name>
        <value>localhost:2181</value>
    </property>
    <property>
<name>hbase.zookeeper.property.dataDir</name>
        <value>/usr/local/apache-zookeeper-3.5.5-bin/zkData</value>
    </property>
</configuration>

添加 core-site.xml 和 hdfs-site.xml

直接在hbase-1.3.5/conf下创建软连接即可

ln -s /usr/local/hadoop-2.7.7/etc/hadoop/core-site.xml /usr/local/hbase-1.3.5/conf/core-site.xml

ln -s /usr/local/hadoop-2.7.7/etc/hadoop/hdfs-site.xml /usr/local/hbase-1.3.5/conf/hdfs-site.xml

修改 regionservers

/hbase-1.3.5/conf/regionservers 中添加集群节点的名字,用于群启与群关

localhost

使用

# 先开HDFS和ZK

# 单节点启动与关闭
bin/hbase-daemon.sh start master
bin/hbase-daemon.sh start regionserver
bin/hbase-daemon.sh stop master
bin/hbase-daemon.sh stop regionserver

# 群启与群关
bin/start-hbase.sh
bin/stop-hbase.sh

# 可视化网页
http://localhost:16010

# 正常启动后的JPS
977 ResourceManager
865 NameNode
4289 Jps
4146 HRegionServer
915 DataNode
1028 NodeManager
2360 QuorumPeerMain
4062 HMaster

简单shell操作

# 进入shell
bin/hbase shell

# 命名空间的相关操作
create_namespace 'zxylearn'

# 表的相关操作
# 建表
create 'zxylearn:student','info1','info2'

# 看表
describe 'zxylearn:student'

# 删表
disable 'zxylearn:student'
drop 'zxylearn:student'

# 数据的相关操作
# 增
put 'zxylearn:student','1001','info1:name','zhangsan'
put 'zxylearn:student','1001','info1:sex','man'
put 'zxylearn:student','1002','info1:age','22'
put 'zxylearn:student','1002','info2:addr','wuhan'
put 'zxylearn:student','1003','info2:addr','beijing'

# 查
scan 'zxylearn:student',{STARTROW=>'1001',STOPROW=>'1003'}
get 'zxylearn:student','1001'
get 'zxylearn:student','1001','info1:name'

# 改
put 'zxylearn:student','1001','info1:name','zxy'

# 删
delete 'zxylearn:student','1001','info1:sex'
deleteall 'zxylearn:student', '1002'
truncate 'zxylearn:student'