一、下载安装包
下载网址:https://zookeeper.apache.org/releases.html
安装之前机器上需要有jdk
二、解压缩安装包
首先通过Xftp把压缩包上传到(/usr/local)目录下,然后使用命令解压文件
tar -zxvf
三、进入文件conf目录下复制zoo_sample.cfg为zoo.cfg
cp zoo_sample.cfg zoo.cfg
四、在与bin和conf的同级目录下再创建data与log两个文件夹
五、修改zoo.cfg配置文件
vim zoo.cfg
绝对路径根据自己实际情况来写
六、设置环境变量(/etc/profile)
绝对路径根据自己实际情况来写
vim /etc/profile
export ZOOKEEPER_INSTALL=/usr/local/zookeeper/zookeeper-3.4.12/
export PATH=$PATH:$ZOOKEEPER_INSTALL/bin
七、重置配置
source /etc/profile
八、zookeeper的命令
启动
sh zkServer.sh start 或者 ./zkServer.sh start
查看zookeeper状态
sh zkServer.sh status
查看zookeeper进程
ps -aux|grep 'zookeeper'
关闭zookeeper
sh zkServer.sh stop 或者 ./zkServer.sh stop
补充一下,启动的时候,8080端口不能被占用,我今天(2020年9月19日)在虚拟机装zk的时候,启动没有报错,在查看状态的时候,报错
5723[root@192 data]# sh zkServer.sh status
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /usr/local/apache-zookeeper-3.6.1/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Error contacting service. It is probably not running.
我在网上找了一下,最后看到说是8080端口被占用的问题,可以查看日志
./zkServer.sh start-foreground
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:176)
at org.apache.zookeeper.server.ZooKeeperServerMain.runFromConfig(ZooKeeperServerMain.java:153)
at org.apache.zookeeper.server.ZooKeeperServerMain.initializeAndRun(ZooKeeperServerMain.java:112)
at org.apache.zookeeper.server.ZooKeeperServerMain.main(ZooKeeperServerMain.java:67)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:140)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:90)
Caused by: java.io.IOException: Failed to bind to /0.0.0.0:8080
at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:346)
at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:307)
at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:231)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
at org.eclipse.jetty.server.Server.doStart(Server.java:385)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
at org.apache.zookeeper.server.admin.JettyAdminServer.start(JettyAdminServer.java:167)
... 5 more
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:342)
... 12 more
Unable to start AdminServer, exiting abnormally
杀死占用8080的进程,启动,一切OK!