Hbase1:HBase全分布模式安装

HBase环境搭建有三种方式:1.本地模式:只需要一个节点(只有HMaster,没有HRegionServer),不需要集成ZooKeeper,数据存储在本地文件系统上;2.伪分布模式:只需要一个节点(HMaster和HRegionServer在同一个节点上),需要集成ZooKeeper,数据存储在HDFS上;3.全分布模式:至少需要3个节点(一个HMaster节点和至少2个HRegionServer节点),需要集成ZooKeeper,数据存储在HDFS上。本节先来介绍HBase伪分布模式的环境搭建过程。
集群环境介绍:
master 192.168.112.10
slave1 192.168.112.11
slave2 192.168.112.12
zookeeper安装包:zookeeper-3.4.11:https://pan.baidu.com/s/1_6TQRcybzU4PDY_-oOREmA

1.搭建Hadoop全分布环境

Hadoop全分布模式的搭建过程请参看文章:
https://www.jianshu.com/p/2a947044f2dc

2.搭建ZooKeeper伪分布环境

请参看文章:
https://www.jianshu.com/p/8935a8a34d6a

3.搭建HBase全分布环境

3.1 下载HBase安装包:
可以从上面的安装介质链接中下载HBase安装包,或者去HBase官网hbase.apache.org下载最新HBase安装包,然后使用WinSCP工具将下载好的安装包上传至master节点的/usr/local/src目录下。
/usr/local/src/hbase-2.0.1

3.2 解压:
tar -zxvf hbase-2.0.1-bin.tar.gz

3.3 配置HBase环境变量(三台机器都做一遍)

root@master tools]# cd /usr/local/src/hbase-2.0.1/
[root@master hbase-2.0.1]# pwd
/usr/local/src/hbase-2.0.1
[root@master hbase-2.0.1]# vim /root/.bash_profile
HBASE_HOME=/usr/local/src/hbase-2.0.1
export HBASE_HOME
PATH=$HBASE_HOME/bin:$PATH
export PATH
[root@master hbase-2.0.1]# source /root/.bash_profile

3.4 配置HBase配置文件

配置前启动Hadoop全分布集群:
[root@master sbin]# ./start-all.sh,启动后在HDFS上新建一个目录用来存储HBase的数据:

[root@master ~]# hdfs dfs -mkdir /hbase

3.5 进入$HBASE_HOME/conf目录,配置hbase-env.sh:

[root@master conf]# vim hbase-env.sh
# The java implementation to use. Java 1.8+ required.
# export JAVA_HOME=/usr/java/jdk1.8.0/
export JAVA_HOME=/root/trainings/jdk1.8.0_144
export HBASE_MANAGES_ZK=true(使用hbase自带的zookeeper)

3.6 配置hbase-site.xml

[root@localhost conf]# vim hbase-site.xml

  
    hbase.rootdir
    hdfs://master:9000/hbase
  
   
    hbase.cluster.distributed 
    true 
  
   
    hbase.zookeeper.quorum 
    master 
  
   
    dfs.replication 
    2 
  

3.7 配置regionservers

[root@master conf]# vim regionservers
slave1
slave2

3.8 将配置好的HBase目录分发给从节点
[root@master src]# scp -rp hbase-2.0.1 slave1:/usr/local/src/
[root@master src]# scp -rp hbase-2.0.1 slave2:/usr/local/src/

3.9 启动HBase集群
]# start-hbase.sh

[root@master src]# start-hbase.sh
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/src/hbase-2.0.1/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/src/hadoop-2.7.3/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/src/hbase-2.0.1/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/src/hadoop-2.7.3/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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]
master: running zookeeper, logging to /usr/local/src/hbase-2.0.1/bin/../logs/hbase-root-zookeeper-master.out
running master, logging to /usr/local/src/hbase-2.0.1/logs/hbase-root-master-master.out
slave1: running regionserver, logging to /usr/local/src/hbase-2.0.1/bin/../logs/hbase-root-regionserver-slave1.out
slave2: running regionserver, logging to /usr/local/src/hbase-2.0.1/bin/../logs/hbase-root-regionserver-slave2.out
[root@master src]#

3.10.1 检查进程:
[root@master src]# jps
2709 SecondaryNameNode
2522 NameNode
3930 Jps
3693 HQuorumPeer
2863 ResourceManager
3759 HMaster

[root@slave1 ~]# jps
2288 NodeManager
2180 DataNode
2505 HRegionServer
2638 Jps

[root@slave2 ~]# jps
2657 Jps
2500 HRegionServer
2262 NodeManager
2153 DataNode

