zookeeper伪集群

1、zookeeper单节点安装
sudo cp zoo_sample.cfg zoo.cfg
cd ../bin
./zkServer.sh start


2、zookeeper伪集群
“伪分布式集群” 就是在在一台PC中启动多个ZooKeeper的实例。
“完全分布式集群” 是每台PC,启动一个ZooKeeper实例。
测试环境目录结构


zk1、zk2、zk3目录内容如下


#新建myid文件
echo "1" > /usr/local/zookeeper/zk1/myid
echo "2" > /usr/local/zookeeper/zk2/myid
echo "3" > /usr/local/zookeeper/zk3/myid


分别修改zook配置文件,conf文件目录如下

vim zoo1.cfg #修改对应的配置文件

# 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=/usr/local/zookeeper/zk1
# 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

server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890


启动
cd ../bin
./zkServer.sh start zoo1.cfg
./zkServer.sh start zoo2.cfg
./zkServer.sh start zoo3.cfg


查看leader,follower状态
./zkServer.sh status zoo1.cfg
./zkServer.sh status zoo2.cfg
./zkServer.sh status zoo3.cfg


测试
 ./zkCli.sh -server 127.0.0.1:2181
ls /
create /zk1 zk1
get /zk1

连上127.0.0.1:2182或者3都能取到在任意一台中设置的数据

可以关闭其中一台测试自动选举leader

猜你喜欢

转载自jinjzk.iteye.com/blog/2149822