把zookeeper作成服务java
一、进入到/etc/rc.d/init.d目录下,新建一个zookeeper脚本vim
[root@zookeeper ~]# cd /etc/rc.d/init.d/
[root@zookeeper init.d]# pwd /etc/rc.d/init.d [root@zookeeper init.d]# touch zookeeper
二、给脚本添加执行权限bash
[root@zookeeper init.d]# chmod +x zookeeper
三、使用命令vim zookeeper进行编辑,在脚本中输入以下内容,其中同上面注意事项同样要添加export JAVA_HOME=/usr/local/java/jdk1.7.0_55这一行,不然没法正常启动。ui
[root@zookeeper init.d]# vim zookeeper
#!/bin/bash #chkconfig:2345 20 90 #description:zookeeper #processname:zookeeper export JAVA_HOME=/usr/local/java/jdk1.7.0_55 case $1 in start) su root /usr/local/zookeeper-3.4.6/bin/zkServer.sh start;; stop) su root /usr/local/zookeeper-3.4.6/bin/zkServer.sh stop;; status) su root /usr/local/zookeeper-3.4.6/bin/zkServer.sh status;; restart) su root /usr/local/zookeeper-3.4.6/bin/zkServer.sh restart;; *) echo "require start|stop|status|restart" ;; esac