HBase服务规划
机器名 | HMaster | HRegionServer | Zookeeper |
---|---|---|---|
node1 | Y | Y | Y |
node2 | Y | Y | Y |
node3 | N | Y | Y |
注意,如果集群较大,HMaster可以大于2。
首先通过物理机(Windows系统)下载HBase软件包,其次通过XShell上传到node1节点,然后在node1节点上进行HBase相关配置,最后分发到node2和node3节点上。按照这个思路,下面来演示HBase的安装与配置。
HBase官方网址:http://hbase.apache.org/
下载推荐的当前稳定版1.2.6
(1)上传软件包。通过XShell将HBase软件包上传到集群中的一个节点,比如node1
(2)解压缩软件包
[root@node1 ~]# tar -zxvf hbase-1.2.6-bin.tar.gz -C /opt
(3)进入HBase根目录
[root@node1 ~]# cd /opt/hbase-1.2.6/
[root@node1 hbase-1.2.6]# ls
bin CHANGES.txt conf docs hbase-webapps LEGAL lib LICENSE.txt NOTICE.txt README.txt
[root@node1 hbase-1.2.6]#
1、配置hbase-env.sh
[root@node1 hbase-1.2.6]# vi conf/hbase-env.sh
需要设置4处 (1)JAVA_HOME
# The java implementation to use. Java 1.7+ required.
export JAVA_HOME=/opt/jdk1.8.0_112
(2)针对JDK8,移除下面两项
# Configure PermSize. Only needed in JDK7. You can safely remove it for JDK8+
#export HBASE_MASTER_OPTS="$HBASE_MASTER_OPTS -XX:PermSize=128m -XX:MaxPermSize=128m"
#export HBASE_REGIONSERVER_OPTS="$HBASE_REGIONSERVER_OPTS -XX:PermSize=128m -XX:MaxPermSize=128m"
(3)设置HBASE_PID_DIR
# The directory where pid files are stored. /tmp by default.
export HBASE_PID_DIR=/var/run
(4) 不使用Hbase自带的zookeeper
# Tell HBase whether it should manage it's own instance of Zookeeper or not.
export HBASE_MANAGES_ZK=false
2、配置hbase-site.xml
[root@node1 hbase-1.2.6]# vi conf/hbase-site.xml
[root@node1 hbase-1.2.6]# cat conf/hbase-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!--
这里必须跟core-site.xml中的配置一致
namenode是HA时,hbase.rootdir=hdfs://nameservices/hbase
namenode非HA时,hbase.rootdir=hdfs://namenode节点:9000/hbase
-->
<property>
<name>hbase.rootdir</name>
<value>hdfs://cetc/hbase</value>
</property>
<!--指定Hbase是分布式的-->
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<!--hbase.master:The port the HBase Master should bind to, Default 16000-->
<!--hbase.master.info.port:The port for the HBase Master web UI. Default 16010-->
<property>
<name>dfs.support.append</name>
<value>true</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>node1:2181,node2:2181,node3:2181</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/var/lib/zookeeper</value>
</property>
</configuration>
[root@node1 hbase-1.2.6]#
提示,hbase-site.xml的参数hbase.zookeeper.property.dataDirZooKeeper与Zookeeper的zoo.conf中的dataDir对应。
3、配置regionservers
[root@node1 hbase-1.2.6]# vi conf/regionservers
[root@node1 hbase-1.2.6]# cat conf/regionservers
node1
node2
node3
[root@node1 hbase-1.2.6]#
4、设置环境变量
[root@node1 hbase-1.2.6]# cd
[root@node1 ~]# vi /etc/profile.d/custom.sh
增加如下内容
#Hbase path
export HBASE_HOME=/opt/hbase-1.2.6
export PATH=$PATH:$HBASE_HOME/bin
5、分发文件 (1)分发Hbase软件包
[root@node1 ~]# scp -r /opt/hbase-1.2.6/ node2:/opt
[root@node1 ~]# scp -r /opt/hbase-1.2.6/ node3:/opt
(2)分发环境变量文件
[root@node1 ~]# scp /etc/profile.d/custom.sh node2:/etc/profile.d/
custom.sh 100% 410 0.4KB/s 00:00
[root@node1 ~]# scp /etc/profile.d/custom.sh node3:/etc/profile.d/
custom.sh
(3)source
[root@node1 ~]# source /etc/profile.d/custom.sh
[root@node2 ~]# source /etc/profile.d/custom.sh
[root@node3 ~]# source /etc/profile.d/custom.sh
(1)不失一般性,选择node1节点启动HBase
[root@node1 ~]# start-hbase.sh
starting master, logging to /opt/hbase-1.2.6/logs/hbase-root-master-node1.out
node2: starting regionserver, logging to /opt/hbase-1.2.6/logs/hbase-root-regionserver-node2.out
node3: starting regionserver, logging to /opt/hbase-1.2.6/logs/hbase-root-regionserver-node3.out
node1: starting regionserver, logging to /opt/hbase-1.2.6/logs/hbase-root-regionserver-node1.out
(2)然后选择另一个节点启动备份Hmaster
[root@node3 ~]# hbase-daemon.sh start master
starting master, logging to /opt/hbase-1.2.6/logs/hbase-root-master-node3.out
(3)jps,查看进程 node1
[root@node1 ~]# jps
2176 QuorumPeerMain
11488 HRegionServer
3667 ResourceManager
11908 Jps
3542 NameNode
11368 HMaster
2764 JournalNode
2924 DFSZKFailoverController
3164 NodeManager
2541 DataNode
node2
[root@node2 ~]# jps
2176 QuorumPeerMain
2359 NameNode
2423 DataNode
2649 DFSZKFailoverController
5817 HRegionServer
6041 Jps
2525 JournalNode
2734 NodeManager
node3
[root@node3 ~]# jps
2177 QuorumPeerMain
2561 NodeManager
3763 HMaster
3911 Jps
2460 JournalNode
3532 HRegionServer
2366 DataNode
2703 ResourceManager
[root@node1 ~]# jps|grep HMaster
11368 HMaster
[root@node1 ~]# kill 11368
重新启动node1节点是HMaster
[root@node1 ~]# hbase-daemon.sh start master
starting master, logging to /opt/hbase-1.2.6/logs/hbase-root-master-node1.out
[root@node1 ~]# jps
2176 QuorumPeerMain
11488 HRegionServer
3667 ResourceManager
12579 HMaster
3542 NameNode
12647 Jps
2764 JournalNode
3164 NodeManager
2541 DataNode