配置伪集群
cp -a zoo_sample.cfg zoo.cfg
mkdir -p /root/kch/zkw/zookeeper/data
mkdir -p /root/kch/zkw/zookeeper/logs
# 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=/root/kch/zkw/zookeeper/data
dataLogDir=/root/kch/zkw/zookeeper/logs
# 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
tickTime=2000
dataDir=/root/kch/zkw/zookeeper/data
dataLogDir=/root/kch/zkw/zookeeper/logs
clientPort=2181
参数说明:
bin/zkServer.sh start
Server启动之后,查看zookeeper状态:
bin/zkServer.sh status
然后就可以启动client连接server了, 执行脚本:
bin/zkCli.sh -server localhost:2181
伪集群模式 所谓伪集群, 是指在单台机器中启动多个zookeeper进程, 并组成一个集群. 以启动3个zookeeper进程为例.
将zookeeper的目录拷贝2份:
|--zookeeper0
|--zookeeper1
|--zookeeper2
更改zookeeper0/conf/zoo.cfg文件为:
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/root/kch/zkw/zookeeper0/data
dataLogDir=/root/kch/zkw/zookeeper0/logs
clientPort=2180
server.0=127.0.0.1:8880:7770
server.1=127.0.0.1:8881:7771
server.2=127.0.0.1:8882:7772
新增了几个参数, 其含义如下:
参照zookeeper0/conf/zoo.cfg, 配置zookeeper1/conf/zoo.cfg, 和zookeeper2/conf/zoo.cfg文件. 只需更改dataDir, dataLogDir, clientPort参数即可.
在之前设置的dataDir中新建myid文件, 写入一个数字, 该数字表示这是第几号server. 该数字必须和zoo.cfg文件中的server.X中的X一一对应. 如果是windows可以创建myid.txt然后里边写数字,最后再修改文件格式去掉后缀 example:
echo 0 > /root/kch/zkw/zookeeper0/data/myid
/root/kch/zkw/zookeeper0/data/myid文件中写入0 /root/kch/zkw/zookeeper1/data/myid文件中写入1 /root/kch/zkw/zookeeper2/data/myid文件中写入2 分别进入/opt/zookeeper/zookeeper0/bin, /opt/zookeeper/zookeeper1/bin, /opt/zookeeper/zookeeper2/bin三个目录, 启动server. 任意选择一个server目录, 启动客户端:
bin/zkCli.sh -server localhost:2180