
搭建完《hadoop伪分布式平台》后就开始搭建hbase伪分布式平台了。有了hadoop环境,搭建hbase就变得很容易了。
一、Hbase安装
1、从官网下载最新版本Hbase安装包1.2.3,为了省去编译安装环节,我直接下载了hbase-1.2.3-bin.tar.gz,解压即可使用。(如果此链接下载速度过慢可更换官网其他下载链接)
[hadoop@master tar]$ tar -xzf hbase-1.2.-bin.tar.gz
[hadoop@master tar]$ mv hbase-1.2. /usr/local/hadoop/hbase
[hadoop@master tar]$ cd /usr/local/hadoop/hbase/
[hadoop@master hbase]$ ./bin/hbase version
HBase 1.2.
Source code repository git://kalashnikov.att.net/Users/stack/checkouts/hbase.git.commit revision=bd63744624a26dc3350137b564fe746df7a721a4
Compiled by stack on Mon Aug :: PDT
From source with checksum 0ca49367ef6c3a680888bbc4f1485d18
运行上面命令得到正常输出即表示安装成功,然后配置环境变量
2、配置环境变量
修改~/.bashrc在PATH后面增加
:$HADOOP_HOME/hbase/bin
则~/.bashrc文件内容如下
export HADOOP_HOME=/usr/local/hadoop
export HADOOP_INSTALL=$HADOOP_HOME
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export YARN_HOME=$HADOOP_HOME
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export PATH=$PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin:$HADOOP_HOME/hbase/bin
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
[hadoop@master hadoop]$ source ~/.bashrc
二、Hbase单机模式
1、修改配置文件 hbase/conf/hbase-env.sh
# export JAVA_HOME=/usr/java/jdk1.6.0/ 修改为
export JAVA_HOME=/usr/local/java/ #export HBASE_MANAGES_ZK=true 修改为
export HBASE_MANAGES_ZK=true # 添加下面一行
export HBASE_SSH_OPTS="-p 322"
2、修改配置文件 hbase/conf/hbase-site.xml
<configuration>
<property>
<name>hbase.rootdir</name>
<value>file:/usr/local/hadoop/tmp/hbase/hbase-tmp</value>
</property>
</configuration>
3、启动 Hbase
[hadoop@master hbase]$ start-hbase.sh
starting master, logging to /usr/local/hadoop/hbase/bin/../logs/hbase-hadoop-master-master.out
Java HotSpot(TM) -Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) -Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
jps下多了一个HMaster进程
[hadoop@master hbase]$ jps
ResourceManager
NameNode
Jps
SecondaryNameNode
NodeManager
DataNode
HMaster
4、使用Hbase shell
[hadoop@master hbase]$ hbase shell
-- ::, WARN [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hadoop/hbase/lib/slf4j-log4j12-1.7..jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7..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.2., rbd63744624a26dc3350137b564fe746df7a721a4, Mon Aug :: PDT hbase(main)::> status
active master, backup masters, servers, dead, 2.0000 average load hbase(main)::> exit
未启动Hbase直接使用Hbase Shell会报错
5、停止Hbase
[hadoop@master hbase]$ stop-hbase.sh
stopping hbase......................
三、Hbase伪分布式
伪分布式和单机模式的区别主要是配置文件的不同
1、修改配置文件 hbase/conf/hbase-env.sh
# export JAVA_HOME=/usr/java/jdk1.6.0/ 修改为
export JAVA_HOME=/usr/local/java/ # export HBASE_MANAGES_ZK=true 修改为
export HBASE_MANAGES_ZK=true # export HBASE_CLASSPATH= 修改为
export HBASE_CLASSPATH=/usr/local/hadoop/etc/hadoop/ # 添加下面一行
export HBASE_SSH_OPTS="-p 322"
zookeeper使用Hbase自带的即可,分布式才有必要开启独立的
2、修改配置文件 hbase/conf/hbase-site.xml
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://10.1.2.108:9000/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
</configuration>
注意这里的hbase.rootdir设置为hdfs的存储路径前提是hadoop平台是伪分布式,只有一个NameNode
3、启动Hbase
[hadoop@master hbase]$ start-hbase.sh
localhost: starting zookeeper, logging to /usr/local/hadoop/hbase/bin/../logs/hbase-hadoop-zookeeper-master.out
master running as process . Stop it first.
starting regionserver, logging to /usr/local/hadoop/hbase/bin/../logs/hbase-hadoop--regionserver-master.out
jps查看进程多了 HMaster和 HRegionServer
[hadoop@master hbase]$ jps
Jps
ResourceManager
NameNode
SecondaryNameNode
NodeManager
DataNode
HMaster
HRegionServer
4、使用Hbase Shell
[hadoop@master hbase]$ hbase shell
-- ::, WARN [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hadoop/hbase/lib/slf4j-log4j12-1.7..jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7..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.2., rbd63744624a26dc3350137b564fe746df7a721a4, Mon Aug :: PDT
1) 查看集群状态和版本信息
hbase(main)::> status
active master, backup masters, servers, dead, 1.0000 average load hbase(main)::> version
1.2., rbd63744624a26dc3350137b564fe746df7a721a4, Mon Aug :: PDT
2) 创建user表和三个列族
hbase(main)::> create 'user','user_id','address','info'
row(s) in 2.3570 seconds => Hbase::Table - user
3) 查看所有表
hbase(main)::> create 'tmp', 't1', 't2'
row(s) in 1.2320 seconds => Hbase::Table - tmp
hbase(main)::> list
TABLE
tmp
user
row(s) in 0.0100 seconds => ["tmp", "user"]
hbase(main)::>
4) 查看表结构
hbase(main)::> describe 'user'
Table user is ENABLED
user
COLUMN FAMILIES DESCRIPTION
{NAME => 'address', BLOOMFILTER => 'ROW', VERSIONS => '', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_V
ERSIONS => '', BLOCKCACHE => 'true', BLOCKSIZE => '', REPLICATION_SCOPE => ''}
{NAME => 'info', BLOOMFILTER => 'ROW', VERSIONS => '', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERS
IONS => '', BLOCKCACHE => 'true', BLOCKSIZE => '', REPLICATION_SCOPE => ''}
{NAME => 'user_id', BLOOMFILTER => 'ROW', VERSIONS => '', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_V
ERSIONS => '', BLOCKCACHE => 'true', BLOCKSIZE => '', REPLICATION_SCOPE => ''}
row(s) in 0.2060 seconds hbase(main)::>
5) 删除表
hbase(main)::> disable 'tmp'
row(s) in 2.2580 seconds hbase(main)::> drop 'tmp'
row(s) in 1.2560 seconds hbase(main)::>
5、停止Hbase
[hadoop@master hbase]$ stop-hbase.sh
stopping hbase......................
localhost: no zookeeper to stop because no pid file /tmp/hbase-hadoop-zookeeper.pid
停止Hadoop的顺序是停止hbase、停止YARN、停止Hdfs
6、web使用
可通过Hdfs页面 http://10.1.2.108:50070进入Hbase页面
或者直接访问 http://10.1.2.108:60010/master.jsp
原创文章,转载请备注原文地址 http://www.cnblogs.com/lxmhhy/p/6026047.html
知识交流讨论请加qq群:180214441。谢谢合作