1. 下载解压zookeeper
(1)下载地址:略
(2)解压:略
要注意的是,你打算在你的单机上建立几个ZooKeeper服务器,你就建立几个目录,然后在每个目录里都解压zookeeper。
2. 部署规模为3的单机伪机群
(1)server0
新建目录data:/home/michael/opt/zookeeper/server0/zookeeper/data
新建目录logs:/home/michael/opt/zookeeper/server0/zookeeper/logs
新建文件myid:/home/michael/opt/zookeeper/server0/zookeeper/data/myid
内容如下:
Html代码
- 0
新建文件zoo.cfg:/home/michael/opt/zookeeper/server0/zookeeper/conf/zoo.cfg
内容如下:
Plain代码
1. tickTime=2000
2. initLimit=5
3. syncLimit=2
4. dataDir=/home/michael/opt/zookeeper/server0/zookeeper/data
5. dataLogDir=/home/michael/opt/zookeeper/server0/zookeeper/logs
6. clientPort=4180
7. server.0=127.0.0.1:8880:7770
8. server.1=127.0.0.1:8881:7771
9. server.2=127.0.0.1:8882:7772
(2)server1
新建目录data:/home/michael/opt/zookeeper/server1/zookeeper/data
新建目录logs:/home/michael/opt/zookeeper/server1/zookeeper/logs
新建文件myid:/home/michael/opt/zookeeper/server1/zookeeper/data/myid
内容如下:
Html代码
1. 1
新建文件zoo.cfg:/home/michael/opt/zookeeper/server1/zookeeper/conf/zoo.cfg
内容如下:
Plain代码
1. tickTime=2000
2. initLimit=5
3. syncLimit=2
4. dataDir=/home/michael/opt/zookeeper/server1/zookeeper/data
5. dataLogDir=/home/michael/opt/zookeeper/server1/zookeeper/logs
6. clientPort=4181
7. server.0=127.0.0.1:8880:7770
8. server.1=127.0.0.1:8881:7771
9. server.2=127.0.0.1:8882:7772
(3)server2
新建目录data:/home/michael/opt/zookeeper/server2/zookeeper/data
新建目录logs:/home/michael/opt/zookeeper/server2/zookeeper/logs
新建文件myid:/home/michael/opt/zookeeper/server2/zookeeper/data/myid
内容如下:
Html代码
1. 2
内容如下:
Plain代码
1. tickTime=2000
2. initLimit=5
3. syncLimit=2
4. dataDir=/home/michael/opt/zookeeper/server2/zookeeper/data
5. dataLogDir=/home/michael/opt/zookeeper/server2/zookeeper/logs
6. clientPort=4182
7. server.0=127.0.0.1:8880:7770
8. server.1=127.0.0.1:8881:7771
9. server.2=127.0.0.1:8882:7772
3.启动ZooKeeper伪机群的所有服务器
分别进入三个服务器的/zookeeper/bin目录下,启动服务。
Html代码
1. ./zkServer.sh start
4. 接入客户端
进入任意一个服务器的zookeeper/bin目录下,启动一个客户端,接入服务。
Plain代码
1. ./zkCli.sh –server 127.0.0.1:4181
相关的命令,可以通过输入help来查看。
Plain代码
help