hbase环境搭建(zookeeper)
一。配置前准备
- java环境,Linux下。
- hadoop环境
二。 hbase安装
1.解压 hbase-1.2.6-bin.tar.gz,重命名,赋予权限给hadoop用户
sudo tar -zxvf hbase-1.2.6-bin.tar.gz
sudo mv hbase-1.2.6 hbase
sudo chown -R hadoop ./hbase
2. 添加环境变量
sudo vim ~/.bashrc
export HBASE_HOME=/usr/local/hbase
export HBASE_CONF_DIR=$HBASE_HOME/conf
export HBASE_CLASS_PATH=$HBASE_CONF_DIR
export PATH=$PATH:$HBASE_HOME/bin
使环境变量生效
source ~/.bashrc
4.修改hbase-site.xml文件
sudo vim /user/lcoal/hbase/conf/hbase-site.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://hadoop:9000/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>hadoop</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/usr/lib/jvm/habse/hadoop/data/zookeeper/zkdata</value>
</property>
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>2181</value>
</property>
<property>
<name>hbase.master</name>
<value>hdfs://hadoop:60000</value>
</property>
<property>
<name>hbase.coprocessor.abortonerror</name>
<value>false</value>
</property>
</configuration>
5.修改hbase-env.sh
sudo vim /user/lcoal/hbase/conf/hbase-env.sh
export JAVA_HOME=/usr/local/java-8-openjdk-amd64
export HBASE_MANAGES_ZK=true
export HBASE_CLASSPATH=/usr/local/hadoop/conf
6. 启动hadoop ./hadoop/sbin/start-all.sh
7. 启动hbase ./hbase/bin/start-hbase.sh 出现9个进程
hadoop@hadoop:/usr/local/hadoop/sbin$ start-hbase.sh
hadoop: starting zookeeper, logging to /usr/local/hbase/logs/hbase-hadoop-zookeeper-hadoop.out
starting master, logging to /usr/local/hbase/logs/hbase-hadoop-master-hadoop.out
OpenJDK 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
starting regionserver, logging to /usr/local/hbase/logs/hbase-hadoop-1-regionserver-hadoop.out
hadoop@hadoop:/usr/local/hadoop/sbin$ jps
14786 ResourceManager
15682 HMaster
16323 Jps
14548 SecondaryNameNode
14921 NodeManager
14346 DataNode
15578 HQuorumPeer
15819 HRegionServer
14190 NameNode
hadoop@hadoop:/usr/local/hadoop/sbin$
8. hbase建表 ./hbase/bin/hbase shell
hadoop@hadoop:/usr/local/hadoop/sbin$ hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hbase/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.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.2.6, rUnknown, Mon May 29 02:25:32 CDT 2017
hbase(main):001:0> list
TABLE
test
1 row(s) in 0.2590 seconds
=> ["test"]
hbase(main):002:0> create 'test2','cf1','cf2'
0 row(s) in 2.4520 seconds
=> Hbase::Table - test2
hbase(main):003:0> put 'test2','row1','cf1:name','java'
0 row(s) in 0.2220 seconds
hbase(main):004:0> scan 'test2'
ROW COLUMN+CELL
row1 column=cf1:name, timestamp=1521690503935, value=java
1 row(s) in 0.0450 seconds
hbase(main):005:0>
三。使用zookeeper
我们下载zookeeper并解压,重命名
sudo tar -zxvf zookeeper-3.4.10.tar.gz
mv zookeeper-3.4.10 /usr/local/zookeeper
添加zookeeper环境变量
sudo vim ~/.bashrc
export ZOOKEEPER_HOME=/usr/local/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
使环境变量生效
source ~/.bashrc
修改zoo.cfg文件
cd zookeeper/conf
cp zoo_sample.cfg zoo.cfg
sudo vim zoo.cfg
zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/hadoop/zookeeper/data
dataLogDir=/home/hadoop/zookeeper/logs
clientPort=2181
启动zookeeper ./zkServer.sh start
关闭zookeeper ./zkServer.sh stop
hadoop@hadoop:$ cd zookeeper/bin
hadoop@hadoop:/usr/local/zookeeper/bin$ ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
hadoop@hadoop:/usr/local/zookeeper/bin$ jps
7889 QuorumPeerMain
7911 Jps
hadoop@hadoop:/usr/local/zookeeper/bin$ ./zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
hadoop@hadoop:/usr/local/zookeeper/bin$
在hbase中使用zookeeper
只需要修改hbase-env.sh,将管理hbase的设置默认不适用自带zookeeper(false)
使用zookeeper+hbase时需要先启动zookeeper,在启动hbase。
sudo vim /user/lcoal/hbase/conf/hbase-env.sh
export JAVA_HOME=/usr/local/java-8-openjdk-amd64
export HBASE_MANAGES_ZK=false
export HBASE_CLASSPATH=/usr/local/hadoop/conf