Error contacting service. It is probably not running.

总体思想是:首先查看是否已经启动,其次查看日志分析原因,接着检查配置文件是否正确,重新启动试试,最后再排查网络原因(防火墙等)。

使用命令 ./bin/zkServer.sh start 启动 Zookeeper 时报错,信息如下:
在这里插入图片描述

首先可以查看日志文件 logslogs 目录和 bin 目录同级。报错:

Error: Could not find or load main class org.apache.zookeeper.server.quorum.QuorumPeerMain
Caused by: java.lang.ClassNotFoundException: org.apache.zookeeper.server.quorum.QuorumPeerMain

原因是因为启动运行的 Zookeeper 包是错误的。我们只需要重新下载对的gz就行。
Zookeeper 3.5.7 以后会有两个包,我们需要下载 apache-zookeeper-x.x.x-bin.tar.gz 包,而不是 apache-zookeeper-x.x.x.tar.gz

另外,可以通过运行启动命令 ./bin/zkServer.sh start-foreground 运行,查看启动过程中发生的异常信息。通过异常信息具体分析去解决问题,比如有端口被占用,这个可以停止其他占用端口应用,服务访问问题,可以检查系统防火墙,确认关闭状态。

2020-05-04 23:35:46,961 [myid:] - ERROR [main:ZooKeeperServerMain@85] - Unable to start AdminServer, exiting abnormally
org.apache.zookeeper.server.admin.AdminServer$AdminServerException: Problem starting AdminServer on address 0.0.0.0, port 8080 and command URL /commands
        at org.apache.zookeeper.server.admin.JettyAdminServer.start(JettyAdminServer.java:176)
        at org.apache.zookeeper.server.ZooKeeperServerMain.runFromConfig(ZooKeeperServerMain.java:153)
        at org.apache.zookeeper.server.ZooKeeperServerMain.initializeAndRun(ZooKeeperServerMain.java:112)
        at org.apache.zookeeper.server.ZooKeeperServerMain.main(ZooKeeperServerMain.java:67)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:140)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:90)
Caused by: java.io.IOException: Failed to bind to /0.0.0.0:8080
        at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:346)
        at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:307)
        at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
        at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:231)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
        at org.eclipse.jetty.server.Server.doStart(Server.java:385)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
        at org.apache.zookeeper.server.admin.JettyAdminServer.start(JettyAdminServer.java:167)
        ... 5 more
Caused by: java.net.BindException: Address already in use
        at java.base/sun.nio.ch.Net.bind0(Native Method)
        at java.base/sun.nio.ch.Net.bind(Net.java:469)
        at java.base/sun.nio.ch.Net.bind(Net.java:458)
        at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:220)
        at java.base/sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:88)
        at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:342)
        ... 12 more
Unable to start AdminServer, exiting abnormally

上述报错信息就说明了 8080 端口被占用了,可以使用命令 netstat -tunlp | grep 8080 查看具体占用的进程,通过 kill -9 pid 关闭进程。

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