项目中用到zookeeper,运维部门要重启机器,要项目组的人现场维护,哥表示懒得到现场,直接将zookeeper做成服务。
首先配置你的zookeeper.
下载,解压( 我的放在/usr/zookeeper下),配置zoo.cfg
zoo.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.
dataDir=/usr/zookeeper
# the port at which the clients will connect
clientPort=2181
在/usr/zookeeper下创建目录logs,mkdir /usr/zookeeper/logs
#cp /usr/zookeeper/zookeeper-3.3.6/bin/zkServer.sh /etc/rc.d/init.d/zookeeper
#cp /usr/zookeeper/zookeeper-3.3.6/bin/zkEnv.sh /etc/rc.d/init.d/zkEnv
sudo ln -s /etc/rc.d/init.d/zookeeper /usr/zookeeper/zookeeper-3.3.6/bin/zkServer.sh
编辑/etc/rc.d/init.d/zookeeper,修改如下:
#1.注释掉
# Only follow symlinks if readlink supports it
#if readlink -f "$0" > /dev/null 2>&1
#then
# ZOOBIN=`readlink -f "$0"`
#else
# ZOOBIN="$0"
#fi
#2.ZOOBINLINK指向/etc/rc.d/init.d/zookeeper
ZOOBINLINK=/etc/rc.d/init.d/zookeeper
#3.指向/usr/zookeeper/zookeeper-3.3.6/bin
ZOOBIN=/usr/zookeeper/zookeeper-3.3.6/bin
ZOOBINDIR=$ZOOBIN
#去掉后缀sh
. "$ZOOENVDIR"/zkEnv
修改/usr/zookeeper/zookeeper-3.3.6/bin/zkEnv.sh
if [ "x$ZOOCFGDIR" = "x" ]
then
if [ -d "/etc/zookeeper" ]
then
ZOOCFGDIR="/etc/zookeeper"
else
#ZOOCFGDIR="$ZOOBINDIR/../conf"
ZOOCFGDIR="$ZOOBIN/../conf"
fi
fi
if [ "x${ZOO_LOG_DIR}" = "x" ]
then
#ZOO_LOG_DIR="."
ZOO_LOG_DIR="$ZOOBIN/../logs"
fi
配置启动级别
ln -s /etc/init.d/zookeeper /etc/rc3.d/K30zookeeper
ln -s /etc/init.d/zookeeper /etc/rc3.d/S70zookeeper
ln -s /etc/init.d/zookeeper /etc/rc5.d/K30zookeeper
ln -s /etc/init.d/zookeeper /etc/rc5.d/S70zookeeper
为所有用户添加执行权限
chmod -f 777 /etc/init.d/zookeeper
chmod -f 777 /etc/rc3.d/S70zookeeper
验证:
service zookeeper start
service zookeeper stop
service zookeeper status