• 设置Nginx开机自动启动


    1.创建nginx.service文件

    # vim /lib/systemd/system/nginx.service

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

    参数说明

    [Unit]服务的说明
    Description 描述服务
    After 描述服务类别
    [Service]服务运行参数的设置
    Type=forking 是后台运行的形式
    ExecStart 为服务的具体运行命令
    ExecReload 为重启命令
    ExecStop 为停止命令
    PrivateTmp=True 表示给服务分配独立的临时空间

    注意:

    [Service]的启动、重启、停止命令全部要求使用绝对路径
    [Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
    对于nginx的位置可以使用find / -name nginx进行寻找

    2.启动关闭

    设置开机自启动

    # systemctl enable nginx

    关闭开机自动启动

    # systemctl disable nginx

    3.服务相关命令

    启动nginx服务

    # systemctl start nginx.service

    停止服务

    # systemctl stop nginx.service

    重新启动服务

    # systemctl restart nginx.service

    查看所有已启动的服务

    # systemctl list-units --type=service

    查看服务当前状态

    # systemctl status nginx.service

    设置开机自启动

    # systemctl enable nginx.service

    停止开机自启动

    # systemctl disable nginx.service
  • 相关阅读:
    使用Spring MVC统一异常处理实战(转载)
    java 异常
    Java 接口和内部类
    JAVA 继承
    Linux中profile(转载)
    java 对象与类
    Java基本的程序结构设计 数组
    Python虚拟机函数机制之位置参数(四)
    Python虚拟机函数机制之参数类别(三)
    Python虚拟机函数机制之名字空间(二)
  • 原文地址:https://www.cnblogs.com/chong-zuo3322/p/14807551.html
Copyright © 2020-2023  润新知