设为首页 加入收藏

TOP

CentOS 6下HBase安装与使用
2018-11-28 17:31:40 】 浏览:168
Tags:CentOS HBase 安装 使用

http://www.phperz.com/article/14/1018/29709.html

HBase是一个分布式的、面向列的开源数据库,该技术来源于 Fay Chang 所撰写的Google论文“Bigtable:一个结构化数据的分布式存储系统”。就像Bigtable利用了Google文件系统(File System)所提供的分布式数据存储一样,HBase在Hadoop之上提供了类似于Bigtable的能力。HBase是Apache的Hadoop项目的子项目。HBase不同于一般的关系数据库,它是一个适合于非结构化数据存储的数据库。另一个不同的是HBase基于列的而不是基于行的模式。

Linux环境:CentOS6.5

HBase版本:hbase-0.94.16

HBase官网:http://hbase.apache.org

1.下载解压安装文件

# wget http://mirror.bit.edu.cn/apache/hbase/stable/hbase-0.94.16.tar.gz

# tar xvfz hbase-0.94.16.tar.gz

2.启动HBase

# /usr/hbase-0.94.16/bin/start-hbase.sh

如果报错

+======================================================================+
| Error: JAVA_HOME is not set and Java could not be found |
+----------------------------------------------------------------------+
| Please download the latest Sun JDK from the Sun Java web site |
| > http://java.sun.com/javase/downloads/ < |
| |
| Hadoop requires Java 1.6 or later. |
| NOTE: This script will find Sun Java whether you install using the |
| binary or the RPM based installer. |
+======================================================================+

如图所示

需要修改HBase的配置文件,配置文件在conf文件夹下
# vi conf/hbase-env.sh

增加JDK的位置,以本机为例JDK被放在/usr/lib/jdk下

  1. exportJAVA_HOME=/usr/lib/jdk/jdk1.7.0_51/


需要说明的是,JDK是要自己安装的,如果系统已经自带JDK是需要删除重新自己安装比较好。

关于JDK的卸载与安装可以参考这里:

Linux环境安装卸载JDK

不然修改配置文件启动还是没用的!

重新启动HBase

# /usr/hbase-0.94.16/bin/start-hbase.sh

如果成功启动会有如下提示信息:

  1. startingmaster,loggingto/usr/hbase-0.94.16/bin/../logs/hbase-root-master-localhost.localdomain.out

3.查看管理界面

运行在端口http://localhost:60010

这样就可以使用HBase了。

4.使用HBase Shell命令行

可以通过HBase Shell和HBase交互

# /usr/hbase-0.94.16/bin/hbase

# /usr/hbase-0.94.16/bin/hbase shell

这说明Java和HBase函数库已经安装成功,列出HBase中的所有表可以使用list命令。

建表

输入数据

scan可以扫描全表

5.HBase常用命令以及建表

复杂的表

建表命令

create 'GDP','city','code','count'
put 'GDP','SH','code:','021'
put 'GDP','BJ','code:','010'
put 'GDP','GZ','code:','020'
put 'GDP','SH','count:pop','2500'
put 'GDP','SH','count:area','6340'
put 'GDP','SH','count:gdp','20100'
put 'GDP','BJ','count:pop','2100'
put 'GDP','BJ','count:area','16410'
put 'GDP','BJ','count:gdp','19500'
put 'GDP','GZ','count:pop','1275'
put 'GDP','GZ','count:area','7434'
put 'GDP','GZ','count:gdp','13500'

分别查出所有信息和SH的信息。

6.使用REST访问HBase

启动REST服务

# /usr/hbase-0.94.16/bin/hbase rest

启动REST服务,监听9999端口

# /usr/hbase-0.94.16/bin/hbase rest start -p 9999

在浏览器以及可以访问HBase的REST了

http://localhost:9999/

http://localhost:9999/version

使用curl访问HBase的REST

# curl -H "Accept: application/json" http://192.168.2.111:9999/GDP/SH/

访问“SH”的数据

# curl -H "Accept: application/json" http://192.168.2.111:9999/GDP/SH/

# curl -H "Accept: application/json" http://192.168.2.111:9999/GDP/SH/count:area

注意输出是JSON格式数据,以Base64编码字符串形式返回的,我们可以验证其中的:

MDIx解码就是021

MDEw解码就是010

就是之前录入的上海和北京的区号。

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Hbase总结(四)- Hbase与传统数.. 下一篇Hbase 日常运维

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目