这一次来部署一个单机版的 Hbase, 单独的 Hbase daemon(Master,RegionServers 和 ZooKeeper) 运行在同一个 JVM 进程中, 然后持久化存储到文件系统中. 这是最简单的部署, 但是却能帮助我们更好的理解 Hbase. 安装完成之后, 我们在演示一下 hbase 命令行的用法.
image
环境
- CentOS 7
- Hbase 1.2.8
安装单机
确保安装了 jdk, 在 Linux 上使用自带的包管理器直接安装就好, 使用二进制也是一个不错的选择, 我用的是 CentOS
yum install java-1.8.0-openjdk* -y
下载 Hbase 的二进制包, 下载地址位于 http://mirror.bit.edu.cn/apache/hbase/hbase-1.2.8/ , 然后解压到系统的目录.
- tar -xf hbase-1.2.8-bin.tar.gz
- cd hbase-1.2.8
配置 hbase 的环境变量, 修改 JAVA_HOME. 注意看下自己的 JAVA_HOME 在什么位置
image
- VIM conf/hbase-env.sh
- // 注意这个是在 CentOS 上的 java 位置
- export JAVA_HOME=/etc/alternatives/java_sdk_1.8.0/
配置 onf/hbase-site.xml, 这个是 Hbase 的主配置文件, 你可以指定 hbase 和 ZooKeeper 数据写入的目录, 当然也可以指定 hbase 的根目录在哪个位置.
我将 hbase 的目录放在 hadoop 用户家目录的 hbase 目录下. 我们不用事先创建好 hbase 的 data 目录, hbase 会自动帮我们创建好的, 如果已经存在了 data 目录, hbase 会将存在的目录进行迁移.
- useradd -s /sbin/nologin -m hadoop
- VIM conf/hbase-site.xml
- <configuration>
- <property>
- <name>hbase.rootdir</name>
- <value>file:///home/hadoop/hbase</value>
- </property>
- <property>
- <name>hbase.zookeeper.property.dataDir</name>
- <value>/home/hadoop/zookeeper</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>
- </configuration>
Hbase 二进制包下有 start-hbase 脚本, 可以方便的启动 hbase, 如果我们的配置是正确的, 那么会正常启动.
./bin/start-hbase.sh
image
如果启动之后, 可以打开 http://localhost:16010/ 查看 Hbase 的 web UI
image
使用 Hbase
我们可以先用 Hbase 提供的命令行工具, 位于 hbase 的 / bin / 目录下
连接 Hbase
./hbase shell
查看帮助信息, 敲
>help
image
创建一个表, 必须要指定表名称和列簇名
- hbase(main):003:0> create 'test', 'cf'
- 0 row(s) in 1.6320 seconds
- => Hbase::Table - test
image
列出关于你的表的信息, list 'sometable'
image
查看表更为详细的信息, 使用 describe 命令
image
把数据放到表中
image
查看表中的所有数据
image
获取单行的数据
image
其余的命令可以自行尝试
退出 shell, 使用 quit
最后
这里演示了下单机版的 hbase 如何安装, 了解 hbase shell 的基本用法, 关于 Hbase 更深入的东西, 可以了解下官方文档.
来源: http://www.jianshu.com/p/a2b9cf968029