Docker搭建Zookeeper集群问题总结

使用docker-compose搭建zk集群遇到的一些问题及解决方案

services:
  zoo1:
    image: zookeeper
    restart: always
    hostname: zoo1
    container_name: zookeeper_1
    #domainname: 
    ports:
      - 2181:2181
    volumes:
      - /home/data/test/docker:/data
    environment:
      ZOO_MY_ID: 1
      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888

  zoo2:
    image: zookeeper
    restart: always
    hostname: zoo2
    container_name: zookeeper_2
    ports:
      - 2182:2181
    volumes:
      - /home/data/test/docker:/data
    environment:
      ZOO_MY_ID: 2
      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888

  zoo3:
    image: zookeeper
    restart: always
    hostname: zoo3
    container_name: zookeeper_3
    ports:
      - 2183:2181
    volumes:
      - /home/data/test/docker:/data
    environment:
      ZOO_MY_ID: 3
      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
Docker-compose.yml

这是从网上随便找了一个集群搭建的命令,执行 docker-compose -f Docker-compose.yml up -d  报错

 

 1 leader:1, n.round:0x1, n.peerEpoch:0x0, n.zxid:0x0, message format version:0x2, n.config version:0x0
 2 zookeeper_1 | 2021-11-03 03:15:19,264 [myid:1] - WARN  [QuorumConnectionThread-[myid=1]-1:QuorumCnxManager@401] - Cannot open channel to 2 at election address zoo2/172.19.0.4:3888
 3 zookeeper_1 | java.net.ConnectException: Connection refused (Connection refused)
 4 zookeeper_1 |     at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
 5 zookeeper_1 |     at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
 6 zookeeper_1 |     at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
 7 zookeeper_1 |     at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
 8 zookeeper_1 |     at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
 9 zookeeper_1 |     at java.base/java.net.Socket.connect(Unknown Source)
10 zookeeper_1 |     at org.apache.zookeeper.server.quorum.QuorumCnxManager.initiateConnection(QuorumCnxManager.java:384)
11 zookeeper_1 |     at org.apache.zookeeper.server.quorum.QuorumCnxManager$QuorumConnectionReqThread.run(QuorumCnxManager.java:458)
12 zookeeper_1 |     at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
13 zookeeper_1 |     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
14 zookeeper_1 |     at java.base/java.lang.Thread.run(Unknown Source)
15 zookeeper_1 | 2021-11-03 03:15:19,264 [myid:1] - WARN  [QuorumConnectionThread-[myid=1]-2:QuorumCnxManager@401] - Cannot open channel to 3 at election address zoo3/172.19.0.3:3888
16 zookeeper_1 | java.net.ConnectException: Connection refused (Connection refused)
17 zookeeper_1 |     at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
18 zookeeper_1 |     at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
19 zookeeper_1 |     at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
20 zookeeper_1 |     at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
21 zookeeper_1 |     at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
22 zookeeper_1 |     at java.base/java.net.Socket.connect(Unknown Source)
23 zookeeper_1 |     at org.apache.zookeeper.server.quorum.QuorumCnxManager.initiateConnection(QuorumCnxManager.java:384)
24 zookeeper_1 |     at org.apache.zookeeper.server.quorum.QuorumCnxManager$QuorumConnectionReqThread.run(QuorumCnxManager.java:458)
25 zookeeper_1 |     at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
26 zookeeper_1 |     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
27 zookeeper_1 |     at java.base/java.lang.Thread.run(Unknown Source)
28 zookeeper_3 | 2021-11-03 03:15:19,373 [myid:1] - ERROR [ListenerHandler-zoo1/172.19.0.2:3888:QuorumCnxManager$Listener$ListenerHandler@1094] - Exception while listening
29 zookeeper_3 | java.net.BindException: Cannot assign requested address (Bind failed)
30 zookeeper_3 |     at java.base/java.net.PlainSocketImpl.socketBind(Native Method)
31 zookeeper_3 |     at java.base/java.net.AbstractPlainSocketImpl.bind(Unknown Source)
32 zookeeper_3 |     at java.base/java.net.ServerSocket.bind(Unknown Source)
33 zookeeper_3 |     at java.base/java.net.ServerSocket.bind(Unknown Source)
34 zookeeper_3 |     at org.apache.zookeeper.server.quorum.QuorumCnxManager$Listener$ListenerHandler.createNewServerSocket(QuorumCnxManager.java:1136)
35 zookeeper_3 |     at org.apache.zookeeper.server.quorum.QuorumCnxManager$Listener$ListenerHandler.acceptConnections(QuorumCnxManager.java:1065)
36 zookeeper_3 |     at org.apache.zookeeper.server.quorum.QuorumCnxManager$Listener$ListenerHandler.run(QuorumCnxManager.java:1034)
37 zookeeper_3 |     at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
38 zookeeper_3 |     at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
39 zookeeper_3 |     at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
40 zookeeper_3 |     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
41 zookeeper_3 |     at java.base/java.lang.Thread.run(Unknown Source)
42 zookeeper_2 | 2021-11-03 03:15:19,382 [myid:1] - ERROR [ListenerHandler-zoo1/172.19.0.2:3888:QuorumCnxManager$Listener$ListenerHandler@1094] - Exception while listening
43 zookeeper_2 | java.net.BindException: Cannot assign requested address (Bind failed)
44 zookeeper_2 |     at java.base/java.net.PlainSocketImpl.socketBind(Native Method)
45 zookeeper_2 |     at java.base/java.net.AbstractPlainSocketImpl.bind(Unknown Source)
46 zookeeper_2 |     at java.base/java.net.ServerSocket.bind(Unknown Source)
47 zookeeper_2 |     at java.base/java.net.ServerSocket.bind(Unknown Source)
48 zookeeper_2 |     at org.apache.zookeeper.server.quorum.QuorumCnxManager$Listener$ListenerHandler.createNewServerSocket(QuorumCnxManager.java:1136)
49 zookeeper_2 |     at org.apache.zookeeper.server.quorum.QuorumCnxManager$Listener$ListenerHandler.acceptConnections(QuorumCnxManager.java:1065)
50 zookeeper_2 |     at org.apache.zookeeper.server.quorum.QuorumCnxManager$Listener$ListenerHandler.run(QuorumCnxManager.java:1034)
51 zookeeper_2 |     at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
52 zookeeper_2 |     at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
53 zookeeper_2 |     at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
54 zookeeper_2 |     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
55 zookeeper_2 |     at java.base/java.lang.Thread.run(Unknown Source)
错误详情

错误原因,直接看报错好像是hostname解析不到,ip

BindException: Cannot assign requested address (Bind failed)

于是乎我就直接将hostname去掉,环境变量配置成172.17.0.2 ~ 172.17.0.4启动还是不好使。

错误原因:volume配置问题。

将volume去掉,或者配置成  ./log/txt.log:/txt.lg就可以了。

=================================================

其实我的计划是将本地当前挂载到docker上容器中去,但目前我只找到了将本地文件copy过去的方法。后续试下利用cmd先在容器中创建目录,然后在挂载目录能不能好使,我怀疑是/data目录不能默认帮我创建

 

posted @ 2021-11-03 11:17  小祥工作室  阅读(722)  评论(0编辑  收藏  举报