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  列出所有运行中的单元

转载于:https://www.cnblogs.com/Enzoo/p/10522652.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值