分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

开机自启动nginx,php-fpm

发布时间:2023-09-06 01:49责任编辑:郭大石关键词:nginx

 

开机自启动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=nginxAfter=network.target[Service]Type=forkingExecStart=/www/lnmp/nginx/sbin/nginx -c /www/lnmp/nginx/conf/nginx.confExecReload=/www/lnmp/nginx/sbin/nginx -s reloadExecStop=/www/lnmp/nginx/sbin/nginx -s quitPrivateTmp=true[Install]WantedBy=multi-user.target
    在系统服务目录里创建php-fpm.service文件
    vi /lib/systemd/system/php-fpm.service
    写入以下内容(路径改成自己的)
    [Unit]Description=php-fpmAfter=network.target[Service]Type=forkingExecStart=/www/lnmp/php/sbin/php-fpmPrivateTmp=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

原文地址:https://www.cnblogs.com/M-D-Luffy/p/8831064.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved