hbase单机版搭建以及完全分布式集群搭建详细过程

   hbase单机版搭建并不需要hadoop环境,zookeeper也是hbase使用自己内部的zookeeper,只需要一个hbase安装包hbase-1.2.6-bin.tar.gz即可完成hbase单机版的搭建。

一、上传hbase安装包到root目录下

二、解压:

[[email protected] ~]#mkdir -p /usr/local/hbase&&tar -zxvf hbase-1.2.6-bin.tar.gz -C /usr/local/hbase

三、切换到hbase的配置目录:

[[email protected] ~]#cd /usr/local/hbase/hbase-1.2.6/conf

四、配置hbase-env.sh:

export JAVA_HOME=/usr/local/java/jdk1.7.0_80

五、配置hbase-site.xml:

<property>
    <name>hbase.rootdir</name>
    <value>file:///tmp/hbase</value>
  </property>
  <property>
    <name>hbase.zookeeper.property.dataDir</name>
    <value>/tmp/zookeeper</value>
  </property>

因为等会还要在虚拟机上配置分布式的hbase,所以这里我写了个tmp目录,生产中千万别写这个tmp目录哦,linux在重启的时候会清空tmp。

六、就这样就配置完成了,是不是比jdk还要简单?启动hbase:

[[email protected] /usr/local/hbase/hbase-1.2.6/conf]#cd /usr/local/hbase/hbase-1.2.6/bin
[[email protected] /usr/local/hbase/hbase-1.2.6/bin]#./start-hbase.sh 
starting master, logging to /usr/local/hbase/hbase-1.2.6/bin/../logs/hbase-root-master-node113.out

七、启动成功验证:

[[email protected] /usr/local/hbase/hbase-1.2.6/bin]#jps
9457 HMaster
9610 Jps
[[email protected] /usr/local/hbase/hbase-1.2.6/bin]#netstat -tunpl|grep java
tcp6       0      0 192.168.28.113:43601    :::*                    LISTEN      9457/java           
tcp6       0      0 192.168.28.113:38711    :::*                    LISTEN      9457/java           
tcp6       0      0 :::2181                 :::*                    LISTEN      9457/java           
tcp6       0      0 :::46760                :::*                    LISTEN      9457/java           
tcp6       0      0 :::16010                :::*                    LISTEN      9457/java

已经有了HMaster进程。下面的2181端口我们知道是zk的端口,这说明,hbase单机版使用的是内置的zk。接着我们访问http://node113:16010这个网址,这个网址是hbase的web管理查看界面:

hbase单机版搭建以及完全分布式集群搭建详细过程

八、最后进入hbase的交互式命令行,输入./hbase  shell即可

