zoukankan      html  css  js  c++  java
  • CentOS配置服务开机自启

    本例子以nginx作为举例:

    CentOS7中 以systemctl 替代了chkconfig 进行服务的管理,

    默认在CentOS6 中控制服务开机自启,是在vim /etc/rc.d/rc.local 这个文件中控制的,

    在CentOS7 中该服务基于systemctl管理,

    提供rc.local.service, 并通过配置/etc/rc.local该文件进行管理系统启动时完成相关自动任务。

    /usr/lib/systemd/system/rc-local.service 该文件是控制开机自启的配置文件。配置文件如下:

    [Unit]
    Description=/etc/rc.d/rc.local Compatibility
    ConditionFileIsExecutable=/etc/rc.d/rc.local
    After=network.target

    [Service]
    Type=forking
    ExecStart=/etc/rc.d/rc.local start
    TimeoutSec=0
    RemainAfterExit=yes

    [Install]
    WantedBy=multi-user.target

    【Install】为新增内容, multi-user.target 代表3 级别, graphical.target 代表5级别

    赋予该文件权限。

    systemctl enable rc-local

    systemctl status rc-local (查看服务状态)

    Nginx 设置开机自启:

    安装好nginx之后,测试curl localhost  看是否访问正常,

     通过systemctl status nginx.service 可以查看到控制nginx服务是否加载的配置文件路径为:/usr/lib/systemd/system/nginx.service

    然后systemctl enable nginx.service  该命令启动nginx服务

    systemctl is-enabled nginx.service 查看某个软件是否开机自启动

    设置了开机自启后查看状态的截图:

    以上,设置相关服务开机自启。

    systemctl list-unit-files  列出所有可用单元(服务)

    systemctl list-units  列出所有运行中的单元

  • 相关阅读:
    使用react+html2canvas+jspdf实现生成pdf文件
    命名函数表达式
    java-信息安全(二十)国密算法 SM1,SM2,SM3,SM4
    003-docker-单宿主机下的网络模式
    【性能扫盲】性能测试面试题
    LoadRunner函数
    爬取干货集中营的美女图片
    ELK 性能优化实践 ---总结篇
    ELK 性能优化实践
    告警图片-搞笑的
  • 原文地址:https://www.cnblogs.com/Enzoo/p/10522652.html
Copyright © 2011-2022 走看看