Skip to content

8.4 进程、服务与日志(systemd)

"会启动服务只是起点,会看日志才算入门运维。"

本章目标:掌握进程管理、systemd 服务控制与日志排查基础。

1. 进程查看与管理

bash
ps -ef | head
top
pgrep sshd
kill -15 <PID>
kill -9 <PID>

说明:

  • -15 是优雅终止(建议优先)
  • -9 是强制终止(最后手段)

2. systemd 服务管理

常用命令:

bash
systemctl status sshd
systemctl start sshd
systemctl stop sshd
systemctl restart sshd
systemctl enable sshd
systemctl disable sshd

重点理解:

  • start/stop:当前会话生效
  • enable/disable:开机是否自启

3. 日志查看(journalctl)

bash
journalctl -xe
journalctl -u sshd --since "-30 min"
journalctl -p err -b

常用思路:

  1. 先看服务状态 systemctl status
  2. 再看该服务日志 journalctl -u
  3. 最后定位关键错误关键字(failed / denied / timeout)

4. RHCSA 风格小练习

任务:

  1. 确认 sshd 处于运行状态并设置开机自启。
  2. 故意修改一项错误配置(实验环境中),观察服务启动失败信息。
  3. 通过日志定位问题并修复。

Next: 进入网络与存储的综合实战:8.5 网络、存储与RHCSA综合练习