CentOS6 配置Nginx,MySql,php-fpm开机启动的方法
程序员文章站
2022-06-08 22:11:42
一. nginx 开机启动
1、在/etc/init.d/目录下创建脚本
vim /etc/init.d/nginx
2、编写脚本内容 (将以下复制进去相应改动安装路...
一. nginx 开机启动
1、在/etc/init.d/目录下创建脚本
vim /etc/init.d/nginx
2、编写脚本内容 (将以下复制进去相应改动安装路径)
#!/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
3、更改脚本权限
chmod 775 /etc/init.d/nginx
4、设置开机启动
#chkconfig nginxd on
二. mysql开机启动
1、将mysql安装目录下 support-files目录下的mysql.server文件拷贝到/etc/init.d/目录下并改名为mysqld,并更改权限
chmod 775 /etc/init.d/mysqld
2、设置开机启动
#chkconfig mysqld on
三. php-fpm开机启动
1、在/etc/init.d/目录下创建脚本
vim /etc/init.d/php-fpm
2、编写脚本内容 (将以下复制进去相应改动安装路径)
#!/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
最后:x 保存退出
3、更改脚本权限
chmod 775 /etc/init.d/php-fpm
4、设置开机启动
#chkconfig php-fpm on
可用命令 chkconfig 查看开机启动服务列表
以上所述是小编给大家介绍的centos6 配置nginx,mysql,php-fpm开机启动的方法,希望对大家有所帮助
推荐阅读
-
nginx php-fpm环境中chroot功能的配置使用方法
-
Windows系统配置python脚本开机启动的3种方法分享
-
mysql 5.7.17 zip安装配置教程 mysql启动失败的解决方法
-
实现Nginx中使用PHP-FPM时记录PHP错误日志的配置方法
-
CentOS6 配置Nginx,MySql,php-fpm开机启动的方法
-
CentOS7安装Nginx并配置自动启动的方法步骤
-
Windows系统配置python脚本开机启动的3种方法分享
-
MySQL因配置过大内存导致无法启动的解决方法
-
MySQL中配置文件my.cnf因权限问题导致无法启动的解决方法
-
阿里云服务器安装配置redis的方法并且加入到开机启动(推荐)