創建自啓動腳本:mysql
vim /etc/init.d/lamp
輸入以下內容:redis
#!/bin/bash # # mysql startup script for the lamp server # # chkconfig: 2345 90 10 # description: start the lamp with mysql deamon # # Source function library . /etc/rc.d/init.d/functions #腳本名稱 prog=lamp #redis安裝目錄 LAMP_HOME=/opt/lampstack export LAMP_HOME case "$1" in start) echo "Starting lampstack with mysql..." $LAMP_HOME/ctlscript.sh start ;; stop) echo "Stopping lampstack with mysql..." $LAMP_HOME/ctlscript.sh stop ;; restart) echo "Restarting lampstack with mysql..." $LAMP_HOME/ctlscript.sh restart ;; *) echo "Usage: $prog {start|stop|restart}" ;; esac exit 0
修改文件爲可運行文件:sql
chmod a+x lamp
查看lamp開機啓動狀況:vim
chkconfig --list
如沒有,則添加到系統啓動隊列中:bash
chkconfig --add lamp
從新檢查lamp開機啓動狀況,若成功,則應顯示以下內容:rest
lamp 0:off 1:off 2:on 3:on 4:on 5:on 6:offcode
使用下列命令對lamp進行重啓、中止、啓動:server
service lamp restart/stop/start