在Centos 中将zookeeper设置成开机启动

 

部署了Zookeeper之后,当需要重启机器时,开机后往往需要花一点时间对zookeeper集群进行启动,

由于zookeeper没有主节点的概念,且一个节点的重启不会对集群造成什么影像,

所以可以考虑把zookeeper设置成开机启动,具体流程如下

 

1 准备工作

1) 切换到/etc/rc.d/init.d/目录下

2) 创建zookeeper文件:touch zookeeper

3)更新权限:chmod +x zookeeper

4)编辑文件,在zookeeper里面输入如下内容

 

 

#!/bin/bash
#chkconfig:2345 20 90
#description:zookeeper
#processname:zookeeper
export JAVA_HOME=/application/jdk1.7.0_79
export PATH=$JAVA_HOME/bin:$PATH
case $1 in
start) su root /home/zsw/tools/zookeeper-3.4.6/bin/zkServer.sh start;;
stop) su root /home/zsw/tools/zookeeper-3.4.6/bin/zkServer.sh stop;;
status) su root /home/zsw/tools/zookeeper-3.4.6/bin/zkServer.sh status;;
restart) su root /home/zsw/tools/zookeeper-3.4.6/bin/zkServer.shrestart;;
*) echo "requirestart|stop|status|restart" ;;
esac

 

 

 

2 chkconfig zookeeper on

 

 

 

3 验证

 

chkconfig --add zookeeper

chkconfig --list zookeeper

 

这个时候我们就可以用servicezookeeper start/stop来启动停止zookeeper服务了

使用chkconfig--add zookeeper命令把zookeeper添加到开机启动里面

添加完成之后接这个使用chkconfig--list 来看看我们添加的zookeeper是否在里面

如果上面的操作都正常的话;你就可以重启你的linux服务器了