[[email protected] /usr/local/hbase/hbase-1.2.6/bin]#./hbase  shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar: 
StaticLoggerBinder.class]
SLF4J: Found binding in [jar: 
org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 1.2.6, rUnknown, Mon May 29 02:25:32 CDT 2017

hbase(main):001:0>

hbase原地待命了,下篇说说hbase的命令。

九、停止hbase

[[email protected] /usr/local/hbase/hbase-1.2.6/bin]#./stop-hbase.sh

 

--------------------hbase集群搭建--------------------

hbase部署规划:

  zk master regionserver
node112 1 1 1
node113 1 1 1
node114 1   1

下面开始搭建hbase完全分布式集群,前提在这里三个节点已经搭建好了hadoop完全分布式集群环境,关于hadoop完全分布式集群的搭建,参见“hadoop2.6.5完全分布式集群搭建”。

任意选择一个节点,这里选择的是node113。

一、上传hbase安装包到root目录下

二、解压:

1

[[email protected] ~]#mkdir -p /usr/local/hbase&&tar -zxvf hbase-1.2.6-bin.tar.gz -C /usr/local/hbase

三、切换到hbase的配置目录:

1

[[email protected] ~]#cd /usr/local/hbase/hbase-1.2.6/conf

四、配置hbase-env.sh:

1

export JAVA_HOME=/usr/local/java/jdk1.7.0_80

export HBASE_MANAGES_ZK=false

为false表示让hbase不再使用自己的zk集群。

五、配置hbase-site.xml:

 <configuration>
  <property>
    <name>hbase.rootdir</name>
    <!--hdfs上的一个目录,hbase这个目录会自己创建,mycluster为hadoop集群的nameservices->
    <value>hdfs://mycluster/hbase</value>
  </property>
  <!--启用分布式-->
  <property>
    <name>hbase.cluster.distributed</name>
    <value>true</value>
  </property>
  <!--原先安装hadoop集群的时候你的zk安装在哪里,这里就写哪里-->
  <property>
    <name>hbase.zookeeper.quorum</name>
    <value>node112,node113,node114</value>
  </property>
</configuration>

六、vi regionservers

node112
node113
node114

七、为了对master做高可用,需要创建一个名为backup-masters的文件并写入backup的master的主机名,vi backup-masters:

node112

八、把hadoop的hdfs-site.xml拷贝到hbase的conf目录下。

[[email protected] /usr/local/hbase/hbase-1.2.6/conf]#cp /usr/local/hadoop/hadoop-2.6.5/etc/hadoop/hdfs-site.xml ./

九、在node112、node114重复上面的八个步骤

十、确保zk与hadoop集群都正确启动

十一、选择一个节点node113吧,执行命令:

[[email protected] /usr/local/hbase/hbase-1.2.6/bin]#./start-hbase.sh 
starting master, logging to /usr/local/hbase/hbase-1.2.6/bin/../logs/hbase-root-master-node113.out
node114: starting regionserver, logging to /usr/local/hbase/hbase-1.2.6/bin/../logs/hbase-root-regionserver-node114.out
node112: starting regionserver, logging to /usr/local/hbase/hbase-1.2.6/bin/../logs/hbase-root-regionserver-node112.out
node113: starting regionserver, logging to /usr/local/hbase/hbase-1.2.6/bin/../logs/hbase-root-regionserver-node113.out
node112: starting master, logging to /usr/local/hbase/hbase-1.2.6/bin/../logs/hbase-root-master-node112.out

分别在node113、node112、node114执行命令jps查看进程:

node113:

hbase单机版搭建以及完全分布式集群搭建详细过程

node112:

hbase单机版搭建以及完全分布式集群搭建详细过程

node114:

hbase单机版搭建以及完全分布式集群搭建详细过程

分别访问http://node112:50070和http://node113:50070和http://node113:8088/cluster检验namenode和mr的web界面也是没问题的。

访问主hbase的master:http://node113:16010/master-status

hbase单机版搭建以及完全分布式集群搭建详细过程

访问主hbase的backup-master:http://node112:16010/master-status

hbase单机版搭建以及完全分布式集群搭建详细过程

十二、验证hmaster的高可用性(思路:在node113上创建表并插入一条数据,然后把node113的hmaster进程kill掉,观察http://node112:16010/master-status是否变为主master,然后再连接hbase集群看还能不能查到刚才插入的数据)

    12.1  

hbase(main):001:0> create 'tb1','cf1'
0 row(s) in 2.0410 seconds

=> Hbase::Table - tb1
hbase(main):002:0> put 'tb1','1','cf1:name','haha'
0 row(s) in 0.9040 seconds

当然,在hdfs上已经存在了cf1:

hbase单机版搭建以及完全分布式集群搭建详细过程

    12.2 杀掉node113的hmaster进程:

[[email protected] /usr/local/hadoop/hadoop-2.6.5/logs]#jps
22592 Jps
20623 DataNode
22406 Main
20996 ResourceManager
21837 HRegionServer
20907 DFSZKFailoverController
20526 NameNode
20783 JournalNode
16866 QuorumPeerMain
21709 HMaster
21115 NodeManager
[[email protected] /usr/local/hadoop/hadoop-2.6.5/logs]#kill -9 21709
[[email protected] /usr/local/hadoop/hadoop-2.6.5/logs]#

12.3  查看hbase的web管理界面的状态http://node112:16010/master-status

hbase单机版搭建以及完全分布式集群搭建详细过程

而http://node113:16010/master-status已经不能访问了。

12.4 依然在node113上连接hbase交互式命令行:

hbase单机版搭建以及完全分布式集群搭建详细过程

完全没有问题,说明zookeeper以前成功履行了自己的高可用功能,完成了hbase  master节点的自动切换。