windows下zookeeper伪集群搭建以及遇到myid文件找不到

1.下载zookeeper压缩包,解压到三个不同文件夹

windows下zookeeper伪集群搭建以及遇到myid文件找不到_第1张图片

zookeeper1、zookeeper2、zookeeper3文件夹打开后如下:

2.找到conf文件下的zoo_sample.cfg,复制后改名称为zoo.cfg

windows下zookeeper伪集群搭建以及遇到myid文件找不到_第2张图片

3.配置zoo.cfg(注意双斜杠,本机测试不加双斜杠提示找不到myid路径,因为myid存放在data文件夹下

zookeeper1的配置:

#dataDir=/tmp/zookeeper
dataDir=C:\\zookfk\\zk_cluster\\zookeeper1\\data
dataLogDir=C:\\zookfk\\zk_cluster\\zookeeper1\\log
# the port at which the clients will connect
clientPort=2181
server.1=127.0.0.1:2016:2006
server.2=127.0.0.1:2017:2007
server.3=127.0.0.1:2018:2008

zookeeper2的配置:

#dataDir=/tmp/zookeeper
dataDir=C:\\zookfk\\zk_cluster\\zookeeper2\\data
dataLogDir=C:\\zookfk\\zk_cluster\\zookeeper2\\log
# the port at which the clients will connect
clientPort=2182
server.1=127.0.0.1:2016:2006
server.2=127.0.0.1:2017:2007
server.3=127.0.0.1:2018:2008

zookeeper3的配置:

#dataDir=/tmp/zookeeper
dataDir=C:\\zookfk\\zk_cluster\\zookeeper3\\data
dataLogDir=C:\\zookfk\\zk_cluster\\zookeeper3\\log
# the port at which the clients will connect
clientPort=2183
server.1=127.0.0.1:2016:2006
server.2=127.0.0.1:2017:2007
server.3=127.0.0.1:2018:2008

4.data文件下创建myid文件

myid文件没有后缀,直接创建名字myid,内容分别为server后的数字1、 2 、 3

5.启动zookeeper

分别切换到三个zookeeper目录下的bin目录,cmd输入zkServer.cmd或者点击zkServer.cmd,启动时会报错如下:

2018-07-27 13:11:33,711 [myid:1] - WARN  [WorkerSender[myid=1]:QuorumCnxManager@382] - Cannot open channel to 3 at election address /127.0.0.1:2008
java.net.ConnectException: Connection refused: connect
        at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
        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.PlainSocketImpl.connect(PlainSocketImpl.java:172)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:589)
        at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:368)
        at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:341)
        at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:449)
        at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:430)
        at java.lang.Thread.run(Thread.java:748)

原因:zookeeper的其他节点还没有启动,当三个节点都启动后,就正常运行了。

6.检测zookeeper是否启动,jps

windows下zookeeper伪集群搭建以及遇到myid文件找不到_第3张图片

QuorumPeerMain是zookeeper启动类,有这个进程就表示启动成功

你可能感兴趣的:(集群)