当我们在启动ZooKeeper时如果报错如下:
2021-04-26 17:42:37,967 [myid:3] - INFO [main:NIOServerCnxnFactory@686] - binding to port 0.0.0.0/0.0.0.0:2181 2021-04-26 17:42:37,968 [myid:3] - ERROR [main:QuorumPeerMain@101] - Unexpected exception, exiting abnormally 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 sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:67) at org.apache.zookeeper.server.NIOServerCnxnFactory.configure(NIOServerCnxnFactory.java:687) at org.apache.zookeeper.server.quorum.QuorumPeerMain.runFromConfig(QuorumPeerMain.java:148) at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:123) at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:82)
说明ZooKeeper中有端口被占用了,我们这里涉及到的端口是2181
端口,通过如下指令查看哪个进程占用了该端口:
netstat -ano | findstr "2181"
如果没有netstat指令,可以执行如下指令安装后再去查看:
yum -y install net-tools
然后找到该进程的id,执行如下指令结束该进程即可:
kill -9 进程pid
最后再去启动ZooKeeper发现就ok了