把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