Docker installation Zookeeper tutorial (super detailed)

生命无罪,健康万岁,我是laity。

Seven times have I despised my soul:

For the first time, it feigned humility when it could have been aggressive;

The second time, when it was empty, fill it with lust;

The third time, between difficult and easy, it chose easy;

For the fourth time, it made a mistake, but comforted itself by saying that others would also make mistakes;

The fifth time, it is free and weak, but it is regarded as the tenacity of life;

The sixth time, when it despises an ugly face, it does not know that it is one of its own masks;

For the seventh time, it leaned sideways in the mud of life, although it was not reconciled, it was timid.

Docker install ZK

  • View local mirrors and retrieve and pull Zookeeper mirrors
# 查看本地镜像
docker images
# 检索ZooKeeper 镜像
docker search zookeeper
# 拉取ZooKeeper镜像最新版本
docker pull zookeeper:latest
# 我使用的版本
docker pull zookeeper:3.5.7
  • Create a ZooKeeper mount directory (data mount directory, configuration mount directory, and log mount directory)

mkdir -p /mydata/zookeeper/data # Data mount directory
mkdir -p /mydata/zookeeper/conf # Configuration mount directory
mkdir -p /mydata/zookeeper/logs # Log mount directory

  • Start the ZooKeeper container
docker run -d --name zookeeper --privileged=true -p 2181:2181  -v /mydata/zookeeper/data:/data -v /mydata/zookeeper/conf:/conf -v /mydata/zookeeper/logs:/datalog zookeeper:3.5.7
  • Parameter Description
-e TZ="Asia/Shanghai" # 指定上海时区 
-d # 表示在一直在后台运行容器
-p 2181:2181 # 对端口进行映射,将本地2181端口映射到容器内部的2181端口
--name # 设置创建的容器名称
-v # 将本地目录(文件)挂载到容器指定目录;
--restart always #始终重新启动zookeeper,看需求设置不设置自启动
  • Add the ZooKeeper configuration file, and add the zoo.cfg configuration file under the mounted configuration file directory (/mydata/zookeeper/conf). The configuration content is as follows:
dataDir=/data  # 保存zookeeper中的数据
clientPort=2181 # 客户端连接端口,通常不做修改
dataLogDir=/datalog
tickTime=2000  # 通信心跳时间
initLimit=5    # LF(leader - follower)初始通信时限
syncLimit=2    # LF 同步通信时限
autopurge.snapRetainCount=3
autopurge.purgeInterval=0
maxClientCnxns=60
standaloneEnabled=true
admin.enableServer=true
server.1=localhost:2888:3888;2181
  • Enter the container and verify the container status
# 进入zookeeper 容器内部
docker exec -it zookeeper /bin/bash
# 检查容器状态
docker exec -it zookeeper /bin/bash ./bin/zkServer.sh status
# 进入控制台
docker exec -it zookeeper zkCli.sh
  • Install ZooInspector client connection

Download address: https://issues.apache.org/jira/secure/attachment/12436620/ZooInspector.zip;

Order:java -jar zookeeper-dev-ZooInspector.jar

The problem encountered: WARNING: IPv4 forwarding is disabled. Networking will not work

解决办法:
# vi /etc/sysctl.conf
或者
# vi /usr/lib/sysctl.d/00-system.conf
添加如下代码:
    net.ipv4.ip_forward=1
重启network服务
# systemctl restart network

test

docker exec -it zookeeper zkCli.sh

insert image description here

Articles about the detailed introduction of zookeeper operation

Docker installs Zookeeper cluster

  • Prepare three machines to ping each other
  • Configuration file zoo.cfg
cd  /mydata/zookeeper/conf
vim zoo.cfg

# 三台机器分别执行添加 
clientPort=2181
dataDir=/data
dataLogDir=/data/log
tickTime=2000
initLimit=5
syncLimit=2
autopurge.snapRetainCount=3
autopurge.purgeInterval=0
maxClientCnxns=60
server.1=node1:2888:3888
server.2=node2:2888:3888
server.3=node3:2888:3888
  • Set myid ID
echo 1 > /mydata/zookeeper/conf/myid
1、2、3 三台机器分别执行
zookeeper选举也会根据myid的大小进行投票master

Guess you like

Origin blog.csdn.net/duyun0/article/details/128437451