CentOS7.X中设置nginx和php-fpm的开机自启动
一、设置nginx的开机自启动方法
1.在/etc/init.d/目录下创建nginx文件
- vi /etc/init.d/nginx
编写内容如下:
- #!/bin/sh
- #
- # nginx - this script starts and stops the nginx daemon
- #
- # chkconfig: - 85 15
- # description: NGINX is an HTTP(S) server, HTTP(S) reverse \
- # proxy and IMAP/POP3 proxy server
- # processname: nginx
- # config: /usr/local/nginx/nginx.conf
- # config: /etc/sysconfig/nginx
- # pidfile: /usr/local/nginx/nginx.pid
- # Source function library.
- . /etc/rc.d/init.d/functions
- # Source networking configuration.
- . /etc/sysconfig/network
- # Check that networking is up.
- [ "$NETWORKING" = "no" ] && exit 0
- nginx="/usr/local/nginx/sbin/nginx"
- prog=$(basename $nginx)
- NGINX_CONF_FILE="/usr/local/nginx/nginx.conf"
- [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
- lockfile=/var/lock/subsys/nginx
- make_dirs() {
- # make required directories
- user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
- if [ -n "$user" ]; then
- if [ -z "`grep $user /etc/passwd`" ]; then
- useradd -M -s /bin/nologin $user
- fi
- options=`$nginx -V 2>&1 | grep 'configure arguments:'`
- for opt in $options; do
- if [ `echo $opt | grep '.*-temp-path'` ]; then
- value=`echo $opt | cut -d "=" -f 2`
- if [ ! -d "$value" ]; then
- # echo "creating" $value
- mkdir -p $value && chown -R $user $value
- fi
- fi
- done
- fi
- }
- start() {
- [ -x $nginx ] || exit 5
- [ -f $NGINX_CONF_FILE ] || exit 6
- make_dirs
- echo -n $"Starting $prog: "
- daemon $nginx -c $NGINX_CONF_FILE
- retval=$?
- echo
- [ $retval -eq 0 ] && touch $lockfile
- return $retval
- }
- stop() {
- echo -n $"Stopping $prog: "
- killproc $prog -QUIT
- retval=$?
- echo
- [ $retval -eq 0 ] && rm -f $lockfile
- return $retval
- }
- restart() {
- configtest || return $?
- stop
- sleep 1
- start
- }
- reload() {
- configtest || return $?
- echo -n $"Reloading $prog: "
- killproc $nginx -HUP
- RETVAL=$?
- echo
- }
- force_reload() {
- restart
- }
- configtest() {
- $nginx -t -c $NGINX_CONF_FILE
- }
- rh_status() {
- status $prog
- }
- rh_status_q() {
- rh_status >/dev/null 2>&1
- }
- case "$1" in
- start)
- rh_status_q && exit 0
- $1
- ;;
- stop)
- rh_status_q || exit 0
- $1
- ;;
- restart|configtest)
- $1
- ;;
- reload)
- rh_status_q || exit 7
- $1
- ;;
- force-reload)
- force_reload
- ;;
- status)
- rh_status
- ;;
- condrestart|try-restart)
- rh_status_q || exit 0
- ;;
- *)
- echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
- exit 2
- esac
脚本来自nginx官方,地址:http://wiki.nginx.org/RedHatNginxInitScript
注意点:脚本标红处,需根据环境安装路径做自定义修改;
2.修改脚本文件权限,(a+x ==> all user can execute 所有用户可执行)
- chmod a+x /etc/init.d/nginx
3.通过以下脚本可实现对nginx服务的管理
- /etc/init.d/nginx start
- /etc/init.d/nginx stop
- /etc/init.d/nginx restart
- /etc/init.d/nginx reload
- /etc/init.d/nginx status
- chkconfig --add /etc/init.d/nginx
5.设置终端模式开机启动:
- chkconfig nginx on
6.执行完上述命令后,就可以使用service对nginx服务的管理
- service nginx start
- service nginx stop
- service nginx restart
- service nginx reload
- service nginx status
二、设置php-fpm的开机自启动方法
1.在/etc/init.d/目录下创建php-fpm文件
- vi /etc/init.d/php-fpm
编写内容如下:
- #!/bin/sh
- # chkconfig: 2345 15 95
- # description: PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation \
- # with some additional features useful for sites of any size, especially busier sites.
- # DateTime: 2016-09-20
- # Source function library.
- . /etc/rc.d/init.d/functions
- # Source networking configuration.
- . /etc/sysconfig/network
- # Check that networking is up.
- [ "$NETWORKING" = "no" ] && exit 0
- phpfpm="/usr/local/php/sbin/php-fpm"
- prog=$(basename ${phpfpm})
- lockfile=/var/lock/subsys/phpfpm
- start() {
- [ -x ${phpfpm} ] || exit 5
- echo -n $"Starting $prog: "
- daemon ${phpfpm}
- retval=$?
- echo
- [ $retval -eq 0 ] && touch $lockfile
- return $retval
- }
- stop() {
- echo -n $"Stopping $prog: "
- killproc $prog -QUIT
- retval=$?
- echo
- [ $retval -eq 0 ] && rm -f $lockfile
- return $retval
- }
- restart() {
- configtest || return $?
- stop
- start
- }
- reload() {
- configtest || return $?
- echo -n $"Reloading $prog: "
- killproc ${phpfpm} -HUP
- RETVAL=$?
- echo
- }
- force_reload() {
- restart
- }
- configtest() {
- ${phpfpm} -t
- }
- rh_status() {
- status $prog
- }
- rh_status_q() {
- rh_status >/dev/null 2>&1
- }
- case "$1" in
- start)
- rh_status_q && exit 0
- $1
- ;;
- stop)
- rh_status_q || exit 0
- $1
- ;;
- restart|configtest)
- $1
- ;;
- reload)
- rh_status_q || exit 7
- $1
- ;;
- status)
- rh_status
- ;;
- *)
- echo $"Usage: $0 {start|stop|status|restart|reload|configtest}"
- exit 2
- esac
注意点:脚本标红处,需根据环境安装路径做自定义修改;
2.修改脚本文件权限,(a+x ==> all user can execute 所有用户可执行)
- chmod a+x /etc/init.d/php-fpm
3.通过以下脚本可实现对php-fpm服务的管理
- /etc/init.d/php-fpm start
- /etc/init.d/php-fpm stop
- /etc/init.d/php-fpm restart
- /etc/init.d/php-fpm reload
- /etc/init.d/php-fpm status
- chkconfig --add /etc/init.d/php-fpm
5.设置终端模式开机启动:
- chkconfig php-fpm on
6.执行完上述命令后,就可以使用service对php-fpm服务的管理
- service php-fpm start
- service php-fpm stop
- service php-fpm restart
- service php-fpm reload
- service php-fpm status
CentOS7.X中设置nginx和php-fpm的开机自启动的更多相关文章
- centos7中设置nginx的systemctl启动方式
1.建立服务文件 (1)文件路径 vim /usr/lib/systemd/system/nginx.service (2)服务文件内容 [Unit] Description=nginx - high ...
- linux下 nginx、php-fpm、mysql 开机自启动
1.分别为每个编写shell脚本放入/etc/init.d下,添加service服务 2.把每个service服务加入到chkconfig列表 这里我们以php-fpm为例说明下步骤: php-fpm ...
- 在Linux中利用Service命令添加系统服务及开机自启动
有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统服务 主要用三种方式进行这一操作: ln -s 在/etc/rc.d/rc*.d目录中建立/e ...
- CentOS7下利用init.d启动脚本实现tomcat开机自启动
在之前的博文中已经对CentOS7下通过tomcat进行WEB系统的发布进行了介绍,今天将利用init.d启动脚本,将服务脚本加入到开机启动服务队列,实现tomcat服务的开机启动. 1. 环境准备 ...
- 如何将Nginx注册为系统服务,开机自启动
亲测有效! 一般程序员在实际工作中,除了敲代码,很少有机会实际接触操作其它东西,例如服务器环境搭建,项目部署等等,不是领导信任或项目组核心成员,应该是没有机会实际接触的,只能通过网上资料稍微了解一下. ...
- 如何将Nginx注册为系统服务,开机自启动。
亲测有效! 一般程序员在实际工作中,除了敲代码,很少有机会实际接触操作其它东西,例如服务器环境搭建,项目部署等等,不是领导信任或项目组核心成员,应该是没有机会实际接触的,只能通过网上资料稍微了解一下. ...
- 对已经创建的docker container设置开机自启动
首先显示出所有的容器 docker ps -a #显示所有容器 设置已经建立的容器的开机自启动方法 docker update --restart=always <container ID 根据 ...
- 详解如何在CentOS7中使用Nginx和PHP7-FPM安装Nextcloud
转载地址:https://www.jb51.net/article/109382.htm 这篇文章主要介绍了详解如何在CentOS7中使用Nginx和PHP7-FPM安装Nextcloud,会通过 N ...
- 如何在 Centos7 中安装 nginx
1. 添加 nginx 的 yum 源(官网安装说明) vi /etc/yum.repos.d/nginx.repo 在该文件中添加如下内容: [nginx]name=nginx repobaseur ...
随机推荐
- 3、css初识
前端内容就分三部分html.css.javascript(js),对一个网页来说html相当于是一个裸体的人,css相当于给这个人穿上了衣服,javascript相当于给这个人赋予动作行为,今天我们要 ...
- Spring Boot @Autowired 没法自动注入的问题
Application 启动类: @SpringBootApplication @EnableConfigurationProperties @ComponentScan(basePackages = ...
- [原创]Delphi XE10 dxLayoutControl 控件应用指南
DevExpress VCL套件是一套非常强大的界面控件,可惜关于Delphi开发方面的说明太少,有些控件使用起来一头雾水,不知从何下手.本节详细介绍在Delphi Xe10 Seattle中如何利用 ...
- Redis接口的调用
1.hiredis是redis数据库的C接口,目录为/redis-3.2.6/deps/hiredis 2.示例代码如下: #include <stdio.h> #include < ...
- 【前端酷站】分享一个纯 Javascript 的图表库与立体像素风制作~
今天小编为大家推荐一个神奇的酷站.ECharts,一个纯 Javascript 的图表库. 以下是各个几个不错的界面的介绍: 首页:http://echarts.baidu.com/ 在首页有完整的说 ...
- ROC曲线-阈值评价标准
ROC曲线指受试者工作特征曲线 / 接收器操作特性曲线(receiver operating characteristic curve), 是反映敏感性和特异性连续变量的综合指标,是用构图法揭示敏感性 ...
- Spring Boot系列——日志配置
日志,通常不会在需求阶段作为一个功能单独提出来,也不会在产品方案中看到它的细节.但是,这丝毫不影响它在任何一个系统中的重要的地位. 为了保证服务的高可用,发现问题一定要即使,解决问题一定要迅速,所以生 ...
- Navicat Premium 12破解方法
来源网址:https://www.jianshu.com/p/42a33b0dda9c 1.按步骤安装Navicat Premium,如果没有可以去官网下载:http://www.navicat.co ...
- 关于在最新的 Visual Studio 2017 版本中使用 Web Deploy 遇到的 SSL 连接错误
错误信息: 无法完成向远程代理 URL 发送请求.请求被中止: 未能创建 SSL/TLS 安全通道. 原因分析: 最新版本的 Visual Studio 中,已经抛弃了 https 协议中旧版 SSL ...
- OC 与 js 界面JSBridge交互
// 1.新建WebView self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds]; [self.view addSubv ...