【Linux -- systemctl管理服务】

Linux – systemctl管理服务


文章目录

  • Linux -- systemctl管理服务
  • 一、通过systemctl管理单一服务(service unit)
  • 二、通过systemctl查看系统上所有的服务
  • 三、通过systemctl管理不同的操作环境(target unit)
  • 四、通过systemctl分析各服务之间的依赖性
  • 总结


一、通过systemctl管理单一服务(service unit)

systemctl [command] [unit]
command:
start : 立刻启动后面跟的unit
stop : 立刻关闭后面接的unit
restart : 立刻重启后面的unit
reload : 不关闭后面的unit的情况下,重新加载配置文件,让设置生效
enable : 设置下次开机后,后面接的unit会被自动启动
disable : 设置下次开机后,后面接的unit不会被自动启动
status : 目前后面接的这个unit的状态(设置),有没有正在执行,会不会开机启动等等
is-active : 目前有没有正在运行中
is-enable : 开机时有没有默认启动这个unit

【Linux -- systemctl管理服务】_第1张图片

二、通过systemctl查看系统上所有的服务

systemctl [command] [--type=TYPE] [--all]
command:
	list-units:依据unit显示目前有启动的unit,若加上all就会也列出没启动的,如果没加command默认就是这个
	list-unit-files:根据/usr/lib/systemd/system/内的文件,将所有文件列表说明

systemctl : 列出系统上所有启动的unit
【Linux -- systemctl管理服务】_第2张图片
systemctl list-unit-files : 列出所有已安装的unit
【Linux -- systemctl管理服务】_第3张图片
systemctl list-units --type=service --all : 列出所有service类别的deamon,并且启没启动都列出来
【Linux -- systemctl管理服务】_第4张图片

三、通过systemctl管理不同的操作环境(target unit)

systemctl list-units --type=target --all

【Linux -- systemctl管理服务】_第5张图片

systemctl [command] [unit.target]
command:
	get-default : 取得目前的target
	set-default : 设置后面接的tarhet成为默认的操作模式
	isolate : 切换到后面接的模式

在这里插入图片描述
systemd也提供了几个简单的命令给我们切换模式:

systemctl poweroff  关机
systemctl reboot	重新开机
systemctl suspend	进入挂起模式
systemctl hibernate	进入休眠模式
systemctl rescue	强制进入恢复模式
systemctl emergency	强制进入紧急恢复模式

四、通过systemctl分析各服务之间的依赖性

systemctl list-dependencies [unit] [--reverse]
--reverse : 反向追踪哪个使用了这个unit

【Linux -- systemctl管理服务】_第6张图片
在看看谁会用到multi-user.target呢?
在这里插入图片描述


总结

本节主要介绍了关于systemctl管理的一些相关操作,唐怡佳继续加油叭!!!

你可能感兴趣的:(Linux,嵌入式,linux,服务器,运维)