下载程序
$ wget https://downloads.apache.org/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz
$ tar xvf ./apache-zookeeper-3.7.0-bin.tar.gz
启动 Server
$ cd apache-zookeeper-3.7.0-bin
$ cp conf/zoo_sample.cfg conf/zoo.cfg
$ bin/zkServer.sh start
/root/app/jdk1.8.0_291/bin/java
ZooKeeper JMX enabled by default
Using config: /root/app/zk/apache-zookeeper-3.7.0-bin/bin/.. /conf/zoo.cfg
Starting zookeeper .. . STARTED
Client 连接 Server
$ bin/zkCli.sh
/root/app/jdk1.8.0_291/bin/java
Connecting to localhost:2181
2021-07-15 23:03:06,888 [myid:] - INFO [main:Environment@98] - Client environment:zookeeper.version=3.7.0-e3704b390a6697bfdf4b0bef79e3da7a4f6bac4b, built on 2021-03-17 09:46 UTC
2021-07-15 23:03:06,891 [myid:] - INFO [main:Environment@98] - Client environment:host.name=Docker
2021-07-15 23:03:06,891 [myid:] - INFO [main:Environment@98] - Client environment:java.version=1.8.0_291
2021-07-15 23:03:06,894 [myid:] - INFO [main:Environment@98] - Client environment:java.vendor=Oracle Corporation
2021-07-15 23:03:06,894 [myid:] - INFO [main:Environment@98] - Client environment:java.home=/root/app/jdk1.8.0_291/jre
[zk: localhost:2181(CONNECTED) 3] ls /
[admin, brokers, cluster, config, consumers, controller_epoch, feature, isr_change_notification, latest_producer_id_block, log_dir_event_notification, zookeeper]
# 创建一个 znode
[zk: localhost:2181(CONNECTED) 4] create /test-znode mydata
Created /test-znode
# 查看 zookeeper 内容
[zk: localhost:2181(CONNECTED) 16] ls /
[admin, brokers, cluster, config, consumers, controller_epoch, feature, isr_change_notification, latest_producer_id_block, log_dir_event_notification, test-znode, zookeeper]
# 查看 /test-znode 值
[zk: localhost:2181(CONNECTED) 5] get /test-znode
mydata
# 覆盖 /test-znode 值
[zk: localhost:2181(CONNECTED) 6] set /test-znode newdata
# 查看 /test-znode 值
[zk: localhost:2181(CONNECTED) 7] get /test-znode
newdata
# 删除 /test-znode
[zk: localhost:2181(CONNECTED) 10] delete /test-znode
# /test-znode 已不存在
[zk: localhost:2181(CONNECTED) 11] get /test-znode
org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode for /test-znode
ZooKeeper Releases
https://downloads.apache.org/zookeeper/Zookeeper入门看这篇就够了
https://blog.youkuaiyun.com/java_66666/article/details/81015302Error: Could not find or load main class org.apache.zookeeper.server.quorum.QuorumPeerMain
https://blog.youkuaiyun.com/weixin_38388991/article/details/95585827