一、设置nginx的开机自启动方法

1.在/etc/init.d/目录下创建nginx文件

  1. vi /etc/init.d/nginx

编写内容如下:

  1. #!/bin/sh
  2. #
  3. # nginx - this script starts and stops the nginx daemon
  4. #
  5. # chkconfig: - 85 15
  6. # description: NGINX is an HTTP(S) server, HTTP(S) reverse \
  7. # proxy and IMAP/POP3 proxy server
  8. # processname: nginx
  9. # config: /usr/local/nginx/nginx.conf
  10. # config: /etc/sysconfig/nginx
  11. # pidfile: /usr/local/nginx/nginx.pid
  12.  
  13. # Source function library.
  14. . /etc/rc.d/init.d/functions
  15.  
  16. # Source networking configuration.
  17. . /etc/sysconfig/network
  18.  
  19. # Check that networking is up.
  20. [ "$NETWORKING" = "no" ] && exit 0
  21.  
  22. nginx="/usr/local/nginx/sbin/nginx"
  23. prog=$(basename $nginx)
  24.  
  25. NGINX_CONF_FILE="/usr/local/nginx/nginx.conf"
  26.  
  27. [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
  28.  
  29. lockfile=/var/lock/subsys/nginx
  30.  
  31. make_dirs() {
  32. # make required directories
  33. user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
  34. if [ -n "$user" ]; then
  35. if [ -z "`grep $user /etc/passwd`" ]; then
  36. useradd -M -s /bin/nologin $user
  37. fi
  38. options=`$nginx -V 2>&1 | grep 'configure arguments:'`
  39. for opt in $options; do
  40. if [ `echo $opt | grep '.*-temp-path'` ]; then
  41. value=`echo $opt | cut -d "=" -f 2`
  42. if [ ! -d "$value" ]; then
  43. # echo "creating" $value
  44. mkdir -p $value && chown -R $user $value
  45. fi
  46. fi
  47. done
  48. fi
  49. }
  50.  
  51. start() {
  52. [ -x $nginx ] || exit 5
  53. [ -f $NGINX_CONF_FILE ] || exit 6
  54. make_dirs
  55. echo -n $"Starting $prog: "
  56. daemon $nginx -c $NGINX_CONF_FILE
  57. retval=$?
  58. echo
  59. [ $retval -eq 0 ] && touch $lockfile
  60. return $retval
  61. }
  62.  
  63. stop() {
  64. echo -n $"Stopping $prog: "
  65. killproc $prog -QUIT
  66. retval=$?
  67. echo
  68. [ $retval -eq 0 ] && rm -f $lockfile
  69. return $retval
  70. }
  71.  
  72. restart() {
  73. configtest || return $?
  74. stop
  75. sleep 1
  76. start
  77. }
  78.  
  79. reload() {
  80. configtest || return $?
  81. echo -n $"Reloading $prog: "
  82. killproc $nginx -HUP
  83. RETVAL=$?
  84. echo
  85. }
  86.  
  87. force_reload() {
  88. restart
  89. }
  90.  
  91. configtest() {
  92. $nginx -t -c $NGINX_CONF_FILE
  93. }
  94.  
  95. rh_status() {
  96. status $prog
  97. }
  98.  
  99. rh_status_q() {
  100. rh_status >/dev/null 2>&1
  101. }
  102.  
  103. case "$1" in
  104. start)
  105. rh_status_q && exit 0
  106. $1
  107. ;;
  108. stop)
  109. rh_status_q || exit 0
  110. $1
  111. ;;
  112. restart|configtest)
  113. $1
  114. ;;
  115. reload)
  116. rh_status_q || exit 7
  117. $1
  118. ;;
  119. force-reload)
  120. force_reload
  121. ;;
  122. status)
  123. rh_status
  124. ;;
  125. condrestart|try-restart)
  126. rh_status_q || exit 0
  127. ;;
  128. *)
  129. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  130. exit 2
  131. esac

脚本来自nginx官方,地址:http://wiki.nginx.org/RedHatNginxInitScript

注意点:脚本标红处,需根据环境安装路径做自定义修改;

2.修改脚本文件权限,(a+x ==> all user can execute 所有用户可执行)

  1. chmod a+x /etc/init.d/nginx

3.通过以下脚本可实现对nginx服务的管理

  1. /etc/init.d/nginx start
  2. /etc/init.d/nginx stop
  3. /etc/init.d/nginx restart
  4. /etc/init.d/nginx reload
  5. /etc/init.d/nginx status
