Windows 系统下载安装 ZooKeeper

本文详细介绍了在Windows系统中下载和安装Apache ZooKeeper 3.4.14版本的全过程,包括从官网下载、解压安装、配置zoo.cfg文件及运行ZooKeeper服务的步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Windows 系统下载安装 ZooKeeper

这里演示 Apache ZooKeeper 3.4.14 版本的下载与安装

1. 进入官网下载 ZooKeeper

ZooKeeper 官网地址: https://zookeeper.apache.org/

点击上面官网链接进入官网

image-20200715091703738跳转页面后,点击下载

image-20200715093033338

image-20200715093147742

2. Zookeeper 安装

  1. 下载完后直接解压,解压后目录如下:

    image-20200715093811917

  2. 创建一个 data 文件夹和 log 文件夹

    image-20200715093508621

  3. 进入 config 文件夹,将 zoo_sample.cfg 复制一份,并重命名 zoo.cfg

    image-20200715094115465

  4. 修改 zoo.cfg 内的配置信息

    dataDir 和 dataLogDir 根据自己的真实路径填写。就是我们刚刚创建的 data 和 log 文件夹的位置

    image-20200715094354754

    # The number of milliseconds of each tick
    tickTime=2000
    # The number of ticks that the initial 
    # synchronization phase can take
    initLimit=10
    # The number of ticks that can pass between 
    # sending a request and getting an acknowledgement
    syncLimit=5
    # the directory where the snapshot is stored.
    # do not use /tmp for storage, /tmp here is just 
    # example sakes.
    dataDir=D:\\Code\\tool\\java\\zookeeper-3.4.14\\zookeeper-3.4.14\\data
    dataLogDir=D:\\Code\\tool\\java\\zookeeper-3.4.14\\zookeeper-3.4.14\\log
    # the port at which the clients will connect
    clientPort=2181
    # the maximum number of client connections.
    # increase this if you need to handle more clients
    #maxClientCnxns=60
    #
    # Be sure to read the maintenance section of the 
    # administrator guide before turning on autopurge.
    #
    # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
    #
    # The number of snapshots to retain in dataDir
    #autopurge.snapRetainCount=3
    # Purge task interval in hours
    # Set to "0" to disable auto purge feature
    #autopurge.purgeInterval=1
    

3. 运行 ZooKeeper

  1. 进入 bin 目录,启动 zkServer.cmd

    image-20200715094708467

    如果闪退的话,就代表启动失败,可能是我们刚刚配置错误了。

    编辑 zkServer.cmd 文件,增加 @pause 让它报错时停下来,然后根据报错百度查询解决方案。

    java.io.IOException: Unable to create data directory XXX 代表是文件路径错误了,检查 dataDir 和 dataLogDir 的路径

    image-20200715095005608

    @echo off
    REM Licensed to the Apache Software Foundation (ASF) under one or more
    REM contributor license agreements.  See the NOTICE file distributed with
    REM this work for additional information regarding copyright ownership.
    REM The ASF licenses this file to You under the Apache License, Version 2.0
    REM (the "License"); you may not use this file except in compliance with
    REM the License.  You may obtain a copy of the License at
    REM
    REM     http://www.apache.org/licenses/LICENSE-2.0
    REM
    REM Unless required by applicable law or agreed to in writing, software
    REM distributed under the License is distributed on an "AS IS" BASIS,
    REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    REM See the License for the specific language governing permissions and
    REM limitations under the License.
    
    setlocal
    call "%~dp0zkEnv.cmd"
    
    set ZOOMAIN=org.apache.zookeeper.server.quorum.QuorumPeerMain
    echo on
    call %JAVA% "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%" %*
    @pause
    endlocal
    
  2. 运行成功

    image-20200715095250155

### 如何在 Windows 系统上安装和配置 ZooKeeper #### 下载 ZooKeeper 安装包 从官方站点或其他可信资源下载 ZooKeeper 的最新稳定版本。可以访问 Apache 官方存档页面获取安装包链接[^4]。 #### 解压安装包至目标路径 将下载好的压缩文件解压到指定目录,例如 `C:\zookeeper` 或其他适合的位置。此操作完成后会生成一个包含 ZooKeeper 所需文件的根目录[^3]。 #### 创建数据存储文件夹 为了确保 ZooKeeper 能够正常运行,在其安装目录下手动建立用于保存数据的日志文件夹。通常命名为 `data` 和 `datalog` 并放置于安装主目录内。 #### 配置 ZooKeeper 设置文件 进入解压后的 ZooKeeper 文件夹中的 `conf` 子目录,找到模板配置文件 `zoo_sample.cfg`,将其复制并重命名为 `zoo.cfg`。这是 ZooKeeper 的核心配置文件。 以下是默认情况下可能需要调整的一些重要参数: ```properties tickTime=2000 initLimit=10 syncLimit=5 dataDir=C:/zookeeper/data clientPort=2181 ``` 其中: - **tickTime**: 基础时间单位 (毫秒),心跳间隔。 - **dataDir**: 数据库快照位置以及事务日志存放处。 - **clientPort**: 接收客户端请求的服务端口,默认为 2181。 完成上述更改之后保存该文档以便后续使用。 #### 添加环境变量支持 为了让命令行工具能够识别 ZooKeeper 可执行脚本所在位置,有必要设置两个新的系统级环境变量: 1. 新增名为 `ZOOKEEPER_HOME` 的全局变量指向实际安装路径; 2. 将 `%ZOOKEEPER_HOME%\bin` 追加进现有的 PATH 中去。 #### 启动与验证服务状态 一切准备就绪以后就可以尝试启动服务器实例了。打开一个新的 CMD 终端窗口输入如下指令来激活后台进程: ```bash zkServer.cmd ``` 如果没有任何错误提示,则说明已经成功部署了一个单节点模式下的 ZooKeeper 实例。可以通过另一个终端测试连接情况: ```bash zkCli.cmd -server 127.0.0.1:2181 ``` 此时应该可以看到交互式的控制台界面显示出来表示连通性良好。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值