安装配置HBase

本文详细描述了如何在HBase集群环境中安装、配置和管理HBase,包括环境变量设置、配置文件修改、数据表操作以及分布式环境的配置。
摘要由CSDN通过智能技术生成

HBase集群需要整个集群所有节点安装的HBase版本保持一致,并且拥有相同的配置,具体配置步骤如下:

1. 解压缩HBase的压缩包

2. 配置HBase的环境变量

3. 修改HBase的配置文件,HBase的配置文件存放在HBase安装目录下的conf中

4. 首先在一台节点对整个HBase集群进行配置,再将此节点的配置发送到集群的其它节点上。

5. 具体需要修改的HBase的配置文件包括 hbase-site.xml、hbase-env.sh、regionservers、backup-masters、

HBase版本选择

安装HBase(在node1上安装配置HBase,然后再使用【scp】命令分发到其他节点)

  • 项目中使用的HBase安装包,已经存放在/opt/software目录下,直接解压使用即可:
[root@node1 ~]# tar -xzf /opt/software/hbase.tar.gz -C /opt/module/
  • 通过【vi】命令编辑/etc/profile文件
[root@node1 ~]# vi /etc/profile
  • 设置HBase环境变量,在/etc/profile 文件的末尾添加如下内容:
export HBASE_HOME=/opt/module/hbase
export PATH=$PATH:$HBASE_HOME/bin

  • 使用【scp】将环境变量分发至其它节点
[root@node1 ~]# scp -rq /etc/profile node2:/etc/
[root@node1 ~]# scp -rq /etc/profile node3:/etc/

解释

部分参数说明: -p:保留原文件的修改时间,访问时间和访问权限。 -q: 不显示传输进度条。 -r: 递归复制整个目录。 所以,如果使用scp命令只复制单个文件,可以不添加-rq参数。

  • 使用【source】命令,使配置文件生效
[root@node1 ~]# source  /etc/profile

配置HBase

  • 配置hbase-env.sh文件
[root@node1 ~]# cd $HBASE_HOME/conf
[root@node1 ~]# vi hbase-env.sh

在文件末尾添加如下配置:

export JAVA_HOME=/opt/module/jdk1.8.0_301/
export HBASE_MANAGES_ZK=false

  • 配置 hbase-site.xml文件,该文件存放在$HBASE_HOME/conf目录下
[root@node1 conf]# vi hbase-site.xml

在<configuration>和</configuration>之间配置内容如下:

<property>
	<name>hbase.rootdir</name>
	<value>hdfs://node1:9000/hbase</value>
</property>
<property>
	<name>hbase.unsafe.stream.capability.enforce</name>
	<value>false</value>
</property>
<property>
	<name>hbase.cluster.distributed</name>
	<value>true</value>
</property>
<property>
	<name>hbase.zookeeper.quorum</name>
	<value>node1:2181,node2:2181,node3:2181</value>
</property>

配置完成后完整内容如下:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
/**
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-->
<configuration>
	<property>
		<name>hbase.rootdir</name>
		<value>hdfs://node1:9000/hbase</value>
	</property>
	<property>
		<name>hbase.unsafe.stream.capability.enforce</name>
		<value>false</value>
	</property>
	<property>
		<name>hbase.cluster.distributed</name>
		<value>true</value>
	</property>
	<property>
		<name>hbase.zookeeper.quorum</name>
		<value>node1:2181,node2:2181,node3:2181</value>
	</property>
</configuration>

配置regionservers文件

[root@node1 conf]# vi regionservers

配置内容如下:

node1
node2
node3
  • 将Hadoop的配置文件拷贝到HBase的conf目录
[root@node1 conf]# cp $HADOOP_HOME/etc/hadoop/core-site.xml $HBASE_HOME/conf/
[root@node1 conf]# cp $HADOOP_HOME/etc/hadoop/hdfs-site.xml $HBASE_HOME/conf/
  • 将node1的HBase分发至整个集群的其他节点:
[root@node1 ~]# cd /opt/module/
[root@node1 module]# scp -rq hbase node2:/opt/module/
[root@node1 module]# scp -rq hbase node3:/opt/module/

启动集群并测试

  • 在node1上启动HBase集群并,并在client节点上通过浏览器访问 http://node1:16010 查看HBase的Web监控页面
[root@node1 ~]# start-hbase.sh

  • 新建一个名为test的表,使其只包含一个名为data的列,表和列族属性都为默认值
[root@node1 ~]# hbase shell
hbase(main):001:0> create 'test','data'
0 row(s) in 0.4150 seconds

  • 通过键入help查看帮助命令,运行list查看新建的表是否存在

解释

hbase(main):003:0> list TABLE test 1 row(s) in 0.0230 seconds

  • 在列族data中二个不同的行和列上插入数据,然后列出表内容
hbase(main):004:0> put 'test','row1','data:1','values1'
0 row(s) in 0.1280 seconds
hbase(main):005:0> put 'test','row2','data:2','values2'
0 row(s) in 0.0090 seconds
hbase(main):006:0> scan 'test'
ROW COLUMN+CELL
row1 column=data:1, timestamp=1473585137461, value=values1
row2 column=data:2, timestamp=1473585158072, value=values2
2 row(s) in 0.0200 seconds
  • 删除刚创建的表test,需要先设为禁用,然后删除,不设置会报错:
hbase(main):008:0> drop 'test'
ERROR: Table test is enabled. Disable it first.
hbase(main):009:0> disable 'test'
0 row(s) in 1.1800 seconds
hbase(main):010:0> drop 'test'
0 row(s) in 0.1570 seconds

  • 查看一下,是否删除成功

  • 输入【quit】命令,即可退出Base Shell命令行模式
hbase(main):007:0> quit()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值