zookeeper

Zookeeper 简介

ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. All of these kinds of services are used in some form or another by distributed applications. Each time they are implemented there is a lot of work that goes into fixing the bugs and race conditions that are inevitable. Because of the difficulty of implementing these kinds of services, applications initially usually skimp on them, which make them brittle in the presence of change and difficult to manage. Even when done correctly, different implementations of these services lead to management complexity when the applications are deployed.

集群搭建

本次搭建基于 docker 容器环境下 ubuntu 20.04 镜像进行分布式搭建.

配置 docker 依赖

安装 docker . 请自行解决.

创建 Docker 网络

配置一个桥接网络, 以后所有依赖 zookeeper 的应用都可以使用此网络, 比如 dubbo

docker network create -d bridge --subnet=192.168.0.0/24 --gateway=192.168.0.254 --ip-range=192.168.0.0/24 app

下载 zookeeper

http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.6.2/zookeeper-3.6.2.tar.gz

解压文件:

tar xf apache-zookeeper-3.6.2-bin.tar.gz / /storage/app/zookeeper/

配置环境变量:

vim ~/.bashrc 
export ZK_HOME= /storage/app/zookeeper/apache-zookeeper-3.6.2-bin
export ZK_DATA=/storage/docker/zookeeper/data
source ~/.bashrc

配置 3个节点的 zookeeper 集群配置文件

  1. 编辑配置文件. vim $ZK_HOME/conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/zk/data
clientPort=2181

server.1=192.168.0.101:2888:3888
server.2=192.168.0.102:2888:3888
server.3=192.168.0.103:2888:3888

打包镜像

创建 Dockerfile vim $ZK_DATA/../Dockerfile

FROM openjdk:8
RUN mkdir /app
COPY . /app
WORKDIR /app
CMD ["./bin/zkServer.sh", "start-foreground"]

打包镜像cd /storage/app/zookeeper/apache-zookeeper-3.6.2-bin

docker build -t jansora/zk:zk1 $ZK_HOME -f $ZK_DATA/../Dockerfile --build-arg HOSTNAME=zk1 --build-arg MY_ID=1
docker build -t jansora/zk:zk2 $ZK_HOME -f $ZK_DATA/../Dockerfile --build-arg HOSTNAME=zk2 --build-arg MY_ID=2
docker build -t jansora/zk:zk3 $ZK_HOME -f $ZK_DATA/../Dockerfile --build-arg HOSTNAME=zk3 --build-arg MY_ID=3

初始化配置

如果你不需要映射 zk 数据到本地, 则不需要本步骤, 上一步在打 Docker 镜像的时候已经操作过这一步了.

参考下一步 启动容器

mkdir -p $ZK_DATA/zk1/data && echo 1 > $ZK_DATA/zk1/data/myid
mkdir -p $ZK_DATA/zk2/data && echo 2 > $ZK_DATA/zk2/data/myid
mkdir -p $ZK_DATA/zk3/data && echo 3 > $ZK_DATA/zk3/data/myid

启动容器

最好映射下 zk 数据到本地, 这样便于管理数据

docker run -it -d  --name=zk1 --hostname=zk1 --network=app --ip 192.168.0.101 -v $ZK_DATA/zk1/data:/app/data jansora/zk:v1
docker run -it -d  --name=zk2 --hostname=zk2 --network=app --ip 192.168.0.102 -v $ZK_DATA/zk2/data:/app/data jansora/zk:v1
docker run -it -d  --name=zk3 --hostname=zk3 --network=app --ip 192.168.0.103 -v $ZK_DATA/zk3/data:/app/data jansora/zk:v1

检查网络状态

