技术共享

Windows 安装Zookeeper

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

安装

下载地址:Apache ZooKeeper

我下载的版本:zookeeper-3.4.12

下载后,解压

配置

1、 在D:zookeeper-3.4.12文件夹中创建一个“data”文件夹和“log”文件夹

2、 复制zoo_sample.cfg,改名:zoo.cfg

修改zoo.cfg文件

  1. # The number of milliseconds of each tick
  2. tickTime=2000
  3. # The number of ticks that the initial
  4. # synchronization phase can take
  5. initLimit=10
  6. # The number of ticks that can pass between
  7. # sending a request and getting an acknowledgement
  8. syncLimit=5
  9. # the directory where the snapshot is stored.
  10. # do not use /tmp for storage, /tmp here is just
  11. # example sakes.
  12. #dataDir=/tmp/zookeeper
  13. dataDir=D:zookeeper-3.4.12data
  14. dataLogDir=D:zookeeper-3.4.12log
  15. # the port at which the clients will connect
  16. clientPort=2181
启动

进入目录:D:zookeeper-3.4.12bin

1、执行zkServer.cmd

2、执行zkCli.cmd

  1. #连接本地zk
  2. zkCli.cmd
  3. #链接远程zk
  4. zkCli.cmd -server ip:port
简单用法

在zkCli.cmd上操作

1. 创建节点

 create /test "my_data"

节点:/test

值:my_data

注意:在zk创建节点,必须要以"/"开头,否则会报错:Command failed: java.lang.IllegalArgumentException: Path must start with / character

2. 获取节点

get /test

3. 修改节点

 set /test "abc"

4. 创建子节点

create /test/child "child"

5. 查看子节点

ls /test

6. 删除节点

delete /test/child