拷贝以前的虚拟机的zookeeper到新的虚拟机后,执行zkServer.sh start后,jps查看有zookeeper进程,但查看状态时显示:
[root@hadoop03 zookeeper-3.4.7]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/software/zookeeper-3.4.7/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
查看zookeeper-3.4.7/bin/zookeeper.out文件,显示:
2019-02-13 23:11:26,716 [myid:] - INFO [main:QuorumPeerConfig@103] - Reading configuration from: /home/software/zookeeper-3.4.7/bin/../conf/zoo.cfg
2019-02-13 23:11:26,737 [myid:] - INFO [main:QuorumPeer$QuorumServer@149] - Resolved hostname: 192.168.195.131 to address: /192.168.195.131
2019-02-13 23:11:26,737 [myid:] - INFO [main:QuorumPeer$QuorumServer@149] - Resolved hostname: 192.168.195.130 to address: /192.168.195.130
2019-02-13 23:11:26,738 [myid:] - INFO [main:QuorumPeer$QuorumServer@149] - Resolved hostname: 192.168.195.128 to address: /192.168.195.128
2019-02-13 23:11:26,738 [myid:] - INFO [main:QuorumPeer$QuorumServer@149] - Resolved hostname: 192.168.195.132 to address: /192.168.195.132
2019-02-13 23:11:26,738 [myid:] - INFO [main:QuorumPeerConfig@331] - Defaulting to majority quorums
2019-02-13 23:11:26,749 [myid:1] - INFO [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2019-02-13 23:11:26,750 [myid:1] - INFO [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2019-02-13 23:11:26,750 [myid:1] - INFO [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2019-02-13 23:11:26,767 [myid:1] - INFO [main:QuorumPeerMain@127] - Starting quorum peer
2019-02-13 23:11:26,782 [myid:1] - INFO [main:NIOServerCnxnFactory@89] - binding to port 0.0.0.0/0.0.0.0:2181
2019-02-13 23:11:26,791 [myid:1] - INFO [main:QuorumPeer@1019] - tickTime set to 2000
2019-02-13 23:11:26,791 [myid:1] - INFO [main:QuorumPeer@1039] - minSessionTimeout set to -1
2019-02-13 23:11:26,791 [myid:1] - INFO [main:QuorumPeer@1050] - maxSessionTimeout set to -1
2019-02-13 23:11:26,791 [myid:1] - INFO [main:QuorumPeer@1065] - initLimit set to 10
2019-02-13 23:11:26,807 [myid:1] - INFO [main:FileSnap@83] - Reading snapshot /home/software/zookeeper-3.4.7/tmp/version-2/snapshot.1b0000000e
2019-02-13 23:11:27,046 [myid:1] - INFO [ListenerThread:QuorumCnxManager$Listener@534] - My election bind port: /192.168.195.128:3888
2019-02-13 23:11:27,046 [myid:1] - ERROR [/192.168.195.128:3888:QuorumCnxManager$Listener@547] - Exception while listening
java.net.BindException: 无法指定被请求的地址 (Bind failed)
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387)
at java.net.ServerSocket.bind(ServerSocket.java:375)
at java.net.ServerSocket.bind(ServerSocket.java:329)
at org.apache.zookeeper.server.quorum.QuorumCnxManager$Listener.run(QuorumCnxManager.java:537)
2019-02-13 23:11:27,061 [myid:1] - INFO [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumPeer@774] - LOOKING
2019-02-13 23:11:27,062 [myid:1] - INFO [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:FastLeaderElection@818] - New election. My id = 1, proposed zxid=0x1c00000fb0
2019-02-13 23:11:27,067 [myid:1] - INFO [WorkerReceiver[myid=1]:FastLeaderElection@600] - Notification: 1 (message format version), 1 (n.leader), 0x1c00000fb0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 1 (n.sid), 0x1c (n.peerEpoch) LOOKING (my state)
2019-02-13 23:11:28,048 [myid:1] - INFO [/192.168.195.128:3888:QuorumCnxManager$Listener@534] - My election bind port: /192.168.195.128:3888
2019-02-13 23:11:28,048 [myid:1] - ERROR [/192.168.195.128:3888:QuorumCnxManager$Listener@547] - Exception while listening
java.net.BindException: 无法指定被请求的地址 (Bind failed)
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387)
at java.net.ServerSocket.bind(ServerSocket.java:375)
at java.net.ServerSocket.bind(ServerSocket.java:329)
at org.apache.zookeeper.server.quorum.QuorumCnxManager$Listener.run(QuorumCnxManager.java:537)
2019-02-13 23:11:29,049 [myid:1] - INFO [/192.168.195.128:3888:QuorumCnxManager$Listener@534] - My election bind port: /192.168.195.128:3888
2019-02-13 23:11:29,049 [myid:1] - ERROR [/192.168.195.128:3888:QuorumCnxManager$Listener@547] - Exception while listening
java.net.BindException: 无法指定被请求的地址 (Bind failed)
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387)
at java.net.ServerSocket.bind(ServerSocket.java:375)
at java.net.ServerSocket.bind(ServerSocket.java:329)
at org.apache.zookeeper.server.quorum.QuorumCnxManager$Listener.run(QuorumCnxManager.java:537)
2019-02-13 23:11:30,050 [myid:1] - INFO [/192.168.195.128:3888:QuorumCnxManager$Listener@560] - Leaving listener
2019-02-13 23:11:30,050 [myid:1] - ERROR [/192.168.195.128:3888:QuorumCnxManager$Listener@562] - As I'm leaving the listener thread, I won't be able to participate in leader election any longer: /192.168.195.128:3888
2019-02-13 23:11:30,071 [myid:1] - WARN [WorkerSender[myid=1]:QuorumCnxManager@400] - Cannot open channel to 2 at election address /192.168.195.130:3888
java.net.NoRouteToHostException: 没有到主机的路由 (Host unreachable)
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:589)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:381)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:354)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:452)
at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:433)
原因是,之前的集群ip是192.168.195.128/130/131/132 ; 而现在的集群ip是192.168.195.134/135/136,故修改zookeeper-3.4.7/conf/zoo.cfg中配置的ip信息:
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/home/software/zookeeper-3.4.7/data
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
server.1=hadoop01:2888:3888
server.2=hadoop02:2888:3888
#server.3=192.168.195.131:2888:3888:observer
server.3=hadoop03:2888:3888
又因为是拷贝的一台中的zk,所有需要修改另外两台的myid文件,内容分别是1,2,3;myid文件在zoo.cfg中配置的dataDir的路径/home/software/zookeeper-3.4.7/data里面.
使用kill -9 pid 杀死原来的zk进程,重启zk后,zk集群启动正常.