hbase安装与使用

hbase架构

环境准备

  • 安装jdk1.8,配置/etc/profile下JAVA_HOME环境变量

  • 安装并启动伪分布式模式hadoop,版本为hadoop-3.1.2,安装到/opt/hadoop-3.1.2目录,启动hdfs,mapreduce,yarn组件

安装

hbase版本和hadoop版本有兼容问题

参考http://hbase.apache.org/book.html#_introduction

这里4.1章节列出了可用的版本关系

由于之前使用的hadoop是最新3.1.2版本,所有下载官方hbase-2.2.0-SNAPSHOT-bin.tar.gz到/opt目录下,解压到/opt/hbase-2.2.0目录下

配置hbase

  1. 修改hbase-site.xml
<configuration>
    <property>
        <name>hbase.rootdir</name>
        <value>hdfs://localhost:9000/hbase</value>
    </property>
    <property>
        <name>hbase.cluster.distributed</name>
        <value>true</value>
    </property>
	 <property>
    <name>hbase.unsafe.stream.capability.enforce</name>
	//设置不检查
    <value>false</value>
    <description>
      Controls whether HBase will check for stream capabilities (hflush/hsync).

      Disable this if you intend to run on LocalFileSystem, denoted by a rootdir
      with the 'file://' scheme, but be mindful of the NOTE below.

      WARNING: Setting this to false blinds you to potential data loss and
      inconsistent system state in the event of process and/or node failures. If
      HBase is complaining of an inability to use hsync or hflush it's most
      likely not a false positive.
    </description>
  </property>
  <property>
      <name>hbase.zookeeper.property.clientPort</name>
      <value>2181</value>
      <description>Property from ZooKeeper's config zoo.cfg.
      The port at which the clients will connect.
      </description>
    </property>
    <property>
      <name>hbase.zookeeper.quorum</name>
      <value>localhost</value>
      <description>Comma separated list of servers in the ZooKeeper Quorum.
      For example, "host1.mydomain.com,host2.mydomain.com,host3.mydomain.com".
      By default this is set to localhost for local and pseudo-distributed modes
      of operation. For a fully-distributed setup, this should be set to a full
      list of ZooKeeper quorum servers. If HBASE_MANAGES_ZK is set in hbase-env.sh
      this is the list of servers which we will start/stop ZooKeeper on.
      </description>
    </property>
    <property>
      <name>hbase.zookeeper.property.dataDir</name>
	  //此处需要设置第三方zookeeper的读写权限 如chmod 777 /opt/hbase-2.2.0/zookeeper
      <value>/opt/hbase-2.2.0/zookeeper</value>
      <description>Property from ZooKeeper's config zoo.cfg.
      The directory where the snapshot is stored.
      </description>
    </property>
</configuration>

hbase.rootdir:该参数制定了HReion服务器的位置,即数据存放的位置。主要端口号要和Hadoop相应配置一致。 hbase.cluster.distributed:HBase的运行模式。false是单机模式,true是分布式模式。若为false, HBase和Zookeeper会运行在同一个JVM里面。默认为false. hbase.unsafe.stream.capability.enforce不设置的话,会导致hmaster启动失败,报错信息: java.lang.IllegalStateException: The procedure WAL relies on the ability to hsync for proper operation during component failures, but the underlying filesystem does not support doing so. Please check the config value of 'hbase.procedure.store.wal.use.hsync' to set the desired level of robustness and ensure the config value of 'hbase.wal.dir' points to a FileSystem mount that can provide it.

  1. 设置环境变量

修改HBase下的conf目录中的hbase-env.sh文件

export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export HBASE_MANAGES_ZK=false
export HBASE_PID_DIR=/opt/hbase-2.2.0/pids

export HBASE_MANAGES_ZK=false 此配置信息,表示设置不由hbase自己管理zookeeper,使用单独的zookeeper, 如果Hbase用的是自带的 zookeeper,设置为true,注意该配置信息默认为true,若想使用单独的zookeeper,则需去掉‘#’并将该值设置为false.,HBASE_PID_DIR如果不修改,会提示hadoo用户没有写入权限(默认pid文件在/tmp目录下,改为有hadoop用户权限的文件即可,权限问题可以直接通过chmod修改文件权限)

  1. 配置/etc/profile

加入hbase环境变量

# set hbase path
export HBASE_HOME=/opt/hbase-2.2.0
export PATH=$PATH:$HBASE_HOME/bin

故障解决

  1. error: KeeperErrorCode = NoNode for /hbase/master

此问题是HMaster服务没有注册到zookeeper的原因,查看hbase-hadoop-master-SZV-BZ1-IRDM4.BOOZHONG.COM.log最后一行是什么错误。 如果你配置的zookeeper.znode.parent =/hbase的话在zookeeper的HMaster路径格式必须是/hbase/master开头

在hbase的shell下输入status

解决办法:

  • zoo.cfg里的data目录是配置在/tmp下的,更改该目录,我的设置为/opt/hbase-2.2.0/zookeeper,设置此文件权限能被zookeeper用户读写。重新启动zookeeper。

  • 删除zookeeper下/hbase目录,即rmr /hbase,然后重启hbase

  1. java.lang.IllegalStateException: The procedure WAL relies on the ability to hsync for proper operation during component failures, but the underlying filesystem does not support doing so. Please check the config value of 'hbase.procedure.store.wal.use.hsync' to set the desired level of robustness and ensure the config value of 'hbase.wal.dir' points to a FileSystem mount that can provide it.

解决办法:

修改hbase-site.xml

<property>
	<name>hbase.unsafe.stream.capability.enforce</name>
	<value>false</value>
</property>

测试hbase

  1. 进入shell环境

进入hbase的bin目录

  1. shell命令
  • 创建表
create 't','f1'
或
create 't1', {NAME => 'f1', VERSIONS => 1}, {NAME => 'f2', VERSIONS => 1}, {NAME => 'f3', VERSIONS => 1}
  • 修改表
disable 't'
alter 't',{NAME=>'f2'}
enable 't'
  • 删除表
disable 't'
drop 't'
  • 插入数据
put 't','row1','f1:x','1'
  • 查看表结构
list
scan 't'
describe 't'
existes 't'
  • 查看表数据
get 't','row1'

转载于:https://my.oschina.net/odetteisgorgeous/blog/3072807

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值