centos7的启动流程(systemctl)(1)

本文详细介绍了CentOS7中使用systemctl管理服务的方法,包括设置服务开机启动、查看服务状态、服务依赖关系和运行级别等内容。通过systemctl命令,可以实现启动、停止、重启服务,以及检查服务的启用和禁用状态。此外,还探讨了service unit文件格式和运行级别的切换,是理解CentOS7服务管理的重要参考资料。
摘要由CSDN通过智能技术生成

设置开机禁止启动

chkconfig name off ==> systemctl disable name.service

查看所有服务的开机自启状态:

chkconfig --list ==> systemctl list-unit-files --type service

用来列出该服务在哪些运行级别下启用和禁用

chkconfig sshd –list ==> ls /etc/systemd/system/*.wants/sshd.service

查看服务是否开机自启

systemctl is-enabled name.service

查看服务的依赖关系

systemctl list-dependencies name.service

杀掉进程

systemctl kill unitname

3.服务状态


systemctl list-unit-files --type service --all显示状态

loaded Unit配置文件已处理

active(running) 一次或多次持续处理的运行

active(exited) 成功完成一次性的配置

active(waiting) 运行中,等待一个事件

inactive 不运行

enabled 开机启动

disabled 开机不启动

static 开机不启动,但可被另一个启用的服务激活

4.例子


显示所有单元状态

systemctl 或 systemctl list-units

只显示服务单元的状态

systemctl --type=service

显示sshd服务单元

systemctl –l status sshd.service

验证sshd服务当前是否活动

systemctl is-active sshd

启动,停止和重启sshd服务

systemctl start sshd.service

systemctl stop sshd.service

systemctl restart sshd.service

重新加载配置

systemctl reload sshd.service

列出活动状态的所有服务单元

systemctl list-units --type=service

列出所有服务单元

systemctl list-units --type=service --all

查看服务单元的启用和禁用状态

systemctl list-unit-files --type=service

列出失败的服务

systemctl --failed --type=service

列出依赖的单元

systemctl list-dependencies sshd

验证sshd服务是否开机启动

systemctl is-enabled sshd

禁用network,使之不能自动启动,但手动可以

systemctl disable network

启用network

systemctl enable network

禁用network,使之不能手动或自动启动

systemctl mask network

启用network

systemctl unmask network

三. service unit文件格式

======================================================================================

/etc/systemd/system系统管理员和用户使用

/usr/lib/systemd/system:发行版打包者使用(一般是参考官方文档写的)

以 “#” 开头的行后面的内容会被认为是注释

相关布尔值,

1、yes、on、true 都是开启

0、no、off、false 都是关闭

时间单位默认是秒,所以要用毫秒(ms

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值