1.進入到/etc/init.d目錄下,新建一個zookeeper腳本
cd /etc/init.d
vi zookeeper
#!/bin/bash #chkconfig:2345 20 90 #description:zookeeper #processname:zookeeper export JAVA_HOME=/usr/local/programs/jdk1.8 case $1 in start) su root /usr/local/programs/zookeeper-3.4.10/bin/zkServer.sh start;; stop) su root /usr/local/programs/zookeeper-3.4.10/bin/zkServer.sh stop;; status) su root /usr/local/programs/zookeeper-3.4.10/bin/zkServer.sh status;; restart) su root /usr/local/programs/zookeeper-3.4.10/bin/zkServer.sh restart;; *) echo "require start|stop|status|restart" ;; esac
2.給腳本添加執行權限
chmod +x zookeeper
[root@TestServer-DFJR bin]# cd /etc/init.d [root@TestServer-DFJR init.d]# chmod +x zookeeper
3.使用service zookeeper start/stop命令來嘗試啟動關閉zookeeper,使用service zookeeper status查看zookeeper狀態。
或者直接 zookeeper start/stop/status
4.添加到開機啟動
[root@TestServer-DFJR init.d]# chkconfig --add zookeeper
5.查看開機自啟的服務中是否已經有我們的zookeeper
[root@TestServer-DFJR init.d]# chkconfig --list zookeeper zookeeper 0:off 1:off 2:on 3:on 4:on 5:on 6:off