设为首页 加入收藏

TOP

Hadoop 之 HBase安装与测试
2019-03-14 12:38:27 】 浏览:57
Tags:Hadoop HBase 安装 测试
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Wpixel/article/details/79269824

开发环境和工具

  1. MAC OS
  2. Parallels Desktop 12
  3. SecureCRT
  4. SecureFX

hadoop环境

  1. Centos7
  2. jdk-8u101-linux-x64
  3. Hadoop2.8.1
  4. zookeeper-3.4.10
  5. hbase-1.3.1-bin.tar.gz
hostname NameNode DataNode JournalNode Zookeeper (新增)HMaster (新增)HRegionServer
wpixel01
wpixel02
wpixel03
wpixel04

1 .安装配置Apache HBase

解压hbase-1.3.1-bin.tar.gz

[root@wpixel01 www]# tar -zxvf hbase-1.3.1-bin.tar.gz 

环境变量配置

[root@wpixel01 www]# vi /etc/profile
export HBASE_HOME=/home/www/hbase-1.3.1
export PATH=$PATH:$HBASE_HOME/bin

配置文件介绍

#配置文件在conf目录下
[root@wpixel01 www]# cd hbase-1.3.1/conf/
[root@wpixel01 conf]# ll
total 144
#只配置这三个文件
-rw-r--r--. 1 root root   7468 Feb  5 13:45 hbase-env.sh 环境配置
-rw-r--r--. 1 root root   1725 Feb  5 14:00 hbase-site.xml 核心配置
-rw-r--r--. 1 root root     31 Feb  5 13:55 regionservers 这个就像配置datanode一样

配置hbase-env.sh

[root@wpixel01 conf]# vi hbase-env.sh 
#修改jdk目录参数
export JAVA_HOME=/home/www/jdk1.8.0_101
#hbase自带zookeeper,我已经配置好zookeeper了,就不用hbase自带的zk,设置为false
export HBASE_MANAGES_ZK=false

配置hbase-site.xml

[root@wpixel01 conf]# vi hbase-site.xml 
 <!-- 这个目录不需要手动创建,项目启动后会自行创建,否则会做迁移操作,引发错误 -->
 <property>
  <value>hbase.rootdir</value>
  <name>hdfs://wpixel01:9000/hbase</name>
 </property>
 <!-- 设置zk客户端端口 -->
 <property>
  <name>hbase.zookeeper.property.clientPort</name>
  <value>2181</value>
 </property>
 <!-- zk环境的地址 -->
 <property>
  <name>hbase.zookeeper.quorum</name>
  <value>wpixel01,wpixel02,wpixel03</value>
 </property>
 <!-- 配置zk的数据目录,与hadoop ha公用,要与zoo.cfg中配置一致 -->
 <property>
  <name>hbase.zookeeper.proprety.dataDir</name>
  <value>/home/www/zookeeper-3.4.10/tmp</value>
 </property>
 <!-- 分布式集群配置为true,单节点为false-->
 <property>
  <name>hbase.cluster.distributed</name>
  <value>true</value>
 </property>
 <property>
  <name>hbase.master.maxclockskew</name>
  <value>180000</value>
 </property>
 <!-- 配置hadoop时配置的副本率为2,这里一致,否则默认是3,也可以将hadoop的hdfs-site.xml文件拷贝到hbase的conf目录下,效果相同 -->
 <property>
  <name>dfs.replication</name>
  <value>2</value>
 </property>
将HBase发送到wpixel02、wpixel03和wpixel04, 并配置环境变量
[root@wpixel01 www]# scp -r hbase-1.3.1/ root@wpixel02:/home/www/
[root@wpixel01 www]# scp -r hbase-1.3.1/ root@wpixel03:/home/www/
[root@wpixel01 www]# scp -r hbase-1.3.1/ root@wpixel04:/home/www/

2 .启动HBase

  • 启动zookeeper (略)
  • 启动hadoop(略)
  • 启动zkfc(略)
  • 启动HMaster
#在wpixel01上启动HMaster
[root@wpixel01 www]# hbase-daemon.sh start master
#一台HMaster是不安全的,实现HA
#在wpixel02和wpixel03上启动HMaster
[root@wpixel02 www]# hbase-daemon.sh start master
[root@wpixel03 www]# hbase-daemon.sh start master
  • 启动HRegionServer
#在wpixel02、wpixel03和wpixel04上启动HRegionServer
[root@wpixel02 ~]# hbase-daemon.sh start regionserver
[root@wpixel03 ~]# hbase-daemon.sh start regionserver
[root@wpixel04 ~]# hbase-daemon.sh start regionserver

3 .通过web和jps查看

web端通过端口16010查看,不是60000、60010了
HBaseWeb
通过jps查看
这里写图片描述

通过以上的步骤,hbase就搭建完成了

