好惨啊,为啥呢?单独关也不能关,排除了脚本的命令写错了这个问题。
[wangzhou@zookeeper01 zookeeper-3.5.7]$ ./bin/zkServer.sh stop ZooKeeper JMX enabled by default Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg Stopping zookeeper ... no zookeeper to stop (could not find file /home/wangzhou/Downloads/zookeeper-3.5.7/zkData/zookeeper_server.pid)
看看log。没发现啥异常。把log删除了,重新连接,再查看log。
2022-04-04 12:32:57,246 [myid:] - INFO [main:QuorumPeerConfig@135] - Reading configuration from: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg 2022-04-04 12:32:57,252 [myid:] - INFO [main:QuorumPeerConfig@387] - clientPortAddress is 0.0.0.0:2181 2022-04-04 12:32:57,252 [myid:] - INFO [main:QuorumPeerConfig@391] - secureClientPort is not set 2022-04-04 12:32:57,259 [myid:1] - INFO [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3 2022-04-04 12:32:57,260 [myid:1] - INFO [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0 2022-04-04 12:32:57,260 [myid:1] - INFO [main:DatadirCleanupManager@101] - Purge task is not scheduled. 2022-04-04 12:32:57,260 [myid:1] - INFO [main:ManagedUtil@46] - Log4j found with jmx enabled. 2022-04-04 12:32:57,269 [myid:1] - INFO [main:QuorumPeerMain@141] - Starting quorum peer 2022-04-04 12:32:57,276 [myid:1] - INFO [main:ServerCnxnFactory@135] - Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory 2022-04-04 12:32:57,278 [myid:1] - INFO [main:NIOServerCnxnFactory@673] - Configuring NIO connection handler with 10s sessionless connection timeout, 1 selector thread(s), 2 worker threads, and 64 kB direct buffers. 2022-04-04 12:32:57,282 [myid:1] - INFO [main:NIOServerCnxnFactory@686] - binding to port 0.0.0.0/0.0.0.0:2181 2022-04-04 12:32:57,282 [myid:1] - 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) ~
好家伙,原来端口被占用了,谁占用了?jps看不到呀,切换到root账号,jps发现原来这个服务在root账户上跑着呢。kill停掉,再来到用户目录启动,果然启动不了。
[wangzhou@zookeeper01 bin]$ ./zkServer.sh start ZooKeeper JMX enabled by default Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg Starting zookeeper ... ./zkServer.sh: line 158: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../logs/zookeeper-wangzhou-server-zookeeper01.out: Permission denied FAILED TO START
原因是我们把zookeeper放在普通用户的home/xxx下了,这个目录的权限默认是755。我们之前启动是用的sudo,让它跑在了root上。基础不牢,地动山摇,看来linux的基础也是不可以被忽视的。
好的,那么想办法解决下吧。我们zookeeper的权限放开吧。
[wangzhou@zookeeper03 Downloads]$ sudo chmod 777 -R zookeeper-3.5.7
测试下。
[wangzhou@zookeeper03 Downloads]$ zookeeper-3.5.7/bin/zkServer.sh start ZooKeeper JMX enabled by default Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
最后集群测试下。
[wangzhou@zookeeper01 bin]$ ./zk.sh status -------------- zookeeper01 状态 ---------------- ZooKeeper JMX enabled by default Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Error contacting service. It is probably not running. -------------- zookeeper02 状态 ---------------- ZooKeeper JMX enabled by default Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Error contacting service. It is probably not running. -------------- zookeeper03 状态 ---------------- ZooKeeper JMX enabled by default Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Error contacting service. It is probably not running. [wangzhou@zookeeper01 bin]$ ./zk.sh start -------------- zookeeper01 启动 ---------------- ZooKeeper JMX enabled by default Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg Starting zookeeper ... STARTED -------------- zookeeper02 启动 ---------------- ZooKeeper JMX enabled by default Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg Starting zookeeper ... STARTED -------------- zookeeper03 启动 ---------------- ZooKeeper JMX enabled by default Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [wangzhou@zookeeper01 bin]$ ./zk.sh status -------------- zookeeper01 状态 ---------------- ZooKeeper JMX enabled by default Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Mode: follower -------------- zookeeper02 状态 ---------------- ZooKeeper JMX enabled by default Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Mode: leader -------------- zookeeper03 状态 ---------------- ZooKeeper JMX enabled by default Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Mode: follower [wangzhou@zookeeper01 bin]$ ./zk.sh stop -------------- zookeeper01 停止 ---------------- ZooKeeper JMX enabled by default Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg Stopping zookeeper ... STOPPED -------------- zookeeper02 停止 ---------------- ZooKeeper JMX enabled by default Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg Stopping zookeeper ... STOPPED -------------- zookeeper03 停止 ---------------- ZooKeeper JMX enabled by default Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg Stopping zookeeper ... STOPPED