可以看到,HBase全分布模式启动之后HMaster进程和HRegionServer进程在位于不同的节点上。

可以在网页上监控HBase的状态信息:端口号16010

4.使用HBase shell

使用hbase shell命令可以进入HBase命令行模式:

[root@master ~]# hbase shell
2018-07-16 23:32:59,553 WARN [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
HBase Shell
Use "help" to get list of supported commands.
Use "exit" to quit this interactive shell.
Version 2.0.1, r987f7b6d37c2fcacc942cc66e5c5122aba8fdfbe, Wed Jun 13 12:03:55 PDT 2018
Took 0.0020 seconds
hbase(main):001:0> create 'tblStudent','Info','Grade'
Created table tblStudent
Took 1.8144 seconds
=> Hbase::Table - tblStudent
hbase(main):002:0> put 'tblStudent','stu001','Info:name','Tom'
Took 0.1655 seconds
hbase(main):003:0> put 'tblStudent','stu001','Info:age','25'
Took 0.0129 seconds
hbase(main):004:0> put 'tblStudent','stu001','Grade:chinese','88'
Took 0.0053 seconds
hbase(main):005:0> put 'tblStudent','stu001','Grade:math','90'
Took 0.0080 seconds
hbase(main):006:0> put 'tblStudent','stu002','Info:name','Jack'
Took 0.0042 seconds
hbase(main):007:0> put 'tblStudent','stu002','Info:age','23'
Took 0.6333 seconds
hbase(main):008:0> put 'tblStudent','stu002','Grade:english','78'
Took 0.0457 seconds
hbase(main):009:0> put 'tblStudent','stu002','Grade:math','60'
Took 0.0108 seconds
hbase(main):010:0> scan 'tblStudent'
ROW COLUMN+CELL
stu001 column=Grade:chinese, timestamp=1531755222379, value=88
stu001 column=Grade:math, timestamp=1531755227442, value=90
stu001 column=Info:age, timestamp=1531755216220, value=25
stu001 column=Info:name, timestamp=1531755211017, value=Tom
stu002 column=Grade:english, timestamp=1531755253054, value=78
stu002 column=Grade:math, timestamp=1531755258620, value=60
stu002 column=Info:age, timestamp=1531755246729, value=23
stu002 column=Info:name, timestamp=1531755232841, value=Jack
2 row(s)
Took 0.0607 seconds
hbase(main):011:0> quit

使用quit命令退出HBase命令行环境。

查看HDFS上/hbase目录下产生的数据:

[root@slave2 ~]# hdfs dfs -ls /hbase
Found 12 items
drwxr-xr-x - root supergroup 0 2018-10-06 01:16 /hbase/.hbck
drwxr-xr-x - root supergroup 0 2018-10-08 22:53 /hbase/.tmp
drwxr-xr-x - root supergroup 0 2018-10-08 22:53 /hbase/MasterProcWALs
drwxr-xr-x - root supergroup 0 2018-10-08 22:53 /hbase/WALs
drwxr-xr-x - root supergroup 0 2018-10-07 13:02 /hbase/archive
drwxr-xr-x - root supergroup 0 2018-10-06 01:16 /hbase/corrupt
drwxr-xr-x - root supergroup 0 2018-10-06 01:16 /hbase/data
-rw-r--r-- 2 root supergroup 42 2018-10-06 01:16 /hbase/hbase.id
-rw-r--r-- 2 root supergroup 7 2018-10-06 01:16 /hbase/hbase.version
drwxr-xr-x - root supergroup 0 2018-10-06 01:16 /hbase/mobdir
drwxr-xr-x - root supergroup 0 2018-10-08 22:53 /hbase/oldWALs
drwx--x--x - root supergroup 0 2018-10-06 01:16 /hbase/staging

5.停止HBase全分布模式

[root@master src]# stop-hbase.sh
stopping hbase.................
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/src/hbase-2.0.1/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/src/hadoop-2.7.3/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/src/hbase-2.0.1/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/src/hadoop-2.7.3/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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]
master: running zookeeper, logging to /usr/local/src/hbase-2.0.1/bin/../logs/hbase-root-zookeeper-master.out
master: stopping zookeeper.
[root@master src]# jps
2709 SecondaryNameNode
4486 Jps
2522 NameNode
2863 ResourceManager
[root@master src]#

[root@slave1 ~]# jps
2288 NodeManager
2180 DataNode
2751 Jps

[root@slave2 ~]# jps
3378 Jps
2262 NodeManager
2153 DataNode

至此,HBase全分布模式环境搭建完成!

你可能感兴趣的:(Hbase1:HBase全分布模式安装)