基本Docker zookeeper 3.4.9 集群搭建

环境搭建步骤


一 准备

Docker环境(centos7 + docker1.12.1)

zookeeper 3.4.9    wget http://mirrors.hust.edu.cn/apache/zookeeper/stable/zookeeper-3.4.9.tar.gz


遗留问题


二 基础镜像制作

Dockerfile

FROM centos:6.7
MAINTAINER loomz [email protected]
ENV REFRESHED_AT 2017-03-15

ENV JAVA_HOME /usr/java/default
ENV CLASSPATH .:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
ENV PATH $JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
ENV ZK_HOME /opt/zookeeper/default

ADD jdk1.6.0_45.tar.gz /usr/java/jdk1.6.0_45
RUN ln -s /usr/java/jdk1.6.0_45 $JAVA_HOME

ADD zookeeper-3.4.9.tar.gz /opt/zookeeper/
RUN ln -s /opt/zookeeper/zookeeper-3.4.9 $ZK_HOME

EXPOSE 2181

ENTRYPOINT ["/opt/zookeeper/default/bin/zkServer.sh", "start-foreground", "/etc/zookeeper/zoo.cfg"]

三 容器启动

配置文件zoo.cfg

tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181

initLimit=5  
syncLimit=2  
server.1=172.17.0.2:2888:3888  
server.2=172.17.0.3:2888:3888  
server.3=172.17.0.4:2888:3888


容器启动脚本start-s1.sh   start-s2.sh  start-s3.sh

#!/bin/bash
docker run -d --restart always -h zookeeper-server1 --name zookeeper-server1 -v /home/loomz/dockerfiles/zk/conf/:/etc/zookeeper/:rw -v /home/loomz/dockerfiles/zk/tmp_server1:/var/lib/zookeeper/ zookeeper:v3.4.9

start-s2.sh   start-s3.sh 对应更改server1   为 server2   server 3

在tmp_server1/tmp_server2/tmp_server3文件夹中建立myid文件在,内容对应数字 1  2  3    (因为上面配置为server.1   server.2    server.3)


四 启动后验证

同时启动start-s1.sh     start-s2.sh    start-s3.sh后进入容器验证zk状态

docker exec -it  zookeeper-server1   /bin/bash

/opt/zookeeper/default/bin/zkServer.sh status /etc/zookeeper/zoo.cfg

ZooKeeper JMX enabled by default
Using config: /etc/zookeeper/zoo.cfg
Mode: leader





你可能感兴趣的:(中间件)