准备好3台服务器:
[x]A-> centos7s:192.168.19.1
[x]B-> centos7_1:192.168.19.2
[x]C-> centos7_2:192.168.19.3
配置Zookeeper安装目录
在3台宿主机配置zookeeper安装目录:/docker/develop/zookeeper
并且在文件夹创建 data 和logs 目录:mkdir -p /docker/develop/zookeeper/data && mkdir -p /docker/develop/zookeeper/logs
mkdir -p /docker/develop/zookeeper/data
mkdir -p /docker/develop/zookeeper/logs
授权文件目录:chmod -R 777 /docker/develop/zookeeper/
安装和部署Zookeeper
拉取zookeeper镜像:docker pull zookeeper:3.5.6
[root@centos-helios ~]# docker pull zookeeper:3.5.6
3.5.6: Pulling from library/zookeeper
8ec398bc0356: Pull complete
8e866b095956: Pull complete
e18af1784b1f: Pull complete
9cec9f51936c: Pull complete
475dcbe0e2e9: Pull complete
222ebb7346b3: Pull complete
f0552f5b3f6c: Pull complete
cdfcdbc43b13: Pull complete
Digest: sha256:6b6b5f7fb6a47d2b311df5af1718af5a425a679dbb844d77913fa68d1a8bf0fd
Status: Downloaded newer image for zookeeper:3.5.6
docker.io/library/zookeeper:3.5.6
[root@centos-helios ~]#
临时安装Zookeeper服务:zookeeper-tmp-server
docker run -itd -p 2181:2181 --restart always --name=zookeeper-tmp-server \
--privileged=true \
-v /docker/develop/zookeeper/data:/data \
-v /docker/develop/zookeeper/datalog:/datalog \
-v /docker/develop/zookeeper/logs:/logs \
-e "ZOO_STANDALONE_ENABLED=true" \
-e "TZ=Asia/Shanghai" \
-e "ZOO_4LW_COMMANDS_WHITELIST=*" \
-e "ZOO_AUTOPURGE_SNAPRETAINCOUNT=5" \
-e "ZOO_AUTOPURGE_PURGEINTERVAL=24" \
-e "ZOO_MAX_CLIENT_CNXNS=64" \
-e "ZOO_TICK_TIME=2000" \
-e "ZOO_INIT_LIMIT=100" \
-e "ZOO_SYNC_LIMIT=5" \
zookeeper:3.5.6
复制zookeeper-tmp-server的conf到/docker/develop/zookeeper:
1.查看容器列表:docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"
[root@centos-helios zookeeper]# docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"
CONTAINER ID NAMES PORTS
71ad055739b6 zookeeper-tmp-server 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, 8080/tcp
[root@centos-helios zookeeper]#
2.执行Docker cp 命令:docker cp Zookeeper容器ID:/conf /docker/zookeeper/
[root@centos-helios zookeeper]# docker cp 71ad055739b6:/conf /docker/develop/zookeeper/
[root@centos-helios zookeeper]#
centos7:docker cp 71ad055739b6:/conf /docker/zookeeper/
centos7_1:docker cp bf9df9966efb:/conf /docker/zookeeper/
centos7_2:docker cp 4b4f8e813c80:/conf /docker/zookeeper/
编写zookeeper的zoo.cfg配置文件:
1.服务器集群配置:
[x]centos7:192.168.19.1:2888:3888
[x]centos7_1:192.168.19.2:2888:3888
[x]centos7_2:192.168.19.3:2888:3888
2.对应的配置文件配置如下:
[x]centos7:/docker/zookeeper/conf/zoo.cfg
tickTime=2000
initLimit=100
syncLimit=5
dataDir=/data
dataLogDir=/datalog
clientPort=2181
quorumListenOnAllIPs=true
preAllocSize=64M
globalOutstandingLimit=100000
snapCount=50000
maxClientCnxns=64
minSessionTimeout=4000
maxSessionTimeout=40000
4lw.commands.whitelist=*
admin.enableServer=true
server.1=192.168.19.1:2888:3888
server.2=192.168.19.2:2888:3888
server.3=192.168.19.3:2888:3888
tcpKeepAlive=true
ipReachableTimeout=0
cnxTimeout=3
electionAlg=3
autopurge.snapRetainCount=5
autopurge.purgeInterval=24
#忽略ACL验证
skipACL=yes
forceSync=yes
server.1=阿里云[外网IP OR 内网IP]:2888:3888
server.2=阿里云[外网IP OR 内网IP]:2888:3888
server.3=阿里云[外网IP OR 内网IP]:2888:3888
编写正式安装Dcoekr命令:
[x]centos-helios:
docker run -itd -p 2181:2181 -p 2888:2888 -p 3888:3888 --restart always --name=zookeeper-server --hostname zookeeper-server --privileged=true \
-v /docker/zookeeper/conf/zoo.cfg:/conf/zoo.cfg \
-v /docker/zookeeper/data:/data \
-v /docker/zookeeper/datalog:/datalog \
-v /docker/zookeeper/logs:/logs \
-e "TZ=Asia/Shanghai" \
-e "ZOO_MY_ID=1" \
-e "JAVA_OPTS=-server -Xms512m -Xmx512m -Xmn256m -Duser.home=/opt -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m -XX:+AlwaysPreTouch -XX:-UseBiasedLocking" \
zookeeper:3.5.6
[x]centos-hestia:
docker run -itd -p 2181:2181 -p 2888:2888 -p 3888:3888 --restart always --name=zookeeper-server --hostname zookeeper-server --privileged=true \
-v /docker/zookeeper/conf/zoo.cfg:/conf/zoo.cfg \
-v /docker/zookeeper/data:/data \
-v /docker/zookeeper/datalog:/datalog \
-v /docker/zookeeper/logs:/logs \
-e "TZ=Asia/Shanghai" \
-e "ZOO_MY_ID=2" \
-e "JAVA_OPTS=-server -Xms512m -Xmx512m -Xmn256m -Duser.home=/opt -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m -XX:+AlwaysPreTouch -XX:-UseBiasedLocking" \
zookeeper:3.5.6
[x]centos-hebe:
docker run -itd -p 2181:2181 -p 2888:2888 -p 3888:3888 --restart always --name=zookeeper-server --hostname zookeeper-server --privileged=true \
-v /docker/zookeeper/conf/zoo.cfg:/conf/zoo.cfg \
-v /docker/zookeeper/data:/data \
-v /docker/zookeeper/datalog:/datalog \
-v /docker/zookeeper/logs:/logs \
-e "TZ=Asia/Shanghai" \
-e "ZOO_MY_ID=3" \
-e "JAVA_OPTS=-server -Xms512m -Xmx512m -Xmn256m -Duser.home=/opt -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m -XX:+AlwaysPreTouch -XX:-UseBiasedLocking" \
zookeeper:3.5.6
后续服务配置
1.开放端口[2181 2888 3888]
[1].启动防火墙:systemctl start firewalld.service
[2].查看防火墙状态:systemctl status firewalld.service
[3].开放端口:firewall-cmd --zone=public --add-port=端口号/tcp --permanent
firewall-cmd --zone=public --add-port=2181/tcp --permanent
firewall-cmd --zone=public --add-port=2888/tcp --permanent
firewall-cmd --zone=public --add-port=3888/tcp --permanent
[4].加载初始化防火墙生效:firewall-cmd --reload
[5].停用防火墙:systemctl stop firewalld.service
2.配置启动以及测试zookeeper服务:
[x]启动容器Zookeeper服务顺序:A->B->C-重启A
[x]进入容器输入:bin/zkServer.sh status
centos7:
root@zookeeper-server:/apache-zookeeper-3.5.6-bin# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
root@zookeeper-server:/apache-zookeeper-3.5.6-bin#
centos7_1:
root@zookeeper-server:/apache-zookeeper-3.5.6-bin# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: leader
root@zookeeper-server:/apache-zookeeper-3.5.6-bin#
centos7_2:
root@zookeeper-server:/apache-zookeeper-3.5.6-bin# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
root@zookeeper-server:/apache-zookeeper-3.5.6-bin#