查看网络状态 docker network inspect app

    {
        "Name": "app",
        "Id": "3fe0af67b6ce349924124618fcf9fcbfc7201662805820dab49c8c8648fa334b",
        "Created": "2020-12-09T14:55:50.49088251+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "192.168.0.0/24",
                    "IPRange": "192.168.0.0/24",
                    "Gateway": "192.168.0.254"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "1b87ca46d188591b3a00aa6432d2c64363af13aff71231b2349d9f1c6967f7c4": {
                "Name": "zk2",
                "EndpointID": "f3b6665e3ebf10225e266efa8ee585f57a897b736e75e8376df54e2de912893a",
                "MacAddress": "02:42:c0:a8:00:66",
                "IPv4Address": "192.168.0.102/24",
                "IPv6Address": ""
            },
            "a97ec943ef34e229ff1552d567d247c31206f7661f7597803e2dcbda792e8476": {
                "Name": "zk1",
                "EndpointID": "482d9761619e209d248453ce4c01e0f08380a7b5927058f36c1e20191c11914e",
                "MacAddress": "02:42:c0:a8:00:65",
                "IPv4Address": "192.168.0.101/24",
                "IPv6Address": ""
            },
            "c7322999b162e4355439100476eda27a467ace335aeafe325f941f34e83686cc": {
                "Name": "zk3",
                "EndpointID": "efbc97a119782b0b0b341b02ca9f801b732fb9986899f42088cdb7afd0aa8ce1",
                "MacAddress": "02:42:c0:a8:00:67",
                "IPv4Address": "192.168.0.103/24",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

检查下 zk 状态

docker exec -it zk1 /zk/bin/zkServer.sh status

ZooKeeper JMX enabled by default
Using config: /zk/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower

跟踪 zk 日志

docker logs zk1

ZooKeeper JMX enabled by default
Using config: /zk/bin/../conf/zoo.cfg
2020-12-09 07:04:39,087 [myid:] - INFO  [main:QuorumPeerConfig@174] - Reading configuration from: /zk/bin/../conf/zoo.cfg
2020-12-09 07:04:39,095 [myid:] - INFO  [main:QuorumPeerConfig@460] - clientPortAddress is 0.0.0.0:2181
2020-12-09 07:04:39,095 [myid:] - INFO  [main:QuorumPeerConfig@464] - secureClientPort is not set
2020-12-09 07:04:39,095 [myid:] - INFO  [main:QuorumPeerConfig@480] - observerMasterPort is not set
2020-12-09 07:04:39,095 [myid:] - INFO  [main:QuorumPeerConfig@497] - metricsProvider.className is org.apache.zookeeper.metrics.impl.DefaultMetricsProvider
2020-12-09 07:04:39,103 [myid:1] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2020-12-09 07:04:39,103 [myid:1] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2020-12-09 07:04:39,104 [myid:1] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2020-12-09 07:04:39,106 [myid:1] - INFO  [main:ManagedUtil@44] - Log4j 1.2 jmx support found and enabled.
2020-12-09 07:04:39,112 [myid:1] - INFO  [main:QuorumPeerMain@151] - Starting quorum peer, myid=1
2020-12-09 07:04:39,122 [myid:1] - INFO  [main:ServerMetrics@62] - ServerMetrics initialized with provider org.apache.zookeeper.metrics.impl.DefaultMetricsProvider@71be98f5
2020-12-09 07:04:39,129 [myid:1] - INFO  [main:ServerCnxnFactory@169] - Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory
2020-12-09 07:04:39,129 [myid:1] - WARN  [main:ServerCnxnFactory@309] - maxCnxns is not configured, using default value 0.
2020-12-09 07:04:39,131 [myid:1] - INFO  [main:NIOServerCnxnFactory@666] - Configuring NIO connection handler with 10s sessionless connection timeout, 1 selector thread(s), 8 worker threads, and 64 kB direct buffers.
2020-12-09 07:04:39,134 [myid:1] - INFO  [main:NIOServerCnxnFactory@674] - binding to port 0.0.0.0/0.0.0.0:2181
2020-12-09 07:04:39,140 [myid:1] - INFO  [main:QuorumPeer@752] - zookeeper.quorumCnxnTimeoutMs=-1
2020-12-09 07:04:39,159 [myid:1] - INFO  [main:Log@169] - Logging initialized @383ms to org.eclipse.jetty.util.log.Slf4jLog
2020-12-09 07:04:39,229 [myid:1] - WARN  [main:ContextHandler@1520] - o.e.j.s.ServletContextHandler@528931cf{/,null,UNAVAILABLE} contextPath ends with /*
2020-12-09 07:04:39,229 [myid:1] - WARN  [main:ContextHandler@1531] - Empty contextPath
2020-12-09 07:04:39,242 [myid:1] - INFO  [main:X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2020-12-09 07:04:39,244 [myid:1] - INFO  [main:FileTxnSnapLog@124] - zookeeper.snapshot.trust.empty : false
2020-12-09 07:04:39,247 [myid:1] - INFO  [main:QuorumPeer@1683] - Local sessions disabled
2020-12-09 07:04:39,247 [myid:1] - INFO  [main:QuorumPeer@1694] - Local session upgrading disabled
2020-12-09 07:04:39,247 [myid:1] - INFO  [main:QuorumPeer@1661] - tickTime set to 2000
2020-12-09 07:04:39,247 [myid:1] - INFO  [main:QuorumPeer@1705] - minSessionTimeout set to 4000
2020-12-09 07:04:39,247 [myid:1] - INFO  [main:QuorumPeer@1716] - maxSessionTimeout set to 40000
2020-12-09 07:04:39,247 [myid:1] - INFO  [main:QuorumPeer@1741] - initLimit set to 10
2020-12-09 07:04:39,247 [myid:1] - INFO  [main:QuorumPeer@1928] - syncLimit set to 5
2020-12-09 07:04:39,247 [myid:1] - INFO  [main:QuorumPeer@1943] - connectToLearnerMasterLimit set to 0
2020-12-09 07:04:39,257 [myid:1] - INFO  [main:ZookeeperBanner@42] -
2020-12-09 07:04:39,257 [myid:1] - INFO  [main:ZookeeperBanner@42] -   ______                  _
2020-12-09 07:04:39,257 [myid:1] - INFO  [main:ZookeeperBanner@42] -  |___  /                 | |
2020-12-09 07:04:39,257 [myid:1] - INFO  [main:ZookeeperBanner@42] -     / /    ___     ___   | | __   ___    ___   _ __     ___   _ __
2020-12-09 07:04:39,257 [myid:1] - INFO  [main:ZookeeperBanner@42] -    / /    / _ \   / _ \  | |/ /  / _ \  / _ \ | '_ \   / _ \ | '__|
2020-12-09 07:04:39,257 [myid:1] - INFO  [main:ZookeeperBanner@42] -   / /__  | (_) | | (_) | |   <  |  __/ |  __/ | |_) | |  __/ | |
2020-12-09 07:04:39,257 [myid:1] - INFO  [main:ZookeeperBanner@42] -  /_____|  \___/   \___/  |_|\_\  \___|  \___| | .__/   \___| |_|
2020-12-09 07:04:39,257 [myid:1] - INFO  [main:ZookeeperBanner@42] -                                               | |
2020-12-09 07:04:39,257 [myid:1] - INFO  [main:ZookeeperBanner@42] -                                               |_|
2020-12-09 07:04:39,257 [myid:1] - INFO  [main:ZookeeperBanner@42] -
2020-12-09 07:04:39,258 [myid:1] - INFO  [main:Environment@98] - Server environment:zookeeper.version=3.6.2--803c7f1a12f85978cb049af5e4ef23bd8b688715, built on 09/04/2020 12:44 GMT
2020-12-09 07:04:39,258 [myid:1] - INFO  [main:Environment@98] - Server environment:host.name=zk1
2020-12-09 07:04:39,258 [myid:1] - INFO  [main:Environment@98] - Server environment:java.version=1.8.0_275
2020-12-09 07:04:39,258 [myid:1] - INFO  [main:Environment@98] - Server environment:java.vendor=Oracle Corporation
2020-12-09 07:04:39,258 [myid:1] - INFO  [main:Environment@98] - Server environment:java.home=/usr/local/openjdk-8/jre
2020-12-09 07:04:39,259 [myid:1] - INFO  [main:Environment@98] - Server environment:java.class.path=/zk/bin/../zookeeper-server/target/classes:/zk/bin/../build/classes:/zk/bin/../zookeeper-server/target/lib/*.jar:/zk/bin/../build/lib/*.jar:/zk/bin/../lib/zookeeper-prometheus-metrics-3.6.2.jar:/zk/bin/../lib/zookeeper-jute-3.6.2.jar:/zk/bin/../lib/zookeeper-3.6.2.jar:/zk/bin/../lib/snappy-java-1.1.7.jar:/zk/bin/../lib/slf4j-log4j12-1.7.25.jar:/zk/bin/../lib/slf4j-api-1.7.25.jar:/zk/bin/../lib/simpleclient_servlet-0.6.0.jar:/zk/bin/../lib/simpleclient_hotspot-0.6.0.jar:/zk/bin/../lib/simpleclient_common-0.6.0.jar:/zk/bin/../lib/simpleclient-0.6.0.jar:/zk/bin/../lib/netty-transport-native-unix-common-4.1.50.Final.jar:/zk/bin/../lib/netty-transport-native-epoll-4.1.50.Final.jar:/zk/bin/../lib/netty-transport-4.1.50.Final.jar:/zk/bin/../lib/netty-resolver-4.1.50.Final.jar:/zk/bin/../lib/netty-handler-4.1.50.Final.jar:/zk/bin/../lib/netty-common-4.1.50.Final.jar:/zk/bin/../lib/netty-codec-4.1.50.Final.jar:/zk/bin/../lib/netty-buffer-4.1.50.Final.jar:/zk/bin/../lib/metrics-core-3.2.5.jar:/zk/bin/../lib/log4j-1.2.17.jar:/zk/bin/../lib/json-simple-1.1.1.jar:/zk/bin/../lib/jline-2.14.6.jar:/zk/bin/../lib/jetty-util-9.4.24.v20191120.jar:/zk/bin/../lib/jetty-servlet-9.4.24.v20191120.jar:/zk/bin/../lib/jetty-server-9.4.24.v20191120.jar:/zk/bin/../lib/jetty-security-9.4.24.v20191120.jar:/zk/bin/../lib/jetty-io-9.4.24.v20191120.jar:/zk/bin/../lib/jetty-http-9.4.24.v20191120.jar:/zk/bin/../lib/javax.servlet-api-3.1.0.jar:/zk/bin/../lib/jackson-databind-2.10.3.jar:/zk/bin/../lib/jackson-core-2.10.3.jar:/zk/bin/../lib/jackson-annotations-2.10.3.jar:/zk/bin/../lib/commons-lang-2.6.jar:/zk/bin/../lib/commons-cli-1.2.jar:/zk/bin/../lib/audience-annotations-0.5.0.jar:/zk/bin/../zookeeper-*.jar:/zk/bin/../zookeeper-server/src/main/resources/lib/*.jar:/zk/bin/../conf:
2020-12-09 07:04:39,259 [myid:1] - INFO  [main:Environment@98] - Server environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2020-12-09 07:04:39,259 [myid:1] - INFO  [main:Environment@98] - Server environment:java.io.tmpdir=/tmp
2020-12-09 07:04:39,259 [myid:1] - INFO  [main:Environment@98] - Server environment:java.compiler=<NA>
2020-12-09 07:04:39,259 [myid:1] - INFO  [main:Environment@98] - Server environment:os.name=Linux
2020-12-09 07:04:39,259 [myid:1] - INFO  [main:Environment@98] - Server environment:os.arch=amd64
2020-12-09 07:04:39,259 [myid:1] - INFO  [main:Environment@98] - Server environment:os.version=5.4.0-42-generic
2020-12-09 07:04:39,259 [myid:1] - INFO  [main:Environment@98] - Server environment:user.name=root
2020-12-09 07:04:39,259 [myid:1] - INFO  [main:Environment@98] - Server environment:user.home=/root
2020-12-09 07:04:39,259 [myid:1] - INFO  [main:Environment@98] - Server environment:user.dir=/zk
2020-12-09 07:04:39,259 [myid:1] - INFO  [main:Environment@98] - Server environment:os.memory.free=91MB
2020-12-09 07:04:39,259 [myid:1] - INFO  [main:Environment@98] - Server environment:os.memory.max=889MB
2020-12-09 07:04:39,259 [myid:1] - INFO  [main:Environment@98] - Server environment:os.memory.total=113MB
2020-12-09 07:04:39,259 [myid:1] - INFO  [main:ZooKeeperServer@129] - zookeeper.enableEagerACLCheck = false
2020-12-09 07:04:39,259 [myid:1] - INFO  [main:ZooKeeperServer@137] - zookeeper.digest.enabled = true
2020-12-09 07:04:39,259 [myid:1] - INFO  [main:ZooKeeperServer@141] - zookeeper.closeSessionTxn.enabled = true
2020-12-09 07:04:39,260 [myid:1] - INFO  [main:ZooKeeperServer@1444] - zookeeper.flushDelay=0
2020-12-09 07:04:39,260 [myid:1] - INFO  [main:ZooKeeperServer@1453] - zookeeper.maxWriteQueuePollTime=0
2020-12-09 07:04:39,260 [myid:1] - INFO  [main:ZooKeeperServer@1462] - zookeeper.maxBatchSize=1000
2020-12-09 07:04:39,260 [myid:1] - INFO  [main:ZooKeeperServer@243] - zookeeper.intBufferStartingSizeBytes = 1024
2020-12-09 07:04:39,263 [myid:1] - INFO  [main:WatchManagerFactory@42] - Using org.apache.zookeeper.server.watch.WatchManager as watch manager
2020-12-09 07:04:39,263 [myid:1] - INFO  [main:WatchManagerFactory@42] - Using org.apache.zookeeper.server.watch.WatchManager as watch manager
2020-12-09 07:04:39,264 [myid:1] - INFO  [main:ZKDatabase@132] - zookeeper.snapshotSizeFactor = 0.33
2020-12-09 07:04:39,264 [myid:1] - INFO  [main:ZKDatabase@152] - zookeeper.commitLogCount=500
2020-12-09 07:04:39,274 [myid:1] - INFO  [main:QuorumPeer@2009] - Using insecure (non-TLS) quorum communication
2020-12-09 07:04:39,274 [myid:1] - INFO  [main:QuorumPeer@2015] - Port unification disabled
2020-12-09 07:04:39,274 [myid:1] - INFO  [main:QuorumPeer@174] - multiAddress.enabled set to false
2020-12-09 07:04:39,274 [myid:1] - INFO  [main:QuorumPeer@199] - multiAddress.reachabilityCheckEnabled set to true
2020-12-09 07:04:39,274 [myid:1] - INFO  [main:QuorumPeer@186] - multiAddress.reachabilityCheckTimeoutMs set to 1000
2020-12-09 07:04:39,274 [myid:1] - INFO  [main:QuorumPeer@2469] - QuorumPeer communication is not secured! (SASL auth disabled)
2020-12-09 07:04:39,274 [myid:1] - INFO  [main:QuorumPeer@2494] - quorum.cnxn.threads.size set to 20
2020-12-09 07:04:39,277 [myid:1] - INFO  [main:SnapStream@61] - zookeeper.snapshot.compression.method = CHECKED
2020-12-09 07:04:39,277 [myid:1] - INFO  [main:FileSnap@85] - Reading snapshot /zk/data/version-2/snapshot.0
2020-12-09 07:04:39,279 [myid:1] - INFO  [main:DataTree@1737] - The digest value is empty in snapshot
2020-12-09 07:04:39,282 [myid:1] - INFO  [main:ZKDatabase@289] - Snapshot loaded in 7 ms, highest zxid is 0x0, digest is 1371985504
2020-12-09 07:04:39,289 [myid:1] - INFO  [main:Server@359] - jetty-9.4.24.v20191120; built: 2019-11-20T21:37:49.771Z; git: 363d5f2df3a8a28de40604320230664b9c793c16; jvm 1.8.0_275-b01
2020-12-09 07:04:39,312 [myid:1] - INFO  [main:DefaultSessionIdManager@333] - DefaultSessionIdManager workerName=node0
2020-12-09 07:04:39,312 [myid:1] - INFO  [main:DefaultSessionIdManager@338] - No SessionScavenger set, using defaults
2020-12-09 07:04:39,317 [myid:1] - INFO  [main:HouseKeeper@140] - node0 Scavenging every 660000ms
2020-12-09 07:04:39,319 [myid:1] - WARN  [main:ConstraintSecurityHandler@757] - ServletContext@o.e.j.s.ServletContextHandler@528931cf{/,null,STARTING} has uncovered http methods for path: /*
2020-12-09 07:04:39,325 [myid:1] - INFO  [main:ContextHandler@825] - Started o.e.j.s.ServletContextHandler@528931cf{/,null,AVAILABLE}
2020-12-09 07:04:39,331 [myid:1] - INFO  [main:AbstractConnector@330] - Started ServerConnector@6ddf90b0{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2020-12-09 07:04:39,331 [myid:1] - INFO  [main:Server@399] - Started @556ms
2020-12-09 07:04:39,332 [myid:1] - INFO  [main:JettyAdminServer@182] - Started AdminServer on address 0.0.0.0, port 8080 and command URL /commands
2020-12-09 07:04:39,332 [myid:1] - INFO  [main:QuorumPeer@2511] - Using 10000ms as the quorum cnxn socket timeout
2020-12-09 07:04:39,336 [myid:1] - INFO  [main:QuorumCnxManager$Listener@923] - Election port bind maximum retries is 3
2020-12-09 07:04:39,341 [myid:1] - INFO  [main:FastLeaderElection@88] - zookeeper.fastleader.minNotificationInterval=200
2020-12-09 07:04:39,341 [myid:1] - INFO  [main:FastLeaderElection@90] - zookeeper.fastleader.maxNotificationInterval=60000
2020-12-09 07:04:39,347 [myid:1] - INFO  [main:ZKAuditProvider@42] - ZooKeeper audit is disabled.
2020-12-09 07:04:39,350 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):QuorumPeer@1374] - LOOKING
2020-12-09 07:04:39,351 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):FastLeaderElection@944] - New election. My id = 1, proposed zxid=0x0
2020-12-09 07:04:39,363 [myid:1] - INFO  [ListenerHandler-/192.168.0.101:3888:QuorumCnxManager$Listener$ListenerHandler@1065] - 1 is accepting connections now, my election bind port: /192.168.0.101:3888
2020-12-09 07:04:39,363 [myid:1] - INFO  [WorkerReceiver[myid=1]:FastLeaderElection$Messenger$WorkerReceiver@389] - Notification: my state:LOOKING; n.sid:1, n.state:LOOKING, n.leader:1, n.round:0x1, n.peerEpoch:0x0, n.zxid:0x0, message format version:0x2, n.config version:0x0
2020-12-09 07:04:39,370 [myid:1] - WARN  [QuorumConnectionThread-[myid=1]-1:QuorumCnxManager@400] - Cannot open channel to 2 at election address /192.168.0.102:3888
java.net.ConnectException: Connection refused (Connection refused)
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:607)
	at org.apache.zookeeper.server.quorum.QuorumCnxManager.initiateConnection(QuorumCnxManager.java:383)
	at org.apache.zookeeper.server.quorum.QuorumCnxManager$QuorumConnectionReqThread.run(QuorumCnxManager.java:457)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
2020-12-09 07:04:39,573 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):FastLeaderElection@979] - Notification time out: 400
2020-12-09 07:04:39,573 [myid:1] - WARN  [QuorumConnectionThread-[myid=1]-3:QuorumCnxManager@400] - Cannot open channel to 2 at election address /192.168.0.102:3888
java.net.ConnectException: Connection refused (Connection refused)
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:607)
	at org.apache.zookeeper.server.quorum.QuorumCnxManager.initiateConnection(QuorumCnxManager.java:383)
	at org.apache.zookeeper.server.quorum.QuorumCnxManager$QuorumConnectionReqThread.run(QuorumCnxManager.java:457)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
2020-12-09 07:04:39,843 [myid:1] - INFO  [ListenerHandler-/192.168.0.101:3888:QuorumCnxManager$Listener$ListenerHandler@1070] - Received connection request from /192.168.0.102:38502
2020-12-09 07:04:39,846 [myid:1] - INFO  [WorkerReceiver[myid=1]:FastLeaderElection$Messenger$WorkerReceiver@389] - Notification: my state:LOOKING; n.sid:2, n.state:LOOKING, n.leader:2, n.round:0x1, n.peerEpoch:0x0, n.zxid:0x0, message format version:0x2, n.config version:0x0
2020-12-09 07:04:39,847 [myid:1] - INFO  [WorkerReceiver[myid=1]:FastLeaderElection$Messenger$WorkerReceiver@389] - Notification: my state:LOOKING; n.sid:1, n.state:LOOKING, n.leader:2, n.round:0x1, n.peerEpoch:0x0, n.zxid:0x0, message format version:0x2, n.config version:0x0
2020-12-09 07:04:40,047 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):QuorumPeer@857] - Peer state changed: following
2020-12-09 07:04:40,048 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):QuorumPeer@1456] - FOLLOWING
2020-12-09 07:04:40,051 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):Learner@117] - leaderConnectDelayDuringRetryMs: 100
2020-12-09 07:04:40,051 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):Learner@118] - TCP NoDelay set to: true
2020-12-09 07:04:40,052 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):BlueThrottle@141] - Weighed connection throttling is disabled
2020-12-09 07:04:40,053 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):ZooKeeperServer@1256] - minSessionTimeout set to 4000
2020-12-09 07:04:40,053 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):ZooKeeperServer@1265] - maxSessionTimeout set to 40000
2020-12-09 07:04:40,054 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):ResponseCache@45] - Response cache size is initialized with value 400.
2020-12-09 07:04:40,054 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):ResponseCache@45] - Response cache size is initialized with value 400.
2020-12-09 07:04:40,055 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):RequestPathMetricsCollector@111] - zookeeper.pathStats.slotCapacity = 60
2020-12-09 07:04:40,055 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):RequestPathMetricsCollector@112] - zookeeper.pathStats.slotDuration = 15
2020-12-09 07:04:40,055 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):RequestPathMetricsCollector@113] - zookeeper.pathStats.maxDepth = 6
2020-12-09 07:04:40,055 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):RequestPathMetricsCollector@114] - zookeeper.pathStats.initialDelay = 5
2020-12-09 07:04:40,055 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):RequestPathMetricsCollector@115] - zookeeper.pathStats.delay = 5
2020-12-09 07:04:40,055 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):RequestPathMetricsCollector@116] - zookeeper.pathStats.enabled = false
2020-12-09 07:04:40,056 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):ZooKeeperServer@1481] - The max bytes for all large requests are set to 104857600
2020-12-09 07:04:40,056 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):ZooKeeperServer@1495] - The large request threshold is set to -1
2020-12-09 07:04:40,056 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):ZooKeeperServer@339] - Created server with tickTime 2000 minSessionTimeout 4000 maxSessionTimeout 40000 clientPortListenBacklog -1 datadir /zk/data/version-2 snapdir /zk/data/version-2
2020-12-09 07:04:40,057 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):Follower@75] - FOLLOWING - LEADER ELECTION TOOK - 706 MS
2020-12-09 07:04:40,059 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):QuorumPeer@863] - Peer state changed: following - discovery
2020-12-09 07:04:40,065 [myid:1] - INFO  [LeaderConnector-/192.168.0.102:2888:Learner$LeaderConnector@330] - Successfully connected to leader, using address: /192.168.0.102:2888
2020-12-09 07:04:40,088 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):QuorumPeer@863] - Peer state changed: following - synchronization
2020-12-09 07:04:40,090 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):Learner@511] - Getting a diff from the leader 0x0
2020-12-09 07:04:40,090 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):QuorumPeer@868] - Peer state changed: following - synchronization - diff
2020-12-09 07:04:40,093 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):Learner@677] - Learner received NEWLEADER message
2020-12-09 07:04:40,093 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):QuorumPeer@1811] - Dynamic reconfig is disabled, we don't store the last seen config.
2020-12-09 07:04:40,119 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):Learner@661] - Learner received UPTODATE message
2020-12-09 07:04:40,120 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):QuorumPeer@868] - Peer state changed: following - synchronization
2020-12-09 07:04:40,123 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):CommitProcessor@476] - Configuring CommitProcessor with readBatchSize -1 commitBatchSize 1
2020-12-09 07:04:40,123 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):CommitProcessor@438] - Configuring CommitProcessor with 4 worker threads.
2020-12-09 07:04:40,125 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):RequestThrottler@74] - zookeeper.request_throttler.shutdownTimeout = 10000
2020-12-09 07:04:40,134 [myid:1] - INFO  [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):QuorumPeer@863] - Peer state changed: following - broadcast
2020-12-09 07:04:41,137 [myid:1] - INFO  [ListenerHandler-/192.168.0.101:3888:QuorumCnxManager$Listener$ListenerHandler@1070] - Received connection request from /192.168.0.103:54278
2020-12-09 07:04:41,138 [myid:1] - INFO  [QuorumConnectionThread-[myid=1]-2:QuorumCnxManager@513] - Have smaller server identifier, so dropping the connection: (myId:1 --> sid:3)
2020-12-09 07:04:41,141 [myid:1] - INFO  [WorkerReceiver[myid=1]:FastLeaderElection$Messenger$WorkerReceiver@389] - Notification: my state:FOLLOWING; n.sid:3, n.state:LOOKING, n.leader:3, n.round:0x1, n.peerEpoch:0x0, n.zxid:0x0, message format version:0x2, n.config version:0x0

zookeeper systemd 配置

[Unit]
Description=zookeeper
Documentation=zookeeper
After=network-online.target
Wants=network-online.target

[Service]
Environment=" "
EnvironmentFile=-/etc/default/%p
ExecStart=/storage/app/zookeeper/apache-zookeeper-3.6.2-bin/bin/zkServer.sh start-foreground
ExecReload=/storage/app/zookeeper/apache-zookeeper-3.6.2-bin/bin/zkServer.sh restart
ExecStop=/storage/app/zookeeper/apache-zookeeper-3.6.2-bin/bin/zkServer.sh stop
Restart=on-failure
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target


评论栏