你说的 “CentOS Context” 一般有两种常见理解,我分别说明,你可以对照看看是哪一种。
SELinux 本身默认就会记录日志,不需要额外“开启”,只要:
查看当前模式:
getenforce
如果不是 Disabled,SELinux 已经在记录上下文相关日志。
/var/log/audit/audit.log
查看 SELinux 拒绝日志:
ausearch -m avc -ts recent
或:
grep "denied" /var/log/audit/audit.log
确认 audit 服务是否运行:
systemctl status auditd
启动并设置开机自启:
systemctl enable --now auditd
安装:
yum install -y setroubleshoot setroubleshoot-server
查看 SELinux 分析结果:
sealert -a /var/log/audit/audit.log
查看某个服务的日志:
journalctl -u 服务名
实时查看:
journalctl -u 服务名 -f
查看本次启动后的日志:
journalctl -b
编辑 service 文件:
systemctl edit 服务名
添加:
[Service]
Environment=SYSTEMD_LOG_LEVEL=debug
重载并重启:
systemctl daemon-reload
systemctl restart 服务名
Docker 容器日志:
docker logs 容器名
Podman:
podman logs 容器名
你可以直接回答我一句:
我说的 Context 是 SELinux / systemd / Docker / 某个具体服务?
我可以给你精确到命令级别的答案。