1.下载安装包
sudo wget -b http://archive.apache.org/dist/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz -o /opt/archive/zookeeper.download.log
2.创建数据及日志目录并修改权限
# 同时为创建3*2=6个目录
sudo mkdir /data/{zk1,zk2,zk3}/{data,logs}
# 修改权限为当前用户所有 sudo chown -R $USER:$GROUPS /data/{zk1,zk2,zk3}
3.指定myid
echo "1" > /data/zk1/data/myid echo "2" > /data/zk2/data/myid echo "3" > /data/zk3/data/myid
4.复制并修改配置文件
cp /opt/zk/conf/zoo_sample.cfg /data/zk1/zoo.cfg
5.配置文件
# 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. # 存储快照的目录,不要使用/tmp目录 dataDir=/data/zk1/data dataLogDir=/data/zk1/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 # 心跳端口,数据端口;选举完成后,每个节点打开数据端口;只有主节点打开心跳端口,接受心跳数据 # server.N 和 myid 是对应的 server.1=bogon:2888:3888 server.2=bogon:2889:3889 server.3=bogon:2890:3890
6.批量操作脚本
for zk in {1,2,3} do myid=/data/zk${zk}/data/myid if [ ! -e "$myid" ];then echo $zk > $myid fi zkServer.sh $1 /data/zk${zk}/zoo.cfg done