• 将nginx设置为开启自启动的配置


    一 操作步骤

    1.1 背景描述

    项目现场项目需求就是需要重启机器之后,机器上的服务能够自动启动并运行。这里介绍nginx的开机自启动。

    1.2 操作步骤

    1.进入 /lib/systemd/system/ 目录下

    [root@localhost ~]# cd /lib/systemd/system/

    2.创建文件:nginx.service

    [root@localhost system]# touch nginx.service
    [root@localhost system]# vi nginx.service 

    3.编辑文件内容

    1. [Unit]
    2. Description=nginx service
    3. After=network.target
    4. [Service]
    5. Type=forking
    6. ExecStart=/usr/local/nginx/sbin/nginx
    7. ExecReload=/usr/local/nginx/sbin/nginx -s reload
    8. ExecStop=/usr/local/nginx/sbin/nginx -s quit
    9. PrivateTmp=true
    10. [Install]
    11. WantedBy=multi-user.target

    4.开机自启动

    [root@localhost system]# systemctl enable nginx
    Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
    [root@localhost system]# 

    5.查看进程
    [root@localhost system]# ps -ef|grep nginx
    root       3544      1  0 18:11 ?        00:00:00 nginx: master process ./nginx
    nobody     3546   3544  0 18:11 ?        00:00:00 nginx: worker process
    root       3676   2606  0 18:16 pts/0    00:00:00 grep --color=auto nginx
    [root@localhost system]# 

    6.关闭机器重新启动机器后,再次查看进程

    [root@localhost ~]# ps -ef|grep nginx
    root       1013      1  0 18:19 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
    nobody     1015   1013  0 18:19 ?        00:00:00 nginx: worker process
    root       2702   2653  0 18:22 pts/0    00:00:00 grep --color=auto nginx
    [root@localhost ~]# 


    7.页面访问

     注意出现如下错误:
    Warning: nginx.service changed on disk. Run 'systemctl daemon-reload' to reload units.
    直接按照提示执行命令systemctl daemon-reload 即可。

    # systemctl daemon-reload
     

    1.3  服务的启动/停止/刷新配置文件/查看状态

    # systemctl start nginx.service          启动nginx服务
    
    # 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         停止开机自启动

  • 相关阅读:
    他们在学校里不会教你的编程原则
    机器学习算法:线性回归、逻辑回归、决策树和随机森林解析
    nodejs+vue+elementui汽车出入库零配件4S服务管理系统python-java
    K8s复习笔记11--dubbo架构
    【车间调度】基于改进帝国企鹅算法求解车间调度问题附matlab代码
    vue中自定义指令的使用场景及示例
    Spring-注解开发管理第三方Bean
    思维模型 阿伦森效应
    HarmonyOS应用开发者基础认证【满分答案】
    Web前端开发——新年倒计实时刷新
  • 原文地址:https://blog.csdn.net/u011066470/article/details/126490622