- 自序
- 概述
- 安装和运行 Zookeeper
- Zookeeper 开发实例
- ZooKeeper 中的组和成员
- 创建组
- 加入组
- 成员列表
- 删除分组
- Zookeeper 服务
- 数据模型 Data Model
- 操作 Operations
- 实现 Implementation
- 数据一致性 Consistency
- 会话 Sessions
- ZooKeeper 应用程序 Building Applications with ZooKeeper
- 配置服务 Configuration Service
- 坚韧的 ZooKeeper 应用 The Resilient ZooKeeper Application
- 一个稳定的配置服务 A reliable configuration service
- 生产环境中的 ZooKeeper ZooKeeper in Production
- 韧性和性能 Resilience and Performance
- 配置
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
安装和运行 Zookeeper
我们采用 standalone 模式,安装运行一个单独的 zookeeper 服务。安装前请确认您已经安装了 Java 运行环境。
我们去 Apache ZooKeeper releases page 下载 zookeeper 安装包,并解压到本地:
% tar xzf zookeeper-x.y.z.tar.gz
ZooKeeper 提供了一些可执行程序的工具,为了方便起见,我们将这些工具的路径加入到 PATH 环境变量中:
% export ZOOKEEPER_HOME=~/sw/zookeeper-x.y.z
% export PATH=$PATH:$ZOOKEEPER_HOME/bin
运行 ZooKeeper 之前我们需要编写配置文件。配置文件一般在安装目录下的 conf/zoo.cfg
。我们可以把这个文件放在 /etc/zookeeper
下,或者放到其他目录下,并在环境变量设置 ZOOCFGDIR
指向这个个目录。下面是配置文件的内容:
tickTime=2000
dataDir=/Users/tom/zookeeper
clientPort=2181
tickTime 是 zookeeper 中的基本时间单元,单位是毫秒。datadir 是 zookeeper 持久化数据存放的目录。clientPort 是 zookeeper 监听客户端连接的端口,默认是 2181.
启动命令:
% zkServer.sh start
我们通过 nc
或者 telnet
命令访问 2181
端口,通过执行 ruok(Are you OK?)命令来检查 zookeeper 是否启动成功:
% echo ruok | nc localhost 2181
imok
那么我看见 zookeeper 回答我们“I’m OK”。下表中是所有的 zookeeper 的命名,都是由 4 个字符组成。
Category | Command | Description |
---|---|---|
Server status | ruok | Prints imok if the server is running and not in an error state. |
conf | Prints the server configuration (from zoo.cfg). | |
envi | Prints the server environment, including ZooKeeper version, Java version, and other system properties. | |
srvr | Prints server statistics, including latency statistics, the number of znodes, and the server mode (standalone, leader, or follower). | |
stat | Prints server statistics and connected clients. | |
srst | Resets server statistics. | |
isro | Shows whether the server is in read-only (ro) mode (due to a network partition) or read/write mode (rw). | |
Client connections | dump | Lists all the sessions and ephemeral znodes for the ensemble. You must connect to the leader (see srvr) for this command. |
cons | Lists connection statistics for all the server’s clients. | |
crst | Resets connection statistics. | |
Watches | wchs | Lists summary information for the server’s watches. |
wchc | Lists all the server’s watches by connection. Caution: may impact server performance for a large number of watches. | |
wchp | Lists all the server’s watches by znode path. Caution: may impact server performance for a large number of watches. | |
Monitoring | mntr | Lists server statistics in Java properties format, suitable as a source for monitoring systems such as Ganglia and Nagios. |
3.5.0 以上的版本会有一个内嵌的 web 服务,通过访问 http://localhost:8080/commands
来访问以上的命令列表。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论