zkServer 命令位于 Zookeeper 安装目录的 bin 子目录,该命令用来启动、停止 Zookeeper 服务。
Windows:zkServer.cmd
Unix/Linux:zkServer.sh
zkServer 命令提供了如下子命令,用来控制 Zookeeper 服务:
启动 ZK 服务: sh bin/zkServer.sh start
查看 ZK 服务状态: sh bin/zkServer.sh status
停止 ZK 服务: sh bin/zkServer.sh stop
重启 ZK 服务: sh bin/zkServer.sh restart
示例:
# 启动服务 hxstrive@localhost:~/apache-zookeeper-3.9.1-bin/bin$ ./zkServer.sh start /usr/bin/java ZooKeeper JMX enabled by default Using config: /home/hxstrive/apache-zookeeper-3.9.1-bin/bin/../conf/zoo.cfg Starting zookeeper ... STARTED # 查看服务状态 hxstrive@localhost:~/apache-zookeeper-3.9.1-bin/bin$ ./zkServer.sh status /usr/bin/java ZooKeeper JMX enabled by default Using config: /home/hxstrive/apache-zookeeper-3.9.1-bin/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Client SSL: false. Mode: standalone # 重启服务 hxstrive@localhost:~/apache-zookeeper-3.9.1-bin/bin$ ./zkServer.sh restart /usr/bin/java ZooKeeper JMX enabled by default Using config: /home/hxstrive/apache-zookeeper-3.9.1-bin/bin/../conf/zoo.cfg /usr/bin/java ZooKeeper JMX enabled by default Using config: /home/hxstrive/apache-zookeeper-3.9.1-bin/bin/../conf/zoo.cfg Stopping zookeeper ... STOPPED /usr/bin/java ZooKeeper JMX enabled by default Using config: /home/hxstrive/apache-zookeeper-3.9.1-bin/bin/../conf/zoo.cfg Starting zookeeper ... STARTED # 停止服务 hxstrive@localhost:~/apache-zookeeper-3.9.1-bin/bin$ ./zkServer.sh stop /usr/bin/java ZooKeeper JMX enabled by default Using config: /home/hxstrive/apache-zookeeper-3.9.1-bin/bin/../conf/zoo.cfg Stopping zookeeper ... STOPPED