《zooker入门系列教程》:
1 - 如何在单机上实现ZooKeeper伪机群/伪集群部署
2 - 解读zookeeper的配置项
-----
此文是为手头没有多余机器可以尝试而又需要尝试部署机群的情况而写的,是一个入门的基础教程。
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
内容如下:
0
内容如下:
tickTime=2000 initLimit=5 syncLimit=2 dataDir=/home/michael/opt/zookeeper/server0/zookeeper/data dataLogDir=/home/michael/opt/zookeeper/server0/zookeeper/logs clientPort=4180 server.0=127.0.0.1:8880:7770 server.1=127.0.0.1:8881:7771 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
内容如下:
1
新建文件zoo.cfg:/home/michael/opt/zookeeper/server1/zookeeper/conf/zoo.cfg
内容如下:
tickTime=2000 initLimit=5 syncLimit=2 dataDir=/home/michael/opt/zookeeper/server1/zookeeper/data dataLogDir=/home/michael/opt/zookeeper/server1/zookeeper/logs clientPort=4181 server.0=127.0.0.1:8880:7770 server.1=127.0.0.1:8881:7771 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
内容如下:
2
内容如下:
tickTime=2000 initLimit=5 syncLimit=2 dataDir=/home/michael/opt/zookeeper/server2/zookeeper/data dataLogDir=/home/michael/opt/zookeeper/server2/zookeeper/logs clientPort=4182 server.0=127.0.0.1:8880:7770 server.1=127.0.0.1:8881:7771 server.2=127.0.0.1:8882:7772
分别进入三个服务器的/zookeeper/bin目录下,启动服务。
./zkServer.sh start
进入任意一个服务器的zookeeper/bin目录下,启动一个客户端,接入服务。
./zkCli.sh –server 127.0.0.1:4181
help
我在本机上的演示图如下所示: