在上篇我们了解了HBase 架构相关的内容,如下:
HBase 系统架构详解
https://www.cndba.cn/dave/article/3315
本篇了解一下HBase集群环境的搭建。
1 Hadoop 集群和ZooKeeper集群搭建
因为HBase依赖与HDFS和Zookeeper环境,所有在搭建HBase集群之前需要先安装这2个环境,这里不在说明,具体操作参考之前的博客。
Linux 7.6 平台 Hadoop 3.1.1 集群搭建手册
https://www.cndba.cn/download/dave/6Zookeeper 集群安装配置
https://www.cndba.cn/dave/article/3295
测试环境中是3节点的Hadoop集群和ZooKeeper集群。
[dave@www.cndba.cn data]$ cat /etc/hosts
127.0.0.1 localhost
192.168.56.100 Master
192.168.56.101 Slave1
192.168.56.102 Slave2
[dave@www.cndba.cn data]$
[dave@www.cndba.cn data]$ yarn node --list
WARNING: YARN_CONF_DIR has been replaced by HADOOP_CONF_DIR. Using value of YARN_CONF_DIR.
2019-03-03 22:18:34,585 INFO client.RMProxy: Connecting to ResourceManager at Master/192.168.56.100:8032
Total Nodes:2
Node-Id Node-State Node-Http-Address Number-of-Running-Containers
Slave1:37588 RUNNING Slave1:8042 0
Slave2:38693 RUNNING Slave2:8042 0
[dave@www.cndba.cn data]$ jps
28672 SecondaryNameNode
19793 Jps
4745 QuorumPeerMain
28442 NameNode
28895 ResourceManager
[dave@www.cndba.cn data]$
2 搭建HBase集群
注意事项:HBase 集群对于时间的同步要求的比 HDFS 严格,所以,集群启动之前千万记住要进行时间同步,时间时间同步的配置这里不在描述。
2.1 下载软件包
直接从apache上下载:
http://hbase.apache.org/downloads.html
http://mirror.bit.edu.cn/apache/hbase/2.1.3/hbase-2.1.3-bin.tar.gz
2.2 解压缩文件
[dave@www.cndba.cn ~]$ pwd
/home/hadoop
[dave@www.cndba.cn ~]$ ls hbase-2.1.3-bin.tar.gz
hbase-2.1.3-bin.tar.gz
[dave@www.cndba.cn ~]$ tar xzvf hbase-2.1.3-bin.tar.gz
[dave@www.cndba.cn ~]$ ls
current_dept_emp.java dept_manager.java hbase-2.1.3 zookeeper
departments.java employees.java hbase-2.1.3-bin.tar.gz zookeeper-3.4.13.tar.gz
dept_emp.java hadoop sqoop zookeeper.out
dept_emp_latest_date.java hadoop-3.2.0.tar.gz sqoop-1.4.7.bin__hadoop-2.6.0.tar.gz
[dave@www.cndba.cn ~]$ mv hbase-2.1.3 hbase
[dave@www.cndba.cn ~]$ ls
current_dept_emp.java dept_manager.java hbase zookeeper
departments.java employees.java hbase-2.1.3-bin.tar.gz zookeeper-3.4.13.tar.gz
dept_emp.java hadoop sqoop zookeeper.out
dept_emp_latest_date.java hadoop-3.2.0.tar.gz sqoop-1.4.7.bin__hadoop-2.6.0.tar.gz
[dave@www.cndba.cn ~]$
2.3 添加环境变量
修改/etc/profile 文件,添加如下内容:
#HBase
export HBASE_HOME=/home/hadoop/hbase
export PATH=$PATH:$HBASE_HOME/bin
source /etc/profie #刷新配置文件
2.4 修改HBase 配置文件
2.4.1 修改hbase-env.sh 文件
修改hbase的环境配置文件hbase-env.sh, 添加如下内容:
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-7.b13.el7.x86_64
#关闭HBase自带的Zookeeper,使用Zookeeper集群
export HBASE_MANAGES_ZK=false
[dave@www.cndba.cn conf]$ pwd
/home/hadoop/hbase/conf
[dave@www.cndba.cn conf]$ ls
hadoop-metrics2-hbase.properties hbase-env.sh hbase-site.xml regionservers
hbase-env.cmd hbase-policy.xml log4j.properties
[dave@www.cndba.cn conf]$
2.4.2 修改hbase-site.xml 文件
添加如下内容:
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://Master:9000/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>Master,Slave1,Slave2</value>
</property>
<property>
<name>zookeeper.znode.parent</name>
<value>/hbase</value>
</property>
<property>
<name>hbase.unsafe.stream.capability.enforce</name>
<value>false</value>
</property>
</configuration>
说明如下:
hbase.rootdir:在HDFS上指定一个目录存放元数据,不需要手工创建,HDFS会自动创建。
hbase.cluster.distributed:是否开启分布式。
hbase.zookeeper.quorum:对应的zookeeper集群,不用加端口。
zookeeper.znode.parent:这里是我们前面修改的主目录名称。
这里要注意配置值前面不能有空格:
HBase zookeeper.RecoverableZooKeeper: Unable to create ZooKeeper Connection 解决方法
https://www.cndba.cn/dave/article/3316
hbase.unsafe.stream.capability.enforce:使用本地文件系统设置为false,使用hdfs设置为true。 在HBase 2.0.0 之后建议设置为false,否则会报如下错误:
HBase Master 启动 check the config value of ‘hbase.procedure.store.wal.use.hsync’ 解决方法
https://www.cndba.cn/dave/article/3321
2.4.3 修改regionservers文件
在regionservers文件中添加对应的节点信息。
[dave@www.cndba.cn conf]$ ls
hadoop-metrics2-hbase.properties hbase-env.sh hbase-site.xml regionservers
hbase-env.cmd hbase-policy.xml log4j.properties
[dave@www.cndba.cn conf]$ vim regionservers
[dave@www.cndba.cn conf]$ cat regionservers
Master
Slave1
Slave2
[dave@www.cndba.cn conf]$
2.4.4 修改backup-masters文件
该文件默认不存在,需要手工添加。
[dave@www.cndba.cn conf]$ pwd
/home/hadoop/hbase/conf
[dave@www.cndba.cn conf]$ touch backup-masters
[dave@www.cndba.cn conf]$ vi backup-masters
[dave@www.cndba.cn conf]$ cat backup-masters
Slave1
[dave@www.cndba.cn conf]$
2.5 整合HDFS和HBase
HBase在HDFS上存储数据,所以将hdfs-site.xml和core-site.xml文件复制到hbase的conf目录下。
[dave@www.cndba.cn conf]$ ls
backup-masters hbase-env.cmd hbase-policy.xml log4j.properties
hadoop-metrics2-hbase.properties hbase-env.sh hbase-site.xml regionservers
[dave@www.cndba.cn conf]$ pwd
/home/hadoop/hbase/conf
[dave@www.cndba.cn conf]$ cp ~/hadoop/etc/hadoop/hdfs-site.xml .
[dave@www.cndba.cn conf]$ cp ~/hadoop/etc/hadoop/core-site.xml .
[dave@www.cndba.cn conf]$ ls
backup-masters hadoop-metrics2-hbase.properties hbase-env.sh hbase-site.xml log4j.properties
core-site.xml hbase-env.cmd hbase-policy.xml hdfs-site.xml regionservers
[dave@www.cndba.cn conf]$
2.6 复制htrace包
执行如下操作:
cp $HBASE_HOME/lib/client-facing-thirdparty/htrace-core-3.1.0-incubating.jar $HBASE_HOME/lib/
如果不复制该包,在启动HMaster主进程时会异常退出,相关日志如下:
HBase HMaster 进程 java.lang.NoClassDefFoundError: org/apache/htrace/SamplerBuilder 解决方法
https://www.cndba.cn/dave/article/3320
2.7 分发Hbase
[dave@www.cndba.cn ~]$ scp -r hbase Slave2:`pwd`
[dave@www.cndba.cn ~]$ scp -r hbase Slave1:`pwd`
2.8 启动HBASE
我们配置的HBase有3个节点,启动hbase时,在哪个节点启动哪个节点就是hmaster。
启动和关闭命令如下:
start-hbase.sh / stop-hbase.sh
在一个节点执行启动命令,会启动集群中所有节点的Hbase,对于hmaster,也可以手工启动:
hbase-daemon.sh start master
hbase-daemon.sh start regionserver
2.9 Web 访问
http://192.168.56.100:16010/master-status
2.10 shell 访问
[cndba@hadoopslave1 ~]$ hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/cndba/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/cndba/hbase/lib/client-facing-thirdparty/slf4j-log4j12-1.7.25.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
Use "help" to get list of supported commands.
Use "exit" to quit this interactive shell.
For Reference, please visit: http://hbase.apache.org/2.0/book.html#shell
Version 2.1.3, rda5ec9e4c06c537213883cca8f3cc9a7c19daf67, Mon Feb 11 15:45:33 CST 2019
Took 0.0038 seconds
hbase(main):001:0> help
HBase Shell, version 2.1.3, rda5ec9e4c06c537213883cca8f3cc9a7c19daf67, Mon Feb 11 15:45:33 CST 2019
Type 'help "COMMAND"', (e.g. 'help "get"' -- the quotes are necessary) for help on a specific command.
Commands are grouped. Type 'help "COMMAND_GROUP"', (e.g. 'help "general"') for help on a command group.
COMMAND GROUPS:
Group name: general
Commands: processlist, status, table_help, version, whoami
Group name: ddl
Commands: alter, alter_async, alter_status, clone_table_schema, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, list_regions, locate_region, show_filters
Group name: namespace
Commands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables
Group name: dml
Commands: append, count, delete, deleteall, get, get_counter, get_splits, incr, put, scan, truncate, truncate_preserve
版权声明:本文为博主原创文章,未经博主允许不得转载。