Hbase
一、安装Hbase
在两台虚拟机Master和Slave1上安装Hbase
所需条件:Hadoop和Zookeeper集群安装完成
Root用户下操作
1、解压安装
将hbase-1.1.2-bin.tar.gz拿U盘复制到/home/hadoop目录下
在/home/hadoop目录下,解压安装
tar -zxvf hbase-1.1.2-bin.tar.gz -C/usr/local
软件下载地址:
http://www.apache.org/dyn/closer.cgi/hbase/
二、配置Hbase
1、修改conf/hbase-env.sh
进行以下修改:
exportJAVA_HOME=/usr/local/java/jdk1.8.0_65
exportHBASE_LOG_DIR=/usr/local/hbase-1.1.2/logs
export HBASE_MANAGES_ZK=true(目的是打开zookeeper管理)
2、修改conf/hbase-site.sh
内容修改如下:
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://Master:9000/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.master</name>
<value>Master:60000</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>Master,Slave1</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/usr/local/zookeeper/zkdata</value>
</property>
</configuration>
备注:
hbase.rootdir 设置hbase在hdfs上的目录,主机名为hdfs的namenode节点所在的主机
hbase.cluster.distributed 设置为true,表明是完全分布式的hbase集群
hbase.master 设置hbase的master主机名和端口
hbase.zookeeper.quorum 设置zookeeper的主机,建议使用单数
hbase.zookeeper.property.dataDir 设置zookeeper的数据路径
hbase-1.1.2目录下,建立logs文件
mkdir logs
3、修改regionservers
将内容修改为:
Slave1
即Slave的名字
4、修改Hadoop hdfs-site.xml
注意其它的datanode也要进行修改
修改内容如下:
<property>
<name>dfs.datanode.max.xcievers</name>
<value>4096</value>
</property>
原因:
该参数限制了datanode所允许同时执行的发送和接受任务的数量,缺省为256,hadoop-defaults.xml中通常不设置这个参数。这个限制看来实际有些偏小,高负载下,DFSClient在put数据的时候会报could not read from stream的Exception
5、拷贝到其它主机
scp -r /usr/local/ hbase-1.1.2 Slave1:/usr/local
6、修改权限
在Master和Slave1上操作
chown -R hadoop:hadoop hbase-1.1.2
三、运行Hbase
1、启动
bin/hbase-1.1.2
2、脚本操作
启动
bin/hbase shell
用list命令来看一下hbase中有哪些表
list
创建一张表
create 'user_info','name'
往表中插入一条数据
put 'user_info','1','name:','Tom'
查询是否表中存在数据
scan 'user_info'
删除hbase表时,需要先disable '表名称',然后在drop '表名称'
disable 'user_info'
drop 'user_info'
退出
exit
操作过程:
[hadoop@Master bin]$ ./start-hbase.sh
Slave1: starting zookeeper, logging to /usr/local/hbase-1.1.2/logs/hbase-hadoop-zookeeper-Slave1.out
Master: starting zookeeper, logging to /usr/local/hbase-1.1.2/logs/hbase-hadoop-zookeeper-Master.out
starting master, logging to /usr/local/hbase-1.1.2/logs/hbase-hadoop-master-Master.out
Slave1: starting regionserver, logging to /usr/local/hbase-1.1.2/logs/hbase-hadoop-regionserver-Slave1.out
Slave1: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Slave1: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
[hadoop@Master bin]$ ./hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hbase-1.1.2/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.5.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]
2016-01-25 23:06:21,475 WARN [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 1.1.2, rcc2b70cf03e3378800661ec5cab11eb43fafe0fc, Wed Aug 26 20:11:27 PDT 2015
hbase(main):001:0> list
TABLE
0 row(s) in 7.8750 seconds
=> []
hbase(main):002:0> create 'user_info','name'
0 row(s) in 8.5030 seconds
=> Hbase::Table - user_info
hbase(main):003:0> put 'user_info','1','name:','Tom'
0 row(s) in 2.0010 seconds
hbase(main):004:0> scan 'user_info'
ROW COLUMN+CELL
1 column=name:, timestamp=1453792722909, value=Tom
1 row(s) in 0.3710 seconds
hbase(main):005:0> list
TABLE
user_info
1 row(s) in 0.0730 seconds
=> ["user_info"]
hbase(main):006:0> drop 'user_info'
ERROR: Table user_info 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'
hbase(main):007:0> list
TABLE
user_info
1 row(s) in 0.0360 seconds
=> ["user_info"]
hbase(main):008:0> disable 'user_info'
0 row(s) in 2.6240 seconds
hbase(main):009:0> drop 'user_info'
0 row(s) in 2.8240 seconds
hbase(main):010:0> list
TABLE
0 row(s) in 0.0230 seconds
=> []
hbase(main):011:0> exit
[hadoop@Master bin]$