启动zookeeper报错java.net.ConnectException: Connection refused

在服务器上启动zookeeper在zookeeper启动时遇到的,输入命令 “ ./zkServer.sh start ” 启动后,以为启动成功,运行项目提供方代码报错java.net.ConnectException: Connection refused

启动zookeeper报错java.net.ConnectException: Connection refused_第1张图片
查看状态:

./zkServer.sh status

启动zookeeper报错java.net.ConnectException: Connection refused_第2张图片

查看日志:

./zkServer.sh start-foreground

错误信息:

ERROR [main:ZooKeeperServerMain@79] - 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

java.net.BindException: Address already in use
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:433)
    at sun.nio.ch.Net.bind(Net.java:425)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)

Caused by: java.net.BindException: Address already in use
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:433)
    at sun.nio.ch.Net.bind(Net.java:425)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
    at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:321)
    at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
    at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.server.Server.doStart(Server.java:366)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.apache.zookeeper.server.admin.JettyAdminServer.start(JettyAdminServer.java:103)
    ... 5 more



发现8080端口被占用,查阅Zookeeper的官方文档,发现这是Zookeeper3.5.5的新特性:

Zookeeper AdminServer,默认使用8080端口,它的配置属性如下:
启动zookeeper报错java.net.ConnectException: Connection refused_第3张图片

我们可以修改在zoo.cfg中修改AdminServer的端口:
启动zookeeper报错java.net.ConnectException: Connection refused_第4张图片

修改完成后,在此启动zookeeper服务器,如下图,即为启动成功:
启动zookeeper报错java.net.ConnectException: Connection refused_第5张图片

你可能感兴趣的:(解困系列)