2.0 Zookeeper 安装配置

约 1359 字 更新于 2026-11-18 5iyo.com

2.0 Zookeeper 安装配置

Linux 安装

zookeeper 下载地址为: https://zookeeper.apache.org/releases.html。

2.0 Zookeeper 安装配置 示意图

选择一稳定版本,本教程使用的 release 版本为3.4.14,下载并安装。

打开网址 https://www.apache.org/dyn/closer.lua/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz,看到如下界面:

2.0 Zookeeper 安装配置 示意图

选择一个下载地址,使用 wget 命令下载并安装:

Zookeeper 下载安装

$ wget https://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
$ tar -zxvf zookeeper-3.4.14.tar.gz
$ cd zookeeper-3.4.14
$ cd conf/
$ cp zoo_sample.cfg zoo.cfg
$ cd ..
$ cd bin/
$ sh zkServer.sh start

执行后,服务端启动成功:

2.0 Zookeeper 安装配置 示意图

查看服务端状态(启动单机节点):

2.0 Zookeeper 安装配置 示意图

启动客户端:

$ sh zkCli.sh

帮助命令:

ZooKeeper -server host:port cmd args

        stat path [watch]

        set path data [version]

        ls path [watch]

        delquota [-n|-b] path

        ls2 path [watch]

        setAcl path acl

        setquota -n|-b val path

        history 

        redo cmdno

        printwatches on|off

        delete path [version]

        sync path

        listquota path

        rmr path

        get path [watch]

        create [-s] [-e] path data acl

        addauth scheme auth

        quit 

        getAcl path

        close 

        connect host:port

Windows 下安装

zookeeper 下载地址为: https://zookeeper.apache.org/releases.html。

选择一个地址点击版本下载:

2.0 Zookeeper 安装配置 示意图

下载后解压:

2.0 Zookeeper 安装配置 示意图

将 conf 目录下的 zoo_sample.cfg 文件,复制一份,重命名为 zoo.cfg:

2.0 Zookeeper 安装配置 示意图

在安装目录下面新建一个空的 data 文件夹和 log 文件夹:

2.0 Zookeeper 安装配置 示意图

修改 zoo.cfg 配置文件,将 dataDir=/tmp/zookeeper 修改成 zookeeper 安装目录所在的 data 文件夹,再添加一条添加数据日志的配置(需要根据自己的安装路径修改)。

2.0 Zookeeper 安装配置 示意图

双击 zkServer.cmd 启动程序:

2.0 Zookeeper 安装配置 示意图

控制台显示 bind to port 0.0.0.0/0.0.0.0:2181,表示服务端启动成功!

2.0 Zookeeper 安装配置 示意图

双击zkCli.cmd 启动客户端

2.0 Zookeeper 安装配置 示意图

出现 Welcome to Zookeeper!,表示我们成功启动客户端。