Hbase学习笔记2--Hbase集群搭建

叶子创业记

共 2309字,需浏览 5分钟

 · 2022-03-04

单机版

首先去hbase官网下载需要的版本,然后解压到相应得节点上。

https://archive.apache.org/dist/hbase/

然后阅读官方文档,找到搭建文档,找到配置文件属性。

https://hbase.apache.org/2.0/book.html#quickstart


b38b12a2a7c873fc51190c0d745fd9bd.webp

配置hbase-site.xml

5610c686c64559c9fa43b0a7562f6baf.webp

启动Hbase

 start-hbase.sh

打开shell脚本

hbase shell

创建表

创建表必须带有一个列族。其中cf就代表一个列族。如下查看表详情得时候,给我们列出来的信息都是按照列族来的。

create 'psn','cf'
create 'psn1','cf1','cf2'
b1e5c211f1a1cbac5ad9c9721e2fc4db.webp

插入数据

列族插入数据,每次插入都要指明本次插入得列族以及字段。如果不带cf得话,就会抛异常,无法找该列族。

put 'psn','1','cf:name','zhangsan'


hbase(main):015:0> put 'psn','1','name','zhangsan'
ERROR: org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException:
Column family name does not exist in region psn

删除表

删除表需要先禁用表才能删除:

disable 'psn'
dorp 'psn'

region

接下来我们去数据目录下,查看hbase表得存储目录。可以看到我们创建的列族在这一串乱码文件下。这个乱码就是region的Id。

e55342358c207c910f851dcaf110b623.webp

文件持久化

当我们插入一部分数据的时候,如果没有超过缓冲区的大小。我们就不会把数据持久化到硬盘。

8c9be353d13033ad2c93375a8076da25.webp96860e8691667bcd217ac60455588651.webp

此时我们可以通过如下命令,手动将数据刷新到磁盘:

flush 'psn'

会发现数据已经到了硬盘。

bdcb6b4214c74ddbe08d43a736b3fe9e.webp

此时我们可以通过命令来查看该文件中的数据,每个人后续生成的region和文件id都不太一样。

 hbase hfile -p -f file:///home/testuser/hbase/data/default/psn/cc5874c7dfbd07c30a5daaa59dbae4f9/cf/677b3478a3c845de876379fc7006b4f4

分布式集群

配置免密操作

node1和node4免密,如下所示:

ssh-keygen

ssh-copy-id -i .ssh/id_rsa.pub node1

配置hbase-env.sh

关闭hbase自身zookeeper实例。采用外部zookeeper集群。

3989c322c348f51a23bebbff87903ed3.webp

配置hbase-site.xml

写入自己的集群配置。

<property>
<name>hbase.rootdirname>
<value>hdfs://mycluster/hbase
property>
<property>
<name>hbase.cluster.distributedname>
<value>truevalue>
property>
<property>
<name>hbase.zookeeper.quorumname>
<value>node2,node3,node4value>
property>


配置regionservers

154e8194cf9eea1b3fc359bbbaddb051.webp

配置backup-masters

表示备份的master。

23799402d79e0941b35cafacec71be49.webp

HDFS配置

Procedure: HDFS Client Configuration
Of note, if you have made HDFS client configuration changes on your Hadoop cluster, such as configuration directives for HDFS clients, as opposed to server-side configurations, you must use one of the following methods to enable HBase to see and use these configuration changes:

1.Add a pointer to your HADOOP_CONF_DIR to the HBASE_CLASSPATH environment variable in hbase-env.sh.

2.Add a copy of hdfs-site.xml (or hadoop-site.xml) or, better, symlinks, under ${HBASE_HOME}/conf, or

3.if only a small set of HDFS client configurations, add them to hbase-site.xml.

我们选择第二种,将hadoop的hdfs-site.xml复制到hbase中进行配置。

 cp /opt/bigdata/hadoop-2.6.5/etc/hadoop/hdfs-site.xml ./

接下来将配置好的hbase复制到其他三个节点,并配置环境变量

scp -r hbase-2.0.5/ root@node4:/opt/bigdata/

启动Hbase集群

可以看到日志中,node1为master,node2,node3,node4为regionserver。node4也为master。

d726440376ef869c4bcf8c6ab091bd1f.webp

可以看到java进程中,node4节点多了一个HMaster,一个HRegionServer。

指定备用Master

同时我们可以指定备用Master,例如node3。使用如下命令:

hbase-daemon.sh start master


3c0efe57216236b3863fabd3622394a6.webp

启动集群shell

在任意节点启动集群shell。

hbase shell
84f55ccb2945a60678adda7669a0eef6.webp

同时在我们的hdfs文件系统中也看到了我们的hbase目录

8b8110ef231f3f308b232cf83a0446a1.webp


浏览 39
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报