4 .测试使用HBase

既然搭建起来了,肯定是要用的
[root@wpixel01 hbase-1.3.1]# hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/www/hbase-1.3.1/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/www/hadoop-2.8.1/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 1.3.1, r930b9a55528fe45d8edce7af42fef2d35e77677a, Thu Apr  6 19:36:54 PDT 2017

hbase(main):001:0> 
噢耶,顺利进入hbase交互命令行界面
查看节点状态
hbase(main):001:0> status
1 active master, 2 backup masters, 3 servers, 0 dead, 0.6667 average load
#1个active状态的master节点
#2个standby状态的master节点
#3台regionServer
创建表:create ‘表名’,’列族名字’
#1. 创建users表,列族info,grade
hbase(main):001:0> create 'users','info','grade'
0 row(s) in 2.8720 seconds
=> Hbase::Table - users

#2. 这里查看users表结构,详细解析
#describe 'users'或者desc 'users'
hbase(main):008:0> describe 'users' 
#状态是ENABLED,不能删除表
Table users is ENABLED                                                                                            
users                          
#这里是列族                                                                      
COLUMN FAMILIES DESCRIPTION   
#grade列:NAME(列族名称),VERSIONS(每个单元格上可以保存的数据个数), IN_MEMORY(是否将数据缓存到内存),COMPRESSION(压缩)                                                                                    
{NAME => 'grade', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS =>
 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0
', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}        
#info列族              
{NAME => 'info', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 
'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0'
, BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                             
2 row(s) in 0.0520 seconds
插入数据:put ‘表名’,’rowkey’,’列族:名’,’值’
#put '表名','主键','列族:名','值'
hbase(main):020:0> put 'users','w01','info:name','wpixel'
0 row(s) in 0.3110 seconds
hbase(main):022:0> put 'users','w01','info:age','18'
0 row(s) in 0.0210 seconds

有人发现两条插入的主键同为w01,
如果是关系型数据库(mysql,oracle)会将key相同的当做修改操作,最终为1条数据
hbase作为NoSql数据库,这里插入两次就是两条数据
效果如下(将就着看吧)

rowkey(行键) info(name) info(age) grade
w01 wpixel
w01 18
查询:scan ‘表名’ 和 get ‘表名’,’rowkey’
#scan操作,相当于  select * from users;
hbase(main):024:0> scan 'users'
ROW                        COLUMN+CELL                                                              
 w01                       column=info:age, timestamp=1517903123893, value=18                       
 w01                       column=info:name, timestamp=1517902873487, value=wpixel                  
1 row(s) in 0.1360 seconds

#get操作,相当于: select * from users where rowkey = 
hbase(main):026:0> get 'users','w01'
COLUMN                     CELL                                                                     
 info:age                  timestamp=1517903123893, value=18                                        
 info:name                 timestamp=1517902873487, value=wpixel                                    
1 row(s) in 0.2280 seconds
清空表中的数据 truncate ‘表名’

truncate ‘users’ —> 本质:先删除表,再重建

#清空表数据
hbase(main):027:0> truncate 'users'
Truncating 'users' table (it may take a while):
 - Disabling table...
 - Truncating table...
0 row(s) in 4.2540 seconds

#现在查看表数据
hbase(main):028:0> scan 'users'
ROW                        COLUMN+CELL                                                              
0 row(s) in 0.2070 seconds
╮(╯_╰)╭ 没了
删除表 drop ‘users’
hbase(main):029:0> drop 'users'

ERROR: Table users is enabled. Disable it first.

Here is some help for this command:
Drop the named table. Table must first be disabled:
  hbase> drop 't1'
  hbase> drop 'ns1:t1'

why!!! 怎么删不掉啊,百度一下
………………………………
哦,嗖嘎
在创建表的时候我有说过,状态是ENABLED,是不能删除表的
既然找到原因了,那就将表的状态改一改

#修改users表的状态,让表失效
hbase(main):030:0> disable 'users'
#查看users表的状态
hbase(main):031:0> desc 'users'
Table users is DISABLED   
...

#现在表的状态是disabled,可以删除表了,再试一遍
hbase(main):032:0> drop 'users'
0 row(s) in 1.2700 seconds

#OK,已删除 ,list命令查看表集合
hbase(main):033:0> list
TABLE                                                                                               
0 row(s) in 0.0330 seconds

=> []
退出HBase命令行
hbase(main):034:0> quit

5 .总结

nosql非常关注对数据高并发地读写和对海量数据的存储等,与关系型数据库相比,在架构和数据模型方量面做了“减法”,而在扩展和并发等方面做了“加法”。

所以nosql数据库是通过增加冗余度来提高效率

^_^

THE END

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Hadoop发行版的比较与选择 下一篇解决hadoop在上传文件的时候连接..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目