一、参考http://www.cnblogs.com/jxwch/p/6433310.html
1.配置文件zoo.cfg,地址采用域名(如hcb.com),改为如下:
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/modules/zookeeper-3.4.9-1/data
# diff zk instance port is deff modify by hcb
clientPort=2181
# add by hcb
server.1=hcb.com:2188:3888
server.2=hcb.com:2189:3889
server.3=hcb.com:2190:3890
注意:1、不同的zookeeper实例,因为在同一机器上,所以端口要不同
2、server.1要使用域名hcb.com
2.配置文件myid
3.启动zookeeper
/opt/modules/zookeeper-3.4.9-3/bin/zkServer.sh start
4.查看zookeeper
/opt/modules/zookeeper-3.4.9-3/bin/zkServer.sh status
5.查看进程
jps
6.关闭zookeeper
/opt/modules/zookeeper-3.4.9-3/bin/zkServer.sh stop
二、常见问题整理
1、问题1:
报错:
zookeeper-3.4.9-2/bin/zkServer.sh status显示
Error contacting service. It is probably not running
或
zookeeper.out中错误日志
2019-05-19 02:44:32,642 [myid:1] - WARN [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@400] - Cannot open channel to 3 at election address localhost/127.0.0.1:3890
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
解决办法
产生上述两条Waring信息是因为zookeeper服务的每个实例都拥有全局的配置信息,他们在启动的时候需要随时随地的进行leader选举,此时server1就需要和其他两个zookeeper实例进行通信,但是,另外两个zookeeper实例还没有启动起来,因此将会产生上述所示的提示信息。当我们用同样的方式启动server2和server3后就不会再有这样的警告信息了。
2、问题2
报错:
2019-05-25 20:56:09,482 [myid:1] - INFO [WorkerReceiver[myid=1]:FastLeaderElection@600] - Notification: 1 (message format version), 1 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 1 (n.sid), 0x2 (n.peerEpoch) LOOKING (my state)
2019-05-25 20:56:09,485 [myid:1] - WARN [WorkerSender[myid=1]:QuorumCnxManager@400] - Cannot open channel to 2 at election address /192.168.175.128:3889
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
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)
at java.lang.Thread.run(Thread.java:745)
2019-05-25 20:56:09,487 [myid:1] - INFO [WorkerSender[myid=1]:QuorumPeer$QuorumServer@149] - Resolved hostname: 192.168.175.128 to address: /192.168.175.128
2019-05-25 20:56:09,487 [myid:1] - WARN [WorkerSender[myid=1]:QuorumCnxManager@400] - Cannot open channel to 3 at election address /192.168.175.128:3890
解决办法:
修改配置文件zoo.cfg,地址采用域名(如hcb.com),改为如下:
#server.1=127.0.0.1:2188:3888
#server.2=127.0.0.1:2189:3889
#server.3=127.0.0.1:2190:3890
#server.1=192.168.175.128:2188:3888
#server.2=192.168.175.128:2189:3889
#server.3=192.168.175.128:2190:3890
server.1=hcb.com:2188:3888
server.2=hcb.com:2189:3889
server.3=hcb.com:2190:3890