【转】LNMP配置开机自启动

编写开机启动脚本:

I、nginx开机启动

1、在/etc/init.d/目录下创建脚本

vi  /etc/init.d/nginx

2、更改脚本权限

chmod 775 /etc/init.d/nginx

3、编写脚本内容

#!/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.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/webserver/nginx/sbin/nginx
nginx_config=/usr/local/webserver/nginx/conf/nginx.conf
nginx_pid=/usr/local/webserver/nginx/logs/nginx.pid
RETVAL=0
prog="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 1
fi
   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 /usr/local/webserver/nginx/logs/nginx.pid
}

reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL

4、设置开机启动

chkconfig nginxd on

II  设置mysql开机启动

1、将mysql安装目录下 support-files目录下的mysql.server文件拷贝到/etc/init.d/目录下并改名为mysqld,并更改权限

chmod 775 /etc/init.d/mysqld

2、设置开机启动

#chkconfig mysqld on

III、php-fpm开机启动

1、在/etc/init.d/目录下创建脚本

vi  /etc/init.d/php-fpm

2、更改脚本权限

chmod 775 /etc/init.d/php-fpm

3、编写脚本内容

#!/bin/sh
       #
       # php-fpm - this script starts and stops the php-fpm daemin
       #
       # chkconfig: - 85 15
       # processname: php-fpm
       # config:      /usr/local/php/etc/php-fpm.conf

       set -e

       PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
       DESC="php-fpm daemon"
       NAME=php-fpm
       DAEMON=/usr/local/php/sbin/$NAME     //这里设成自己的目录
       CONFIGFILE=/usr/local/php/etc/php-fpm.conf   //这里设成自己的目录
       PIDFILE=/usr/local/php/var/run/$NAME.pid   //这里设成自己的目录
       SCRIPTNAME=/etc/init.d/$NAME   //这里设成自己的目录

       # If the daemon file is not found, terminate the script.
       test -x $DAEMON || exit 0

       d_start(){
           $DAEMON -y $CONFIGFILE || echo -n " already running"
       }

       d_stop(){
           kill -QUIT `cat $PIDFILE` || echo -n " no running"
       }

       d_reload(){
           kill -HUP `cat $PIDFILE` || echo -n " could not reload"
       }

       case "$1" in
           start)
               echo -n "Starting $DESC: $NAME"
               d_start
               echo "."
               ;;
           stop)
               echo -n "Stopping $DESC: $NAME"
               d_stop
               echo "."
               ;;
           reload)
               echo -n "Reloading $DESC configuration..."
               d_reload
               echo "Reloaded."
               ;;
           restart)
               echo -n "Restarting $DESC: $NAME"
               d_stop
               # Sleep for two seconds before starting again, this should give the nginx daemon some time to perform a graceful stop
               sleep 2
               d_start
               echo "."
               ;;
           *)
               echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload)" >&2
               exit 3
               ;;
       esac
       exit 0

4、设置开机启动

#chkconfig php-fpm on

至此,大功告成。可以用命令 chkconfig 查看开机启动服务列表

from:https://blog.51cto.com/8804562/1398793

原文地址:https://www.cnblogs.com/xuan52rock/p/12663802.html

时间: 2024-10-25 20:40:34

【转】LNMP配置开机自启动的相关文章

树莓派实战3:配置开机自启动

接上 4. 配置开机自启动,修改rc.local 或者配置init.d ,这里修改rc.local sudo nano /etc/rc.local 如果你的mail.py在Desktop 则在exit 0上面一行添加 cd /home/pi/Desktop 然后 python mail.py 然后保存 退出 此时sudo reboot,等树莓派重新启动好了,你也会收到一封邮件 版权声明:本文为博主原创文章,未经博主允许不得转载.

linux centos6.2 node mongo 配置开机自启动

#!/bin/bash### BEGIN INIT INFO# Provides:        xiyoulib# Required-Start:    $all# Required-Stop:     $all# Default-Start:     2 3 4 5# Default-Stop: 0 1 6# Short-Description: Start daemon at boot time# Description: Enable service provided by daemon

centos7系统下nginx安装并配置开机自启动操作

准备工作 我的centos7系统是最小化安装的, 缺很多库, 首先安装必须的运行库 ? 1 2 3 4 5 6 7 8 9 10 11 yum install wget gcc gcc-c++ pcre-devel zlib-devel ##创建工作目录并进入工作目录 mkdir -p /z/nginx && cd /z/nginx ##获取nginx最新的安装包 wget http://nginx.org/download/nginx-1.11.10.tar.gz ##解压缩 tar z

CentOS6.8下安装redis并配置开机自启动

参考资料:http://www.bubuko.com/infodetail-1006383.html   http://www.cnblogs.com/skyessay/p/6433349.html 一.安装 下载redis-3.0.5.tar.gz [[email protected] ~]# cd /opt [[email protected] opt]# wget http://192.168.10.173:8080/website/linux/redis-3.0.5.tar.gz [[e

redis 服务配置开机自启动

1.常用的写入键值对命令和开启密码登录redis操作 如果是在其他盘如下操作: cd / 进入系统根目录 cd /d E:\CH\redis  进入E盘CH目录下的redis目录 2.注册开机自启动服务(注意:要到你安装redis的根目录下执行下面的cmd命令) redis-server --service-install redis.windows.conf --loglevel verbose   原文地址:https://www.cnblogs.com/chLxq/p/11062607.h

Redis 在Centos7下配置开机自启动

设置Redis开机启动需要如下几个步骤: 编写配置脚本 [ vim /etc/init.d/redis ] #!/bin/sh # # Simple Redis init.d script conceived to work on Linux systems # as it does use of the /proc filesystem. #chkconfig: 2345 80 90 #description:auto_run REDISPORT=6379 EXEC=/usr/local/bi

Linux配置开机自启动的两种方法

一.通过rc.local该文件实现开机自启 1:编写测试脚本 [[email protected] ~]# vim test.sh #!/bin/bash /bin/echo $(/bin/date +%F_%T) >> /tmp/test.log ##开机启动打印当前时间输出到test.log文本里 2:测试脚本完成之后,更改rc.local配置文件 [[email protected] ~]# vim /etc/rc.d/rc.local #!/bin/bash # THIS FILE I

7、xen虚拟机开机自启动配置

与其它虚拟化平台一样,xen虚拟机也可以配置开机自启动,就是在xen虚拟化服务器开机的时候, 其上承担的虚拟机也自动的启动,无需要人为干预启动. 1. xen开机自动说明  xen配置文件所在目录为/etc/xen,查看配置相关内容如下,有dd虚拟机的配置文件,还有一个auto目录, 配置开机自启动就是在auto目录中创建虚拟机配置文件的链接,xen服务在启动的时候会启动auto目录的虚拟机配置文件,启动虚拟机. 2. xen开机自动配置  在/etc/xen/auto目录中创建一个/etc/x

windows server 2008R2 配置tomcat服务开机自启动

一.配置环境 操作系统:Windows server 2008 R2 软件包:jdk_1.7.rar 二.安装操作 1,右击解压jdk_1.7.rar:解压后双击运行jdk-7u79-windows-i586 .exe 2.点击[下一步]一直到有个[更改]按钮,可以更改安装路径,设置完成后点击“下一步”. 到达这个界面可以直接点击[关闭]:也可以点击[后续步骤]. 3.右击计算机―[属性]―[高级系统设置]―[环境变量] 4.如果之前没后安装过Java环境:请点击系统变量下的[新建].变量名为