环境配置
- VM:VMware Workstation
- OS:Ubuntu 14.04 LTS
- HBASE:hbase-1.2.2
HBase集群规划
- 172.17.0.5 hmaster
- 172.17.0.6 regionserver1
- 172.17.0.7 regionserver2
- 192.168.162.129 zkhost1
基于Dockerfile构建HBase基础镜像
创建Dockerfile文件,内容如下 :
FROM ubuntu:14.04
MAINTAINER Rain <>
ENV REFRESHED_AT 2016-09-15
RUN apt-get update
RUN apt-get install -y openssh-server openssh-client
ADD jdk-7u80-linux-x64.tar.gz /usr/local/
ENV JAVA_HOME /usr/local/jdk1.7.0_80
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH $PATH:$JAVA_HOME/bin
RUN addgroup hadoop
RUN useradd -m hadoop -g hadoop -p qazwsx
ADD hbase-1.2.2-bin.tar.gz /usr/local/
RUN chown -R hadoop:hadoop /usr/local/hbase-1.2.2
RUN cd /usr/local && ln -s ./hbase-1.2.2 hbase
ENV HBASE_HOME /usr/local/hbase
ENV PATH ${HBASE_HOME}/bin:$PATH
RUN cd /etc/sudoers.d && sudo touch nopasswdsudo && echo "hadoop ALL=(ALL) NOPASSWD : ALL" >> nopasswdsudo
RUN mkdir /var/run/sshd
USER hadoop
RUN ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
RUN cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
EXPOSE 22
构建基础镜像:
$ sudo docker build -t="rain:hbase-base" .
从镜像启动容器:
$ sudo docker run -t -i rain:hbase-base /bin/bash
基于Dockerfile构建HBase主镜像
创建Dockerfile文件,内容如下 :
FROM rain:hbase-base
MAINTAINER Rain <>
ENV REFRESHED_AT 2016-09-15
ADD hbase-env.sh $HBASE_HOME/conf/
ADD hbase-site.xml $HBASE_HOME/conf/
ADD regionservers $HBASE_HOME/conf/
RUN sudo chown -R hadoop:hadoop $HBASE_HOME/conf
RUN sudo mkdir -p /opt/hadoop/data/zookeeper
RUN sudo chown -R hadoop:hadoop /opt/hadoop
WORKDIR /home/hadoop
COPY bootstrap.sh /home/hadoop/
RUN sudo chown -R hadoop:hadoop /home/hadoop
RUN sudo chmod 766 /home/hadoop/bootstrap.sh
ENTRYPOINT ["/home/hadoop/bootstrap.sh"]
#EXPOSE 16000 16010 16020 16030
构建HBase Master镜像:
$ sudo docker build -t="rain:hmaster" .
启动容器:
$ sudo docker run -t -i --name hmaster -h hmaster -d -P -p 16010:16010 rain:hmaster
基于Dockerfile构建HBase RegionServer镜像
创建Dockerfile文件,内容同HBase Master镜像。
编辑bootstrap.sh用于启动ssh:
#!/bin/bash
sudo /usr/sbin/sshd -D
构建HBase Region Server镜像:
$ sudo docker build -t="rain:regionserver" .
启动容器:
$ sudo docker run -t -i --name regionserver1 -h regionserver1 -d rain:regionserver
$ sudo docker run -t -i --name regionserver2 -h regionserver2 -d rain:regionserver
与HBase Master和Region Servers交互
操作命令如下:
$ sudo docker exec -it hmaster /bin/bash
$ sudo docker exec -it regionserver1 /bin/bash
$ sudo docker exec -it regionserver2 /bin/bash
配置Host编写脚本:
hadoop@hmaster:~$ vi run_hosts.sh
内容如下:
#!/bin/bash
echo 172.17.0.2 hadoop-master >> /etc/hosts
echo 172.17.0.5 hmaster >> /etc/hosts
echo 172.17.0.6 regionserver1 >> /etc/hosts
echo 172.17.0.7 regionserver2 >> /etc/hosts
echo 192.168.162.129 zkhost1 >> /etc/hosts
执行脚本:
hadoop@hmaster:~$ chmod +x run_hosts.sh
hadoop@hmaster:~$ sudo ./run_hosts.sh
复制脚本到其它两个Region Server节点,并执行脚本:
hadoop@hmaster:~$ scp run_hosts.sh regionserver1:/home/hadoop/
hadoop@hmaster:~$ scp run_hosts.sh regionserver1:/home/hadoop/
HBase集群操作:
启动集群:
$ bin/start-hbase.sh
节点启动成功后,可以在相应节点上看到下面进程:
hadoop@hmaster:/usr/local/hbase$ jps
715 HMaster
992 Jps
hadoop@regionserver1:~$ jps
247 HRegionServer
423 Jps
hadoop@regionserver2:~$ jps
264 HRegionServer
486 Jps
通过宿主机访问WEB控制台:
http://宿主机IP:16010
界面效果图:
HBase配置文件:
1.编辑hbase-env.sh:
export JAVA_HOME=/usr/local/jdk1.7.0_80
export HBASE_MANAGES_ZK=false
2.编辑hbase-site.xml:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
-->
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://hadoop-master:8020/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>zkhost1</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/opt/hadoop/data/zookeeper</value>
</property>
</configuration>
3.编辑regionservers:
hregionserver1
hregionserver2