zoukankan      html  css  js  c++  java
  • Centos8 Nginx 开机自启配

    第一步:创建 service文件

    vim /lib/systemd/system/nginx.service
    
    • /lib 与 /usr/lib 我这里配置时是一样的,在那个文件夹配置都可以

    第二步:编写 启动脚本

    
    [Unit]
    
    Description=nginx service
    
    After=network.target
    
    [Service]
    
    Type=forking
    
    PIDFile=/home/app/nginx/log/nginx.pid
    
    ExecStart=/home/app/nginx/sbin/nginx
    
    ExecReload=/home/app/nginx/sbin/nginx -s reload
    
    ExecStop=/home/app/nginx/sbin/nginx -s stop
    
    PrivateTmp=true
    
    [Install]
    
    WantedBy=multi-user.target
    
    

    脚本介绍

    Description

    服务描述

    After

    如果该字段指定的 Unit 也要启动,那么必须在当前 Unit 之前启动

    Type=forking

    后台运行

    PIDFile=/home/app/nginx/log/nginx.pid

    nginx.pid 文件需要在,nginx配置文件中查找。如果查不多,不配置此属性也可以

    如果type是后台运行,那么建议将此属性加上。指定pid。

    ExecStart=/home/app/nginx/sbin/nginx

    启动脚本

    ExecReload=/home/app/nginx/sbin/nginx -s reload

    重启脚本

    ExecStop=/home/app/nginx/sbin/nginx -s stop

    停止脚本

    PrivateTmp=true

    是否使用私有tmp目录

    WantedBy=multi-user.target

    运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3

    第三步:保存退出,重新加载systemd

    systemctl daemon-reload
    

    重新加载,使 systemd生效

    第四步:验证脚本

    # 查看服务状态
    systemctl status nginx.service
    # 停止服务
    systemctl stop nginx.service
    # 启动服务
    systemctl start nginx.service
    # 重启服务
    systemctl restart nginx.service
    

    第五步:配置开机自启

    #开启开机自启
    systemctl enable tomcat.service
    #取消开机自启
    systemctl disable nginx.service
    
  • 相关阅读:
    iOS中网络请求判断是否设置代理
    swif开发笔记12-Animations
    swift开发笔记11
    swift开发笔记06
    Idea热部署jrebel失败
    Oracle连接知识
    Idea安装及其简介
    博客园cnblog发布word
    en笔记音标
    测试案例小问题
  • 原文地址:https://www.cnblogs.com/easonchean/p/14199109.html
Copyright © 2011-2022 走看看