打开一个码头Zookeeper集装箱的端口

cigdeys3  于 2022-12-09  发布在  Apache
关注(0)|答案(1)|浏览(228)

我要在我的集装箱上安装Zookeeper。
我所做的是:

root@46966b33c3a1:/opt:> wget https://downloads.apache.org/zookeeper/zookeeper-3.6.2/apache-zookeeper-3.6.2-bin.tar.gz
root@46966b33c3a1:/opt:> tar zxf apache-zookeeper-3.6.2-bin.tar.gz
root@46966b33c3a1:/opt:> cd apache-zookeeper-3.6.2-bin
root@46966b33c3a1:/opt/apache-zookeeper-3.6.2-bin:> cp conf/zoo_sample.cfg conf/zoo.cfg
root@46966b33c3a1:/opt/apache-zookeeper-3.6.2-bin:> vi conf/zoo.cfg
root@46966b33c3a1:/opt/apache-zookeeper-3.6.2-bin:> ./bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/apache-zookeeper-3.6.2-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

zoo.cfg

tickTime=2000
dataDir=/opt/apache-zookeeper-3.6.2-bin/data
clientPort=2181
initLimit=5
syncLimit=2

看起来zk服务器启动没有问题。
但是,当我尝试连接到zk CLI时,出现错误:

2021-02-09 22:59:16,920 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1167] - Opening socket connection to server localhost/127.0.0.1:2181.
2021-02-09 22:59:16,921 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1169] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2021-02-09 22:59:17,001 [myid:localhost:2181] - WARN  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1285] - Session 0x0 for sever localhost/127.0.0.1:2181, Closing socket connection. Attempting reconnect except it is a SessionExpiredException.
java.net.ConnectException: Connection refused
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
    at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:344)
    at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1275)

所以,我检查了2181端口的连接。

root@46966b33c3a1:/opt/apache-zookeeper-3.6.2-bin:> telnet localhost 2181
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
Trying ::1...
telnet: connect to address ::1: Network is unreachable

root@46966b33c3a1:/opt/apache-zookeeper-3.6.2-bin:> hostname -i
172.17.0.2
root@46966b33c3a1:/opt/apache-zookeeper-3.6.2-bin:> telnet 172.17.0.2 2181
Trying 172.17.0.2...
telnet: connect to address 172.17.0.2: Connection refused

连接被拒绝。
如何解决此问题?

swvgeqrz

swvgeqrz1#

您可以使用zookeeper official docker image。您可以使用docker-compose代替在docker中手动安装zookeeper。以下是一个docker-compose文件示例。您可以根据需要修改文档中的其他配置。

version: '3.9'

services:
  zoo1:
    image: zookeeper
    restart: always
    hostname: zoo1
    ports:
      - 2181:2181
    environment:
      ZOO_MY_ID: 1
      ZOO_SERVERS: server.1=0.0.0.0:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
      ZOO_TICK_TIME: 2000
      ZOO_INIT_LIMIT: 5
      ZOO_SYNC_LIMIT: 2

  zoo2:
    image: zookeeper
    restart: always
    hostname: zoo2
    ports:
      - 2182:2181
    environment:
      ZOO_MY_ID: 2
      ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=0.0.0.0:2888:3888;2181 server.3=zoo3:2888:3888;2181
      ZOO_TICK_TIME: 2000
      ZOO_INIT_LIMIT: 5
      ZOO_SYNC_LIMIT: 2

  zoo3:
    image: zookeeper
    restart: always
    hostname: zoo3
    ports:
      - 2183:2181
    environment:
      ZOO_MY_ID: 3
      ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=0.0.0.0:2888:3888;2181
      ZOO_TICK_TIME: 2000
      ZOO_INIT_LIMIT: 5
      ZOO_SYNC_LIMIT: 2

相关问题