开发环境和工具
MAC OS
Parallels Desktop 12
SecureCRT
SecureFX
hadoop环境
Centos7
jdk-8u101-linux-x64
Hadoop2.8.1
zookeeper-3.4.10
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]
环境变量配置
[root@wpixel01 www]
export HBASE_HOME=/home/www/hbase-1.3 .1
export PATH=$PATH :$HBASE_HOME /bin
配置文件介绍
[root@wpixel01 www]
[root@wpixel01 conf]
total 144
-rw-r
-rw-r
-rw-r
配置hbase-env.sh
[root@wpixel01 conf]
export JAVA_HOME=/home/www/jdk1.8 .0 _101
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 >
<property >
<name > hbase.zookeeper.property.clientPort</name >
<value > 2181</value >
</property >
<property >
<name > hbase.zookeeper.quorum</name >
<value > wpixel01,wpixel02,wpixel03</value >
</property >
<property >
<name > hbase.zookeeper.proprety.dataDir</name >
<value > /home/www/zookeeper-3.4.10/tmp</value >
</property >
<property >
<name > hbase.cluster.distributed</name >
<value > true</value >
</property >
<property >
<name > hbase.master.maxclockskew</name >
<value > 180000</value >
</property >
<property >
<name > dfs.replication</name >
<value > 2</value >
</property >
将HBase发送到wpixel02、wpixel03和wpixel04, 并配置环境变量
[root@wpixel01 www]
[root@wpixel01 www]
[root@wpixel01 www]
2 .启动HBase
启动zookeeper (略)
启动hadoop(略)
启动zkfc(略)
启动HMaster
[root@wpixel01 www]
[root@wpixel02 www]
[root@wpixel03 www]
[root@wpixel02 ~]
[root@wpixel03 ~]
[root@wpixel04 ~]
3 .通过web和jps查看
web端通过端口16010查看,不是60000、60010了
通过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.slf 4j.org /codes.html #multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf 4j.impl .Log 4jLoggerFactory]
HBase Shell
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 ‘表名’,’列族名字’
hbase(main):001 :0 > create 'users' ,'info' ,'grade'
0 row(s) in 2.8720 seconds
=> Hbase ::Table - users
hbase(main):008 :0 > describe 'users'
Table users is ENABLED
users
COLUMN FAMILIES DESCRIPTION
{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' }
{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’,’列族:名’,’值’
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’
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
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,是不能删除表的
既然找到原因了,那就将表的状态改一改
hbase(main):030 :0 > disable 'users'
hbase(main):031 :0 > desc 'users'
Table users is DISABLED
...
hbase(main):032 :0 > drop 'users'
0 row(s) in 1.2700 seconds
hbase(main):033 :0 > list
TABLE
0 row(s) in 0.0330 seconds
=> []
退出HBase命令行
hbase (main ):034 :0 > quit
5 .总结
nosql非常关注对数据高并发地读写和对海量数据的存储等,与关系型数据库相比,在架构和数据模型方量面做了“减法”,而在扩展和并发等方面做了“加法”。
所以nosql数据库是通过增加冗余度来提高效率
^_^
THE END