0
点赞
收藏
分享

微信扫一扫

Error contacting service. It is probably not running java.net.ConnectException: 拒绝连接

李雨喵 2024-11-23 阅读 19

一.报错现象

安装zookeeper集群,启动和查看状态报错

[root@elk01 ~]# zkServer.sh start

/es/softwares/jdk1.8.0_351/bin/java

ZooKeeper JMX enabled by default

Using config: /es/softwares/zk/bin/../conf/zoo.cfg

Starting zookeeper ... FAILED TO START

等待一会儿

[root@elk01 zk]# zkServer.sh status

/es/softwares/jdk1.8.0_351/bin/java

ZooKeeper JMX enabled by default

Using config: /es/softwares/zk/bin/../conf/zoo.cfg

Client port found: 2181. Client address: localhost. Client SSL: false.

Error contacting service. It is probably not running.

连接测试报错

[root@elk01 zk]# zkCli.sh

/es/softwares/jdk1.8.0_351/bin/java

Connecting to localhost:2181

......

Welcome to ZooKeeper!

2024-11-23 20:26:22,033 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):o.a.z.ClientCnxn$SendThread@1177] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181.

2024-11-23 20:26:22,033 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):o.a.z.ClientCnxn$SendThread@1179] - SASL config status: Will not attempt to authenticate using SASL (unknown error)

2024-11-23 20:26:22,042 [myid:localhost:2181] - WARN  [main-SendThread(localhost:2181):o.a.z.ClientCnxn$SendThread@1300] - Session 0x0 for server localhost/0:0:0:0:0:0:0:1:2181, Closing socket connection. Attempting reconnect except it is a SessionExpiredException.

java.net.ConnectException: 拒绝连接

at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)

at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:715)

at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:344)

at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1289)

JLine support is enabled

[zk: localhost:2181(CONNECTING) 0] 2024-11-23 20:26:23,148 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):o.a.z.ClientCnxn$SendThread@1177] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181.

2024-11-23 20:26:23,149 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):o.a.z.ClientCnxn$SendThread@1179] - SASL config status: Will not attempt to authenticate using SASL (unknown error)

2024-11-23 20:26:23,150 [myid:localhost:2181] - WARN  [main-SendThread(localhost:2181):o.a.z.ClientCnxn$SendThread@1300] - Session 0x0 for server localhost/0:0:0:0:0:0:0:1:2181, Closing socket connection. Attempting reconnect except it is a SessionExpiredException.

二.排查问题

1.未发现其他多余的进程和zk进程

[root@elk01 conf]# jps
32220 Jps
23999 Elasticsearch
[root@elk01 conf]#netstat -nlpt | grep -E "2181|2888|3888"

2.查看日志

cd /es/softwares/zk/logs
tailf -n 100 zookeeper-root-server-elk01.out

报错

2024-11-23 20:53:36,643 [myid:176] - ERROR [main:o.a.z.s.q.QuorumPeerMain@114] - Unexpected exception, exiting abnormally

java.lang.RuntimeException: My id 176 not in the peer list

at org.apache.zookeeper.server.quorum.QuorumPeer.start(QuorumPeer.java:1130)

at org.apache.zookeeper.server.quorum.QuorumPeerMain.runFromConfig(QuorumPeerMain.java:229)

at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:137)

at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:91)

3.查看配置文件 发现server.id的ID与myid的值不一致

#查看zk的配置文件
cd /es/softwares/zk/conf/
cat zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data/softwares/zk/data
dataLogDir=/data/softwares/zk/logs
clientPort=2181

server.1=192.168.77.176:2888:3888
server.2=192.168.77.177:2888:3888
server.3=192.168.77.178:2888:3888
EOF
#查看myid
cat /data/softwares/zk/data/myid 
176

三.解决问题

1.修改配置文件,使server.1的ID与myid的值一致

#创建zk的配置文件
cd /es/softwares/zk/conf/
cat >zoo.cfg<<'EOF'
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data/softwares/zk/data
dataLogDir=/data/softwares/zk/logs
clientPort=2181

server.176=192.168.77.176:2888:3888
server.177=192.168.77.177:2888:3888
server.178=192.168.77.178:2888:3888
EOF

2.再次启动查看

#启动Zookeeper服务 所有节点上执行
zkServer.sh start

#查看zk的角色状态
zkServer.sh status

注:启动后,稍等片刻,所有节点启动后,再查看状态。不然会报错Error contacting service. It is probably not running.

3.状态正常

[root@elk01 conf]# zkServer.sh status

/es/softwares/jdk1.8.0_351/bin/java

ZooKeeper JMX enabled by default

Using config: /es/softwares/zk/bin/../conf/zoo.cfg

Client port found: 2181. Client address: localhost. Client SSL: false.

Mode: follower

[root@elk02 conf]# zkServer.sh status

/es/softwares/jdk1.8.0_351/bin/java

ZooKeeper JMX enabled by default

Using config: /es/softwares/zk/bin/../conf/zoo.cfg

Client port found: 2181. Client address: localhost. Client SSL: false.

Mode: leader

举报

相关推荐

0 条评论