linux下添加zookeeper開機自動啓動

1、安裝zookeeper

請自行百度,假設安裝的路徑爲:

/opt/apache-zookeeper-3.5.7-bin

啓動:/opt/apache-zookeeper-3.5.7-bin/bin/zkServer.sh start

查看:/opt/apache-zookeeper-3.5.7-bin/bin/zkServer.sh status

停止:/opt/apache-zookeeper-3.5.7-bin/bin/zkServer.sh stop

2、添加開機啓動腳本zookeeper文件到/etc/rc.d/init.d目錄(centos機器)

#!/bin/bash
#chkconfig: 2345 10 90
#description: service zookeeper
#processname:zookeeper

#環境變量加載
source /etc/profile
#export JAVA_HOME=/usr/local/java/jdk1.8.0_241
export ZOOKEEPER_HOME=/opt/apache-zookeeper-3.5.7-bin

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;;
    test)  echo "test good";;
    *) echo "requirestart|start-foreground|stop|status|restart|print-cmd";;
esac

3、添加到開機服務

chkconfig --add zookeeper

ps:查看開機啓動服務使用:chkconfig --list

4、重啓機器reboot看看,zookeeper就會自動啓動了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章