开机自启动nginx,php-fpm(其他服务类似)

centos 7以上是用Systemd进行系统初始化的,Systemd 是 Linux 系统中最新的初始化系统(init),它主要的设计目标是克服 sysvinit 固有的缺点,提高系统的启动速度。 Systemd服务文件以.service结尾,比如现在要建立nginx为开机启动,如果用yum install命令安装的,yum命令会自动创建nginx.service文件,直接用命令systemcel enable nginx.service设置开机启动即可。

systemcel enable nginx.service

源码安装的手动建立nginx.service服务文件

  1. 在系统服务目录里创建nginx.service文件

    vi /lib/systemd/system/nginx.service

    写入以下内容(路径改成自己的)

    [Unit]
    Description=nginx
    After=network.target
    [Service]
    Type=forking
    ExecStart=/www/lnmp/nginx/sbin/nginx -c /www/lnmp/nginx/conf/nginx.conf
    ExecReload=/www/lnmp/nginx/sbin/nginx -s reload
    ExecStop=/www/lnmp/nginx/sbin/nginx -s quit
    PrivateTmp=true
    [Install]
    WantedBy=multi-user.target

    在系统服务目录里创建php-fpm.service文件

    vi /lib/systemd/system/php-fpm.service

    写入以下内容(路径改成自己的)

    [Unit]
    Description=php-fpm
    After=network.target
    [Service]
    Type=forking
    ExecStart=/www/lnmp/php/sbin/php-fpm
    PrivateTmp=true
    [Install]
    WantedBy=multi-user.target

    [Unit]:服务的说明
    Description:描述服务
    After:描述服务类别
    [Service]服务运行参数的设置
    Type=forking是后台运行的形式
    ExecStart为服务的具体运行命令
    ExecReload为重启命令
    ExecStop为停止命令
    PrivateTmp=True表示给服务分配独立的临时空间
    注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
    [Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3

  2. 测试并加入开机自启
    先关闭nginx,php-fpm
    使用以下命令开启
    systemctl start nginx.service             #如果服务是开启状态,使用此命令会启动失败。
    systemctl start php-fpm.service

    开启成功,将服务加入开机自启

    systemctl enable nginx.service                #注意后面不能跟空格
    systemctl enable php-fpm.service

    重启服务器,查看是否启动

    shutdown -r now        #重启
    systemctl list-units --type=service #查看运行的服务

其他命令

systemctl start nginx.service              #启动nginx服务
systemctl enable nginx.service #设置开机自启动
systemctl disable nginx.service #停止开机自启动
systemctl status nginx.service #查看服务当前状态
systemctl restart nginx.service  #重新启动服务
systemctl list-units --type=service #查看所有已启动的服务


转载:https://blog.csdn.net/ijijni/article/details/78513521

开机自启动nginx,php-fpm的更多相关文章

  1. 开机自启动Nginx的脚本

    1.1 编写shell脚本 这里使用的是编写shell脚本的方式来处理 vi /etc/init.d/nginx  (输入下面的代码) #!/bin/bash # nginx Startup scri ...

  2. 【windows】【php】【nginx】windows 开机自启动nginx php 及nginx php配置

    #启动php-nginx   start-php-nginx.bat   @ECHO OFFECHO Starting PHP FastCGI...RunHiddenConsole.exe php-c ...

  3. 将命令添加到shell脚本中然后设置开机自启动

    例如开机自启动nginx 编写一个脚本 #vi /usr/local/Monitor_nginx.sh #!/bin/bash if [ "$(ps -ef | grep "ngi ...

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

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

  5. Mac Pro 开机自启动 PHP-FPM,Nginx,MySql 等软件

    在Mac下安装好了PHP开发环境(PHP-FPM,Nginx,MySql), 想设置成开机自启动,原来以为和一般的Linux系统一样,也是在rc.d这样目录放置启动脚本.在网上查了一些资料,发现苹果应 ...

  6. Linux(CentOS)系统下设置nginx开机自启动

    Nginx 是一个很强大的高性能Web和反向代理服务器.下面介绍在linux下安装后,如何设置开机自启动.首先,在linux系统的/etc/init.d/目录下创建nginx文件,使用如下命令:vi ...

  7. nginx启动、开机自启动、重启、关闭

    yum -y  install nginx # yum info nginx Loaded plugins: fastestmirror Loading mirror speeds from cach ...

  8. centos7 设置nginx和php开机自启动

    nginx开机自启动 首先我是源码安装的,需要手动建立nginx.service服务文件 cd /lib/systemd/system touch nginx.service nginx.servic ...

  9. CentOS7.X中设置nginx和php-fpm的开机自启动

    一.设置nginx的开机自启动方法 1.在/etc/init.d/目录下创建nginx文件 vi /etc/init.d/nginx 编写内容如下: #!/bin/sh # # nginx - thi ...

随机推荐

  1. A - Zebras

    Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Ol ...

  2. Eclipse安装Git插件(在线和离线)

    在线安装: help-->install new software-->add location就是安装的地址:http://download.eclipse.org/egit/updat ...

  3. cleanCode[1]:有意义的命名

    为什么要有意义的命名: 我们都曾经说过有朝一日再回头清理那些糟糕的代码,然而最终总是弃之不顾.稍后等于永不,我们需要立即行动,写优雅的代码. 写代码的过程中,读占的比例很大,所以首先要让代码易读. 有 ...

  4. 20155206 Exp2 后门原理与实践

    20155206 Exp2 后门原理与实践 1.Windows获得Linux Shell 在windows下,打开CMD,使用ipconfig指令查看本机IP 然后使用ncat.exe程序,ncat. ...

  5. 20155226《网络攻防》 Exp3 免杀原理与实践

    20155226<网络攻防> Exp3 免杀原理与实践 实验过程 1. msfvenom直接生成meterpreter可执行文件 直接将上周做实验时用msf生成的后门文件放在virscan ...

  6. #20155232《网络对抗》Exp9 Web安全基础

    20155232<网络对抗>Exp9 Web安全基础 本实践的目标理解常用网络攻击技术的基本原理.Webgoat实践下相关实验. 实验过程 WebGoat Webgoat是OWASP组织研 ...

  7. CISCN 应用环境相关指令备忘录

    1 - 关于Python环境的 使用Anaconda2管理Python环境 1.1 - 安装 官网下载安装包下载. 1.2 - 创建Python环境 localhost:template mac$ c ...

  8. Remote 桌面的win2003 servre端设定

    Microsoft Windows [版本 5.2.3790](C) 版权所有 1985-2003 Microsoft Corp. C:\Documents and Settings\Administ ...

  9. 汇编 shr 逻辑右移指令,shl 逻辑左移指令,SAL 算术左移指令,SAR 算术右移指令

    知识点: shr 逻辑右移指令 shl 逻辑左移指令 一.SHL 逻辑左移指令测试 shr 逻辑右移指令 右移一位相当于整除2 shl 逻辑左移指令 左移一位相当于乘2 //很多时候会溢出 //& ...

  10. SPA程序加载首界面eclipse卡顿解决笔记

    最近在开发SPA程序项目时遇到一个问题,因为是在开发阶段,所以直接就在eclipse中启动项目. 每次进入首界面时,eclipse就会长时间卡顿,前端界面也加载不出来,很影响开发效率. 在查找问题的时 ...