4.将nginx服务加入chkconfig管理列表:
  1. chkconfig --add /etc/init.d/nginx

5.设置终端模式开机启动:

  1. chkconfig nginx on

6.执行完上述命令后,就可以使用service对nginx服务的管理

  1. service nginx start
  2. service nginx stop
  3. service nginx restart
  4. service nginx reload
  5. service nginx status

二、设置php-fpm的开机自启动方法

1.在/etc/init.d/目录下创建php-fpm文件

  1. vi /etc/init.d/php-fpm

编写内容如下:

  1. #!/bin/sh
  2. # chkconfig: 2345 15 95
  3.  
  4. # description: PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation \
  5.  
  6. # with some additional features useful for sites of any size, especially busier sites.
  7. # DateTime: 2016-09-20
  8.  
  9. # Source function library.
  10. . /etc/rc.d/init.d/functions
  11.  
  12. # Source networking configuration.
  13. . /etc/sysconfig/network
  14.  
  15. # Check that networking is up.
  16. [ "$NETWORKING" = "no" ] && exit 0
  17.  
  18. phpfpm="/usr/local/php/sbin/php-fpm"
  19. prog=$(basename ${phpfpm})
  20.  
  21. lockfile=/var/lock/subsys/phpfpm
  22.  
  23. start() {
  24. [ -x ${phpfpm} ] || exit 5
  25. echo -n $"Starting $prog: "
  26. daemon ${phpfpm}
  27. retval=$?
  28. echo
  29. [ $retval -eq 0 ] && touch $lockfile
  30. return $retval
  31. }
  32.  
  33. stop() {
  34. echo -n $"Stopping $prog: "
  35. killproc $prog -QUIT
  36. retval=$?
  37. echo
  38. [ $retval -eq 0 ] && rm -f $lockfile
  39. return $retval
  40. }
  41.  
  42. restart() {
  43. configtest || return $?
  44. stop
  45. start
  46. }
  47.  
  48. reload() {
  49. configtest || return $?
  50. echo -n $"Reloading $prog: "
  51. killproc ${phpfpm} -HUP
  52. RETVAL=$?
  53. echo
  54. }
  55.  
  56. force_reload() {
  57. restart
  58. }
  59.  
  60. configtest() {
  61. ${phpfpm} -t
  62. }
  63.  
  64. rh_status() {
  65. status $prog
  66. }
  67.  
  68. rh_status_q() {
  69. rh_status >/dev/null 2>&1
  70. }
  71.  
  72. case "$1" in
  73. start)
  74. rh_status_q && exit 0
  75. $1
  76. ;;
  77. stop)
  78. rh_status_q || exit 0
  79. $1
  80. ;;
  81. restart|configtest)
  82. $1
  83. ;;
  84. reload)
  85. rh_status_q || exit 7
  86. $1
  87. ;;
  88. status)
  89. rh_status
  90. ;;
  91. *)
  92. echo $"Usage: $0 {start|stop|status|restart|reload|configtest}"
  93. exit 2
  94. esac

注意点:脚本标红处,需根据环境安装路径做自定义修改;

2.修改脚本文件权限,(a+x ==> all user can execute 所有用户可执行)

  1. chmod a+x /etc/init.d/php-fpm

3.通过以下脚本可实现对php-fpm服务的管理

  1. /etc/init.d/php-fpm start
  2. /etc/init.d/php-fpm stop
  3. /etc/init.d/php-fpm restart
  4. /etc/init.d/php-fpm reload
  5. /etc/init.d/php-fpm status
4.将php-fpm服务加入chkconfig管理列表:
  1. chkconfig --add /etc/init.d/php-fpm

5.设置终端模式开机启动:

  1. chkconfig php-fpm on

6.执行完上述命令后,就可以使用service对php-fpm服务的管理

  1. service php-fpm start
  2. service php-fpm stop
  3. service php-fpm restart
  4. service php-fpm reload
  5. service php-fpm status

