最近学习的微服务需要用到zookeeper,索性今天重新安装了zookeeper-3.8.0想再找找感觉。以前3.6.X版本无脑安装完成,设定好zoo.cfg就可启动,谁知道3.8.0不能无脑了,需要脑子拿出来活动一下了。
zookeeper-3.8.0安装完成一直启动不了:
[root@localhost zookeeper-3.8.0]# ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.8.0/bin/…/conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Error contacting service. It is probably not running.
首先查看了下安装根路径下的logs目录里的out日志,发现:
2022-05-15 00:09:22,833 [myid:1] - ERROR [main:o.a.z.s.ZooKeeperServerMain@86] - 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:194)
at org.apache.zookeeper.server.ZooKeeperServerMain.runFromConfig(ZooKeeperServerMain.java:155)
at org.apache.zookeeper.server.ZooKeeperServerMain.initializeAndRun(ZooKeeperServerMain.java:113)
at org.apache.zookeeper.server.ZooKeeperServerMain.main(ZooKeeperServerMain.java:68)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:141)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:91)
Caused by: java.io.IOException: Failed to bind to /0.0.0.0:8080
at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:349)
at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:310)
at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:234)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
at org.eclipse.jetty.server.Server.doStart(Server.java:401)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
at org.apache.zookeeper.server.admin.JettyAdminServer.start(JettyAdminServer.java:185)
... 5 common frames omitted
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.openAcceptChannel(ServerConnector.java:344)
... 12 common frames omitted
Unable to start AdminServer, exiting abnormally
一眼看到 端口:8080我就嘀咕了下,难不成,zookeeper自己配启动容器了?找了下网上的资料发现,果真!zookeeper还真的自己搞了一个简易应用服务器。看一下zookeeper的lib目录,出现了一些jetty的jar,官方文档中也出现了关于Admin的配置项,
admin.enableServer
(Java system property: zookeeper.admin.enableServer)
Set to "false" to disable the AdminServer. By default the AdminServer is enabled.
admin.serverPort
(Java system property: zookeeper.admin.serverPort)
The port the embedded Jetty server listens on. Defaults to 8080.
admin.commandURL
(Java system property: zookeeper.admin.commandURL)
The URL for listing and issuing commands relative to the root URL. Defaults to "/commands".
于是,我在zoo.cfg中加了admin.serverPort=8765
启动!
记录完毕,开搞微服务!