1.在~/cluster/zookeeper目录下,安装3份zookeeper程序副本,分别命名为server1,server2,server3
2.执行以下命令。
cp server1/conf/zoo_sample.cfg server1/conf/zoo.cfg
3.在zoo.cfg文件中添加如下命令
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/abc/cluster/zookeeper/data/server1/data
dataLogDir=/home/abc/cluster/zookeeper/data/server1/log
clientPort=2181
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890
4.因为是伪集群,故另外两份必须如下设置。
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/abc/cluster/zookeeper/data/server2/data
dataLogDir=/home/abc/cluster/zookeeper/data/server2/log
clientPort=2182
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/abc/cluster/zookeeper/data/server3/data
dataLogDir=/home/abc/cluster/zookeeper/data/server3/log
clientPort=2183
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890
5.执行余下这些命令
mkdir -p /home/abc/cluster/zookeeper/data/server1/data
mkdir -p /home/abc/cluster/zookeeper/data/server2/data
mkdir -p /home/abc/cluster/zookeeper/data/server3/data
echo "1" > /home/abc/cluster/zookeeper/data/server1/data/myid
echo "2" > /home/abc/cluster/zookeeper/data/server2/data/myid
echo "3" > /home/abc/cluster/zookeeper/data/server3/data/myid
6.启动集群
cd ~/cluster/zookeeper
server1/bin/zkServer.sh start
server2/bin/zkServer.sh start
server3/bin/zkServer.sh start