Hbase是一个开源的分布式的NoSql数据库,采用列式存储,可支持数十亿行、百万列的数据存储和检索。由于其高效的读写性能,被广泛应用于大数据领域非结构化数据的存储和快速检索场景。
Hbase采用Master/Slave模式,集群由一到多个Master组成,Master做为管理节点,一般不存储数据。多个Slave节点做为数据存储节点,受master管理。一般Master节点叫做HMaster,同时只有一个处于active状态,其他Master处于Backup状态,类似于Hadoop的NameNode的HA。Slave节点被成为RegionServer,Hbase数据存储在多个Region中,RegionServer负责管理这些Region。
前提
- 三台linux服务器,分别命名为node1、node2、node3(已在/etc/hosts文件里做好了ip和名字的映射)
- 已经安装hdfs
- 已经安装zookeeper
-
安装包下载
地址一:
Apache HBase – Apache HBase Downloads
地址二:
Index of /hbase
-
解压并移动
tar -zxf hbase-2.4.17-bin.tar.gz
mv hbase-2.4.17 /usr/local/
-
配置环境变量
vi /etc/profile export HBASE_HOME=/export/servers/hbase export PATH=$PATH:$HBASE_HOME/bin 刷新环境变量,使配置生效 source /etc/profile
-
修改hbase-site.xml文件
vim hbase-site.xml <configuration> <property> <name>hbase.cluster.distributed</name> <value>true</value> </property> <property> <name>hbase.rootdir</name> <value>hdfs://node1:8020/hbase</value> </property> <property> <name>hbase.zookeeper.quorum</name> <value>node1,node2,node3</value> </property> </configuration>
-
配置regionservers
vim conf/regionservers node1 node2 node3
-
修改hbase-env.sh文件
尾部插入: export JAVA_HOME=/usr/local/java export HBASE_MANAGES_ZK=false
-
hbase运行
启动、停止Hbase集群 start-hbase.sh stop-hbase.sh 注:在Hmaster进程的节点机器进行 启动和停止命令
-
管理网页,浏览器输入
http://node1:16010/master-status
看到Region Servers 模块有对应的三台节点信息,说明已经成功启动了。 -
高可用(可选)
在HBase 中HMaster 负责监控 HRegionServer 的生命周期,均衡 RegionServer 的负载如果 HMaster 挂掉了,那么整个 HBase 集群将陷入不健康的状态,并且此时的工作状态并不会维持太久。所以HBase 支持对 HMaster 的高可用配置。
1)关闭 HBase 集群(如果没有开启则跳过此步) bin/stop-hbase.sh 2)在conf 目录下创建 backup-masters 文件 touch conf/backup-masters 3)在backup-masters 文件中配置高可用HMaster节点 echo node3 > conf/backup-masters 4)在其他节点上执行 1 2 3操作 5)重启 hbase,打开页面测试查看
注意:假设备用master上位后,stop-hbase.sh 命令就需要在上位的master节点上执行,当整个集群关掉 重新启动的时候,还需要在原来的master节点上执行start-hbase.sh,万不能在备用的节点上运行。
-
排错1:启动hbase时jps查看master和regionserver进程都启动成功,但是打开webui界面查看时,页面中显示 backup master以及不显示regionserver情况,hbase shlle也可以连接、看似一切都正常,查看hbase启动日志如下:
2023-05-08 15:02:46,818 WARN [RS-EventLoopGroup-1-1] concurrent.DefaultPromise: An exception was thrown by org.apache.hadoop.hbase.io.asyncfs.FanOutOneBlockAsyncDFSOutputHelper$4.operationComplete() java.lang.IllegalArgumentException: object is not an instance of declaring class at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.hadoop.hbase.io.asyncfs.ProtobufDecoder.<init>(ProtobufDecoder.java:64) at org.apache.hadoop.hbase.io.asyncfs.FanOutOneBlockAsyncDFSOutputHelper.processWriteBlockResponse(FanOutOneBlockAsyncDFSOutputHelper.java:342) at org.apache.hadoop.hbase.io.asyncfs.FanOutOneBlockAsyncDFSOutputHelper.access$100(FanOutOneBlockAsyncDFSOutputHelper.java:112) at org.apache.hadoop.hbase.io.asyncfs.FanOutOneBlockAsyncDFSOutputHelper$4.operationComplete(FanOutOneBlockAsyncDFSOutputHelper.java:424) at org.apache.hbase.thirdparty.io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:590) at org.apache.hbase.thirdparty.io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:557) at org.apache.hbase.thirdparty.io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:492) at org.apache.hbase.thirdparty.io.netty.util.concurrent.DefaultPromise.addListener(DefaultPromise.java:185) at org.apache.hadoop.hbase.io.asyncfs.FanOutOneBlockAsyncDFSOutputHelper.initialize(FanOutOneBlockAsyncDFSOutputHelper.java:418) at org.apache.hadoop.hbase.io.asyncfs.FanOutOneBlockAsyncDFSOutputHelper.access$300(FanOutOneBlockAsyncDFSOutputHelper.java:112) at org.apache.hadoop.hbase.io.asyncfs.FanOutOneBlockAsyncDFSOutputHelper$5.operationComplete(FanOutOneBlockAsyncDFSOutputHelper.java:476) at org.apache.hadoop.hbase.io.asyncfs.FanOutOneBlockAsyncDFSOutputHelper$5.operationComplete(FanOutOneBlockAsyncDFSOutputHelper.java:471) at org.apache.hbase.thirdparty.io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:590) at org.apache.hbase.thirdparty.io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:583) at org.apache.hbase.thirdparty.io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:559) at org.apache.hbase.thirdparty.io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:492) at org.apache.hbase.thirdparty.io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:636) at org.apache.hbase.thirdparty.io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:625) at org.apache.hbase.thirdparty.io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:105) at org.apache.hbase.thirdparty.io.netty.channel.DefaultChannelPromise.trySuccess(DefaultChannelPromise.java:84) at org.apache.hbase.thirdparty.io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.fulfillConnectPromise(AbstractEpollChannel.java:653) at org.apache.hbase.thirdparty.io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.finishConnect(AbstractEpollChannel.java:691) at org.apache.hbase.thirdparty.io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.epollOutReady(AbstractEpollChannel.java:567) at org.apache.hbase.thirdparty.io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:489) at org.apache.hbase.thirdparty.io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:397) at org.apache.hbase.thirdparty.io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) at org.apache.hbase.thirdparty.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at org.apache.hbase.thirdparty.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:750)
出现此错误在 hbase-site.xml 文件内添加
<property> <name>hbase.wal.provider</name> <value>filesystem</value> </property>
重启hbase即可。