CentOS7.X中设置nginx和php-fpm的开机自启动的更多相关文章

  1. centos7中设置nginx的systemctl启动方式

    1.建立服务文件 (1)文件路径 vim /usr/lib/systemd/system/nginx.service (2)服务文件内容 [Unit] Description=nginx - high ...

  2. linux下 nginx、php-fpm、mysql 开机自启动

    1.分别为每个编写shell脚本放入/etc/init.d下,添加service服务 2.把每个service服务加入到chkconfig列表 这里我们以php-fpm为例说明下步骤: php-fpm ...

  3. 在Linux中利用Service命令添加系统服务及开机自启动

    有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统服务 主要用三种方式进行这一操作: ln -s                       在/etc/rc.d/rc*.d目录中建立/e ...

  4. CentOS7下利用init.d启动脚本实现tomcat开机自启动

    在之前的博文中已经对CentOS7下通过tomcat进行WEB系统的发布进行了介绍,今天将利用init.d启动脚本,将服务脚本加入到开机启动服务队列,实现tomcat服务的开机启动. 1. 环境准备 ...

  5. 如何将Nginx注册为系统服务,开机自启动

    亲测有效! 一般程序员在实际工作中,除了敲代码,很少有机会实际接触操作其它东西,例如服务器环境搭建,项目部署等等,不是领导信任或项目组核心成员,应该是没有机会实际接触的,只能通过网上资料稍微了解一下. ...

  6. 如何将Nginx注册为系统服务,开机自启动。

    亲测有效! 一般程序员在实际工作中,除了敲代码,很少有机会实际接触操作其它东西,例如服务器环境搭建,项目部署等等,不是领导信任或项目组核心成员,应该是没有机会实际接触的,只能通过网上资料稍微了解一下. ...

  7. 对已经创建的docker container设置开机自启动

    首先显示出所有的容器 docker ps -a #显示所有容器 设置已经建立的容器的开机自启动方法 docker update --restart=always <container ID 根据 ...

  8. 详解如何在CentOS7中使用Nginx和PHP7-FPM安装Nextcloud

    转载地址:https://www.jb51.net/article/109382.htm 这篇文章主要介绍了详解如何在CentOS7中使用Nginx和PHP7-FPM安装Nextcloud,会通过 N ...

  9. 如何在 Centos7 中安装 nginx

    1. 添加 nginx 的 yum 源(官网安装说明) vi /etc/yum.repos.d/nginx.repo 在该文件中添加如下内容: [nginx]name=nginx repobaseur ...

随机推荐

  1. 3、css初识

    前端内容就分三部分html.css.javascript(js),对一个网页来说html相当于是一个裸体的人,css相当于给这个人穿上了衣服,javascript相当于给这个人赋予动作行为,今天我们要 ...

  2. Spring Boot @Autowired 没法自动注入的问题

    Application 启动类: @SpringBootApplication @EnableConfigurationProperties @ComponentScan(basePackages = ...

  3. [原创]Delphi XE10 dxLayoutControl 控件应用指南

    DevExpress VCL套件是一套非常强大的界面控件,可惜关于Delphi开发方面的说明太少,有些控件使用起来一头雾水,不知从何下手.本节详细介绍在Delphi Xe10 Seattle中如何利用 ...

  4. Redis接口的调用

    1.hiredis是redis数据库的C接口,目录为/redis-3.2.6/deps/hiredis 2.示例代码如下: #include <stdio.h> #include < ...

  5. 【前端酷站】分享一个纯 Javascript 的图表库与立体像素风制作~

    今天小编为大家推荐一个神奇的酷站.ECharts,一个纯 Javascript 的图表库. 以下是各个几个不错的界面的介绍: 首页:http://echarts.baidu.com/ 在首页有完整的说 ...

  6. ROC曲线-阈值评价标准

    ROC曲线指受试者工作特征曲线 / 接收器操作特性曲线(receiver operating characteristic curve), 是反映敏感性和特异性连续变量的综合指标,是用构图法揭示敏感性 ...

  7. Spring Boot系列——日志配置

    日志,通常不会在需求阶段作为一个功能单独提出来,也不会在产品方案中看到它的细节.但是,这丝毫不影响它在任何一个系统中的重要的地位. 为了保证服务的高可用,发现问题一定要即使,解决问题一定要迅速,所以生 ...

  8. Navicat Premium 12破解方法

    来源网址:https://www.jianshu.com/p/42a33b0dda9c 1.按步骤安装Navicat Premium,如果没有可以去官网下载:http://www.navicat.co ...

  9. 关于在最新的 Visual Studio 2017 版本中使用 Web Deploy 遇到的 SSL 连接错误

    错误信息: 无法完成向远程代理 URL 发送请求.请求被中止: 未能创建 SSL/TLS 安全通道. 原因分析: 最新版本的 Visual Studio 中,已经抛弃了 https 协议中旧版 SSL ...

  10. OC 与 js 界面JSBridge交互

    // 1.新建WebView self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds]; [self.view addSubv ...