#!/bin/bash
#/usr/local/zookeeper1/bin/zkServer.sh start
#/usr/local/zookeeper2/bin/zkServer.sh start
#/usr/local/zookeeper3/bin/zkServer.sh start
setup_dir="/usr/local/"
zooVersion="zookeeper-3.4.8"
cd $setup_dir
wget http://apache.fayea.com/zookeeper/${zooVersion}/${zooVersion}.tar.gz || wwwget http://apache.fayea.com/zookeeper/${zooVersion}/${zooVersion}.tar.gz
tar zxvf ${zooVersion}.tar.gz
mkdir -p ${zooVersion}/data
cp -a ${zooVersion} zookeeper1
cp -a ${zooVersion} zookeeper2
cp -a ${zooVersion} zookeeper3
z1="${setup_dir}zookeeper1/"
z2="${setup_dir}zookeeper2/"
z3="${setup_dir}zookeeper3/"
#########################################################################
cat >>${z1}conf/zoo.cfg << eof
# 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.
# example sakes.
dataDir=${z1}data
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
#autopurge.purgeInterval=1
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
eof
##########################################################################
cat >>${z2}conf/zoo.cfg << eof
# 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.
# example sakes.
dataDir=${z2}data
# the port at which the clients will connect
clientPort=2182
# the maximum number of client connections.
#autopurge.purgeInterval=1
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
eof
##########################################################################
cat >>${z3}conf/zoo.cfg << eof
# 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.
# example sakes.
dataDir=${z3}data
# the port at which the clients will connect
clientPort=2183
# the maximum number of client connections.
#autopurge.purgeInterval=1
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
eof
# dataDir新建myid文件写入数字表示这是第几号server. 该数字必须和zoo.cfg文件中的server.X中的X对应
echo 1 >${z1}data/myid
echo 2 >${z2}data/myid
echo 3 >${z3}data/myid
echo "# Zookeeper" >>/etc/rc.local
echo "${z1}bin/zkServer.sh start" >>/etc/rc.local
echo "${z2}bin/zkServer.sh start" >>/etc/rc.local
echo "${z3}bin/zkServer.sh start" >>/etc/rc.local
zookeeper自动化安装配置脚本
于 2023-06-21 17:09:39 首次发布