Centos 设置zookeeper开机自启动

把zookeeper做成服务

1、进入到/etc/rc.d/init.d目录下,新建一个zookeeper脚本

[root@zookeeper ~]# cd /etc/rc.d/init.d/ 
[root@zookeeper init.d]# pwd 
/etc/rc.d/init.d 
[root@zookeeper init.d]# touch zookeeper

2、给脚本添加执行权限

[root@zookeeper init.d]# chmod +x zookeeper

3、使用命令vim zookeeper进行编辑,在脚本中输入如下内容,其中同上面注意事项一样要添加export JAVA_HOME=/usr/java/jdk1.8.0_112这一行,否则无法正常启动。

[root@zookeeper init.d]# vim zookeeper   
#!/bin/bash
#chkconfig:2345 10 90
#description:service zookeeper
export     JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64
export     ZOO_LOG_DIR=/data/zookeeper/logs
ZOOKEEPER_HOME=/data/zookeeper-3.6.3/
case  "$1"   in
     start)  su  root  ${ZOOKEEPER_HOME}/bin/zkServer.sh  start;;
     start-foreground)  su  root ${ZOOKEEPER_HOME}/bin/zkServer.sh   start-foreground;;
     stop)  su  root  ${ZOOKEEPER_HOME}/bin/zkServer.sh  stop;;
     status)  su root  ${ZOOKEEPER_HOME}/bin/zkServer.sh    status;;
     restart)  su root   ${ZOOKEEPER_HOME}/bin/zkServer.sh   restart;;
     upgrade)su root  ${ZOOKEEPER_HOME}/bin/zkServer.sh  upgrade;;
     print-cmd)su root  ${ZOOKEEPER_HOME}/bin/zkServer.sh  print-cmd;;
     *)  echo "requirestart|start-foreground|stop|status|restart|print-cmd";;
esac

4、使用service zookeeper start/stop命令来尝试启动关闭zookeeper,使用service zookeeper status查看zookeeper状态。

先来看启动及状态

[root@zookeeper init.d]# service zookeeper start 
JMX enabled by default 
Using config: /usr/local/zookeeper-3.6.3/bin/../conf/zoo.cfg 
Starting zookeeper ... STARTED 
[root@zookeeper init.d]# service zookeeper status 
JMX enabled by default 
Using config: /usr/local/zookeeper-3.6.3/bin/../conf/zoo.cfg 
Mode: standalone 
[root@zookeeper init.d]#

接着看关闭及状态

[root@zookeeper init.d]# service zookeeper stop 
JMX enabled by default 
Using config: /usr/local/zookeeper-3.6.3/bin/../conf/zoo.cfg 
Stopping zookeeper ... STOPPED 
[root@zookeeper init.d]# service zookeeper status 
JMX enabled by default 
Using config: /usr/local/zookeeper-3.6.3/bin/../conf/zoo.cfg 
Error contacting service. It is probably not running. 
[root@zookeeper init.d]#

5、添加到开机自启

[root@zookeeper init.d]# chkconfig --add zookeeper

添加完之后,我们使用chkconfig --list来查看开机自启的服务中是否已经有我们的zookeeper了,如下所示,可以看到在最后一行便是我们的zookeeper服务了。

netconsole     	0:关	1:关	2:关	3:关	4:关	5:关	6:关
network        	0:关	1:关	2:开	3:开	4:开	5:开	6:关
zookeeper      	0:关	1:关	2:开	3:开	4:开	5:开	6:关
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值