控制服务与守护进程_Systemd

本文介绍了Systemd的基础知识,包括如何查看服务状态、管理服务的启动与停止、服务的依赖关系以及开机启动服务。此外,还涉及了目标(target)的选择和切换,以及如何进行系统诊断和故障修复。内容涵盖systemctl命令的各种用法,是理解Systemd服务管理和Linux系统控制的重要参考。

Sytemd 的介绍
一个服务经常关系到多个服务。在7版本中,PID1是systemd,新的init system.
查看服务状态。

systemctl status service

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

systemctl list-units --type=service #查看active状态 -all将添加inactive单元。
systemctl list-units --type=service --all

systemctl list-units-files --type=service #查看 enable和disable单元设置。

system --falied --type=service #仅查看failed服务。

开启与停止系统守护进程。

systemctl stop sshd.service #停止sshd服务。
systemctl start sshd.service #开启sshd 服务。

Reload 与restart,reload重新加载服务,进程不会断掉,PID号不改变;restart关闭服务再开启,给予 新的PID号。

systemctl reload sshd.service
systemctl restart sshd.service

systemctl list--dependencies --type=service #查看服务的依赖服务。

Masking 服务。即便使用restart也不能开启。用于两个服务冲突,只能使用一个如:iptables,firewalld

systemct	l mask iptables #禁止iptables
systemctl unmask iptables #解锁iptables

在开机的时候开启服务或者停止服务。

systemctl enable sshd #在开机的时候开启服务 类似于6版本的chkconfig on
systemctl disable sshd 

在这里插入图片描述
控制BOOT进程
选择systemd target
在这里插入图片描述

systemctl list-dependencies graphical.target | grep target #查看target的依赖关系
systemctl list-units --type=target --all #查看所有可用的target
systemctl list-unit--files --type=target --all #查看已经安装在磁盘的target

1.systemctl isolate multi-user.taget #临时切换到命令模式。

2.systemctl get-default #查看默认的target
  systemctl set-default graphical.target #设置默认的target

3.systemd.unit=rescue.target #在开机的时候启动target,设置在linux 16行

诊断和修复 systemd boot
如果在开启服务的时候出现问题,可以使用#systemctl enable debug-shell.service
或者进入紧急和救援模式。

systemctl list-jobs systemd #产生一堆作业号码,用于排错。

请珍惜劳动成果,支持原创,欢迎点赞或者关注收藏,你每一次的点赞和收藏都是作者的动力,内容如有问题请私信随时联系作者,谢谢!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小Eason哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值