Linux(CentOS)——Zookeeper开机自启动/服务化

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/LyySwx/article/details/86698855

目录

把zookeeper做成服务

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

2、给脚本添加执行权限

3、使用命令vim zookeeper进行编辑

4、运行并查看所配zookeeper文件是否生效

5、添加到开机自启

6、重启验证


把zookeeper做成服务

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

1

2

3

4

[root@localhost~]# cd /etc/rc.d/init.d 

[root@localhostinit.d]# pwd 

/etc/rc.d/init.d 

[root@localhostinit.d]# touch zookeeper

2、给脚本添加执行权限

1

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

3、使用命令vim zookeeper进行编辑

在脚本中输入如下内容,其中同上面注意事项一样要添加export JAVA_HOME=/root/jdk1.7.0_55 这一行,否则无法正常启动。

#!/bin/bash
#chkconfig:2345 10 90
#description:service zookeeper
export     JAVA_HOME=/root/jdk1.7.0_55
export     ZOO_LOG_DIR=/data/zookeeper/logs
ZOOKEEPER_HOME=/root/zookeeper-3.4.6
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、运行并查看所配zookeeper文件是否生效

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

先来看启动及状态

1

2

3

4

5

6

7

8

9

[root@localhostinit.d]# service zookeeper start 

JMX enabled by default
Using config: /root/zookeeper-3.4.6/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

[root@localhostinit.d]# service zookeeper status 

JMX enabled by default 

Using config: /root/zookeeper-3.4.10/bin/../conf/zoo.cfg 

Mode: standalone 

[root@localhostinit.d]#

接着看关闭及状态

1

2

3

4

5

6

7

8

9

[root@localhostinit.d]# service zookeeper stop 

JMX enabled by default 

Using config: /root/zookeeper-3.4.10/bin/../conf/zoo.cfg 

Stopping zookeeper ... STOPPED 

[root@localhostinit.d]# service zookeeper status 

JMX enabled by default 

Using config: /root/zookeeper-3.4.10/bin/../conf/zoo.cfg 

Error contacting service. It is probably not running. 

[root@localhostinit.d]#

5、添加到开机自启

1

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

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

6、重启验证

开机自启配置好了,我们重启之后查看一下状态试试,如下所示。一切正常!!说明我们的开机自启动成功了。

[root@localhost /]# /root/zookeeper-3.4.6/bin/zkServer.sh status
JMX enabled by default
Using config: /root/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: standalone


 

猜你喜欢

转载自blog.csdn.net/LyySwx/article/details/86698855