返回介绍

安装和运行 Zookeeper

发布于 2025-01-04 01:04:22 字数 3276 浏览 0 评论 0 收藏 0

我们采用 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 个字符组成。

CategoryCommandDescription
Server statusruokPrints imok if the server is running and not in an error state.
 confPrints the server configuration (from zoo.cfg).
 enviPrints the server environment, including ZooKeeper version, Java version, and other system properties.
 srvrPrints server statistics, including latency statistics, the number of znodes, and the server mode (standalone, leader, or follower).
 statPrints server statistics and connected clients.
 srstResets server statistics.
 isroShows whether the server is in read-only (ro) mode (due to a network partition) or read/write mode (rw).
Client connectionsdumpLists all the sessions and ephemeral znodes for the ensemble. You must connect to the leader (see srvr) for this command.
 consLists connection statistics for all the server’s clients.
 crstResets connection statistics.
WatcheswchsLists summary information for the server’s watches.
 wchcLists all the server’s watches by connection. Caution: may impact server performance for a large number of watches.
 wchpLists all the server’s watches by znode path. Caution: may impact server performance for a large number of watches.
MonitoringmntrLists 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文