创建自启动脚本: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