https://blog.csdn.net/pucao_cug/article/details/72229223
1下载和解压缩
1.1下载
1.2解压缩
2 配置
2.1环境变量配置
2.2 conf目录下的配置
2.2.1修改hbase-env.sh文件
2.2.2修改配置文件hbase-site.xml
2.2.3修改regionservers文件
3启动和测试
3.1启动
3.2测试
3.2.1用浏览器访问Hbase状态信息
3.2.2启动hbase的命令行
关键词:Linux CentOS Hadoop Hbase Zookeeper JAVA
版本号:CentOS7 Hadoop2.8.0 Hbase1.2.5 Zookeeper3.4.10 JDK1.8
说明:Hbase可以在Hadoop集群的某些机器(一台也可以,例如选择namenode节点来安装)上安装,也可以全部机器上都安装。Hbase是依赖Hadoop和Zookeeper的,所以在安装Hbase之前,请先安装Hadoop和Zookeeper,Zookeeper可以是单机的也可以是集群,Hadoop的安装请参考博文:
http://blog.csdn.net/pucao_cug/article/details/71698903
Zookeeper的安装请参考:
http://blog.csdn.net/pucao_cug/article/details/72228973
可以直接在CentOS上用wget下载,也可以在本地下载之后再用工具上载到CetnOS上。
目前稳定的版本是1.2.5,所以这里也是安装1.2.5。
下载地址:
http://mirror.bit.edu.cn/apache/hbase/stable/
如图:
使用root账号登录,在opt命令下新建一个没hbase的目录,把压缩包放到该目录下
如图:
进入到该目录内然:
cd /opt/hbase
执行解压缩命令:
tar -xvf hbase-1.2.5-bin.tar.gz
在/etc/profile文件中主要增加的内容是:
ZK_HOME=/opt/zookeeper/zookeeper-3.4.10
HBASE_HOME=/opt/hbase/hbase-1.2.5
PATH中增加:
$HBASE_HOME/bin:$ZK_HOME/bin
我的/etc/profile文件中主要的配置:
export JAVA_HOME=/opt/java/jdk1.8.0_121
export HADOOP_HOME=/opt/hadoop/hadoop-2.8.0
export HADOOP_CONF_DIR=${HADOOP_HOME}/etc/hadoop
export HADOOP_COMMON_LIB_NATIVE_DIR=${HADOOP_HOME}/lib/native
export HADOOP_OPTS="-Djava.library.path=${HADOOP_HOME}/lib"
export HIVE_HOME=/opt/hive/apache-hive-2.1.1-bin
export HIVE_CONF_DIR=${HIVE_HOME}/conf
export SQOOP_HOME=/opt/sqoop/sqoop-1.4.6.bin__hadoop-2.0.4-alpha
export HBASE_HOME=/opt/hbase/hbase-1.2.5
export ZK_HOME=/opt/zookeeper/zookeeper-3.4.10
export CLASS_PATH=.:${JAVA_HOME}/lib:${HIVE_HOME}/lib:$CLASS_PATH
exportPATH=.:${JAVA_HOME}/bin:${HADOOP_HOME}/bin:${HADOOP_HOME}/sbin:${SPARK_HOME}/bin:${ZOOKEEPER_HOME}/bin:${HIVE_HOME}/bin:${SQOOP_HOME}/bin:${HBASE_HOME}:${ZK_HOME}/bin:$PATH
说明:环境变量配置完后,要执行source /etc/profile才能生效。
对/opt/hbase/hbase-1.2.5/conf目录下的一系列文件做配置。使用命令进入到该目录:
cd /opt/hbase/hbase-1.2.5/conf
在/opt/hbase/hbase-1.2.5/conf/hbase-env.sh中增加内容:
export JAVA_HOME=/opt/java/jdk1.8.0_121
export HADOOP_HOME=/opt/hadoop/hadoop-2.8.0
export HBASE_HOME=/opt/hbase/hbase-1.2.5
export HBASE_CLASSPATH=/opt/hadoop/hadoop-2.8.0/etc/hadoop
export HBASE_PID_DIR=/root/hbase/pids
export HBASE_MANAGES_ZK=false
如图:
在该配置文件中可以给hbase配置一个临时目录,这里指定为mkdir /root/hbase/tmp,先执行命令创建文件夹。
执行新建目录的命令:
mkdir /root/hbase
mkdir /root/hbase/tmp
mkdir /root/hbase/pids
在
<property>
<name>hbase.rootdirname>
<value>hdfs://hserver1:9000/hbasevalue>
<description>The directory shared byregion servers.description>
property>
<property>
<name>hbase.zookeeper.property.clientPortname>
<value>2181value>
<description>Property from ZooKeeper'sconfig zoo.cfg. The port at which the clients will connect.
description>
property>
<property>
<name>zookeeper.session.timeoutname>
<value>120000value>
property>
<property>
<name>hbase.zookeeper.quorumname>
<value>hserver1,hserver2,hserver3value>
property>
<property>
<name>hbase.tmp.dirname>
<value>/root/hbase/tmpvalue>
property>
<property>
<name>hbase.cluster.distributedname>
<value>truevalue>
property>
修改完成后,我的hbase-site.xml内容是:
xmlversion="1.0"?>
xml-stylesheettype="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>hbase.rootdirname>
<value>hdfs://hserver1:9000/hbasevalue>
<description>The directory shared byregion servers.description>
property>
<property>
<name>hbase.zookeeper.property.clientPortname>
<value>2181value>
<description>Property from ZooKeeper'sconfig zoo.cfg. The port at which the clients will connect.
description>
property>
<property>
<name>zookeeper.session.timeoutname>
<value>120000value>
property>
<property>
<name>hbase.zookeeper.quorumname>
<value>hserver1,hserver2,hserver3value>
property>
<property>
<name>hbase.tmp.dirname>
<value>/root/hbase/tmpvalue>
property>
<property>
<name>hbase.cluster.distributedname>
<value>truevalue>
property>
configuration>
将该文件内容修改为:
hserver1
hserver2
hserver3
如图:
Hbase是基于hadoop提供的分布式文件系统的,所以启动Hbase之前,先确保hadoop在正常运行,另外Hbase还依赖于zookkeeper,本来我们可以用hbase自带的zookeeper,但是我们上面的配置启用的是我们自己的zookeeper集群,所以在启动hbase前,还要确保zokeeper已经正常运行。
Hbase可以只在hadoop的某个namenode节点上安装,也可以在所有的hadoop节点上安装,但是启动的时候只需要在一个节点上启动就行了,本例中,我在hserver1、hserver2、hserver3都安装了Hbase,启动的时候只需要在hserver1上启动就OK。
在hserver1上执行命令,进入到Hbase的bin目录内,命令是:
cd /opt/hbase/hbase-1.2.5/bin
执行命令启动Hbase,命令是:
./start-hbase.sh
如图:
输出信息是:
[root@hserver1~]# cd /opt/hbase/hbase-1.2.5/bin
[root@hserver1bin]# ./start-hbase.sh
starting master,logging to /opt/hbase/hbase-1.2.5/logs/hbase-root-master-hserver1.out
Java HotSpot(TM)64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in8.0
Java HotSpot(TM)64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removedin 8.0
hserver3:starting regionserver, logging to /opt/hbase/hbase-1.2.5/logs/hbase-root-regionserver-hserver3.out
hserver2:starting regionserver, logging to/opt/hbase/hbase-1.2.5/logs/hbase-root-regionserver-hserver2.out
hserver2: JavaHotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; supportwas removed in 8.0
hserver2: JavaHotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; supportwas removed in 8.0
hserver3: JavaHotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; supportwas removed in 8.0
hserver3: Java HotSpot(TM)64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removedin 8.0
hserver1:starting regionserver, logging to/opt/hbase/hbase-1.2.5/logs/hbase-root-regionserver-hserver1.out
[root@hserver1bin]#
直接访问地址:http://192.168.27.139:16030/
如图:
执行命令,进入到Hbase的bin目录内,命令是:
cd /opt/hbase/hbase-1.2.5/bin
执行命令启动Hbase命令行窗口,命令是:
./hbase shell
如图:
完整的输出是:
[root@hserver1 bin]# cd /opt/hbase/hbase-1.2.5/bin
[root@hserver1 bin]# ./hbase shell
2017-05-15 17:52:55,411 WARN [main] util.NativeCodeLoader: Unable to loadnative-hadoop library for your platform... using builtin-java classes whereapplicable
SLF4J: Class path contains multiple SLF4Jbindings.
SLF4J: Found binding in[jar:file:/opt/hbase/hbase-1.2.5/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in[jar:file:/opt/hadoop/hadoop-2.8.0/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Seehttp://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type[org.slf4j.impl.Log4jLoggerFactory]
HBase Shell; enter 'help' forlist of supported commands.
Type "exit" toleave the HBase Shell
Version 1.2.5,rd7b05f79dee10e0ada614765bb354b93d615a157, Wed Mar 1 00:34:48 CST 2017
在hbase命令行模式下,可以输入一系列hbase命令,进行测试
输入:status
如图:
完整的输出是:
hbase(main):001:0> status
1 active master, 0 backup masters, 3servers, 0 dead, 0.6667 average load
hbase(main):002:0>
如果要退出Hbase命令行模式的话,输入:exit
如图: