zookeeper 本地测试环境搭建

搭建shell脚本

#/bin/sh

# zookeeper 安装脚本,用于自己搭建测试环境

cd /opt/tmp

ZOOKEEPER_VERSION="zookeeper-3.4.8"

wget http://apache.01link.hk/zookeeper/$ZOOKEEPER_VERSION/$ZOOKEEPER_VERSION.tar.gz
tar -zxvf $ZOOKEEPER_VERSION.tar.gz > /dev/null

for((i = 1; i < 4; i++)); do
	echo "begin $i";
	dirZookeeper="server$i"
	cp -r $ZOOKEEPER_VERSION $dirZookeeper
	mkdir $dirZookeeper/data $dirZookeeper/dataLog $dirZookeeper/logs
	echo $i > $dirZookeeper/data/myid
	echo "#zookeeper1" >> $dirZookeeper/conf/zoo.cfg
	echo "initLimit=5" >> $dirZookeeper/conf/zoo.cfg
	echo "tickTime=2000" >> $dirZookeeper/conf/zoo.cfg
	echo "syncLimit=2" >> $dirZookeeper/conf/zoo.cfg
	echo "dataDir=/opt/zookeeper/$dirZookeeper/data" >> $dirZookeeper/conf/zoo.cfg
	echo "dataLogDir=/opt/zookeeper/$dirZookeeper/dataLog" >> $dirZookeeper/conf/zoo.cfg
	echo "clientPort=$(expr $i + 2180)" >> $dirZookeeper/conf/zoo.cfg
	echo "server.1=127.0.0.1:2888:3888" >> $dirZookeeper/conf/zoo.cfg
	echo "server.2=127.0.0.1:2889:3889" >> $dirZookeeper/conf/zoo.cfg
	echo "server.3=127.0.0.1:2890:3890" >> $dirZookeeper/conf/zoo.cfg
done

rm -rf $ZOOKEEPER_VERSION
rm $ZOOKEEPER_VERSION.tar.gz

启动服务

./opt/tmp/server1/bin/zkServer.sh start
./opt/tmp/server2/bin/zkServer.sh start
./opt/tmp/server3/bin/zkServer.sh start

客户端连接

./opt/tmp/server1/bin/zkCli.sh -server 127.0.0.1:2181


你可能感兴趣的:(zookeeper,shell)