centos ngnix+php+mysql开机启动

来源:互联网 发布:搜房帮网络经纪人登录 编辑:程序博客网 时间:2024/05/19 03:24

一:nginx开机启动

1:添加nginx的shell脚本

vi  ./etc/init.d/nginx
脚本内容如下:

#!/bin/bash# nginx Startup script for the Nginx HTTP Server# it is v.0.0.2 version.# chkconfig: - 85 15# description: Nginx is a high-performance web and proxy server.# It has a lot of features, but it's not for everyone.nginxd=/usr/phpenv/nginx-1.8.0/sbin/nginxnginx_config=/usr/phpenv/nginx-1.8.0/conf/nginx.confnginx_pid=/etc/nginx/nginx.pidRETVAL=0prog="nginx"# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/network# Check that networking is up.[ ${NETWORKING} = "no" ] && exit 0[ -x $nginxd ] || exit 0# Start nginx daemons functions.start() {if [ -e $nginx_pid ];then   echo "nginx already running...."   exit 1fi   echo -n $"Starting $prog: "   daemon $nginxd -c ${nginx_config}   RETVAL=$?   echo   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx   return $RETVAL}# Stop nginx daemons functions.stop() {        echo -n $"Stopping $prog: "        killproc $nginxd        RETVAL=$?        echo        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid}# reload nginx service functions.reload() {    echo -n $"Reloading $prog: "    #kill -HUP `cat ${nginx_pid}`    killproc $nginxd -HUP    RETVAL=$?    echo}# See how we were called.case "$1" instart)        start        ;;stop)        stop        ;;reload)        reload        ;;restart)        stop        start        ;;status)        status $prog        RETVAL=$?        ;;*)        echo $"Usage: $prog {start|stop|restart|reload|status|help}"        exit 1esacexit $RETVAL

wq保存

这样nginx就添加到系统服务了

2.设置/etc/init.d/nginx 执行权限

chmod 755 /etc/init.d/nginx

3.设置开机默认启动
chkconfig --add nginx //系统服务启动级别或者chkconfig nginx on  //系统服务启动级别为开机启动

4::测试

[root@xiaofei ~]# service nginxUsage: nginx {start|stop|restart|reload|status|help}

二:php-fpm开机启动

步骤和nginx一样,脚本文件换为php-fpm,内容如下:

#!/bin/bash## Startup script for the PHP-FPM server.## chkconfig: 345 85 15# description: PHP is an HTML-embedded scripting language# processname: php-fpm# config: /usr/local/php/etc/php.ini # Source function library.. /etc/rc.d/init.d/functions PHP_PATH=/usr/phpenv/php5.5.37DESC="php-fpm daemon"NAME=php-fpm# php-fpm路径DAEMON=$PHP_PATH/sbin/$NAME# 配置文件路径CONFIGFILE=$PHP_PATH/etc/php-fpm.conf# PID文件路径(在php-fpm.conf设置)PIDFILE=$PHP_PATH/var/run/$NAME.pidSCRIPTNAME=/etc/init.d/$NAME # Gracefully exit if the package has been removed.test -x $DAEMON || exit 0 rh_start() {  $DAEMON -y $CONFIGFILE || echo -n " already running"} rh_stop() {  kill -QUIT `cat $PIDFILE` || echo -n " not running"} rh_reload() {  kill -HUP `cat $PIDFILE` || echo -n " can't reload"} case "$1" in  start)        echo -n "Starting $DESC: $NAME"        rh_start        echo "."        ;;  stop)        echo -n "Stopping $DESC: $NAME"        rh_stop        echo "."        ;;  reload)        echo -n "Reloading $DESC configuration..."        rh_reload        echo "reloaded."  ;;  restart)        echo -n "Restarting $DESC: $NAME"        rh_stop        sleep 1        rh_start        echo "."        ;;  *)         echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2         exit 3        ;;esacexit 0

三:mysql开机启动

拷贝服务脚本到init.d目录,并设置开机启动

cp support-files/mysql.server /etc/init.d/mysqlchkconfig mysql onservice mysql start  //启动MySQL


注解:如果在启动中出现shell脚本/bin/bash^M: bad interprete的话,解决办法:http://blog.csdn.net/lxf0613050210/article/details/51790437


0 0
原创粉丝点击