欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-07-07 14:47:38
...

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

启动zookeeper报错java.net.ConnectException: Connection refused
查看状态:

./zkServer.sh status

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

查看日志:

./zkServer.sh start-foreground

错误信息:

ERROR [main:aaa@qq.com] - 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

我们可以修改在zoo.cfg中修改AdminServer的端口:
启动zookeeper报错java.net.ConnectException: Connection refused

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