温馨提示×

centos怎样检查selinux日志

小樊
50
2026-10-20 08:28:31
栏目: 智能运维

在 CentOS 中,检查 SELinux 相关日志通常有几种常用方式,取决于系统是否使用 auditd 服务。


一、通过 audit 日志(推荐)

SELinux 拒绝(denials)通常会记录在 audit 日志中。

1. 查看 SELinux 拒绝日志

sudo ausearch -m avc -ts recent

常用参数:

  • -m avc:只查看 SELinux AVC 消息
  • -ts recent:最近一段时间
  • -ts today:今天
  • -ts boot:本次启动后

示例:

sudo ausearch -m avc -ts today

2. 实时查看 SELinux 日志

sudo tail -f /var/log/audit/audit.log

二、通过 /var/log/messages(老版本或未运行 auditd)

如果系统未运行 auditd,SELinux 日志可能在:

/var/log/messages

查看方式:

sudo grep SELinux /var/log/messages

或

sudo grep avc /var/log/messages

三、使用 sealert 工具(非常适合排查)

1. 安装 setroubleshoot(如未安装)

sudo yum install -y setroubleshoot-server

2. 查看 SELinux 告警摘要

sudo sealert -a /var/log/audit/audit.log

3. 查看某个 AVC 的详细建议

sudo sealert -l <alert-id>

四、快速判断是否 SELinux 导致的问题

临时关闭 SELinux 测试(仅测试用)

sudo setenforce 0

如果问题消失,基本可确认是 SELinux 导致。

⚠️ 生产环境不建议长期关闭

查看当前状态:

getenforce

五、常见排查命令总结

目的 命令
查看 SELinux 状态 getenforce
查看 AVC 日志 ausearch -m avc
实时日志 tail -f /var/log/audit/audit.log
智能分析 sealert -a /var/log/audit/audit.log

如果你有具体的报错或场景(如 Nginx / FTP / 自定义服务被拒绝),可以把日志贴出来,我可以帮你分析并给出 sebool 或 semanage 的解决命令。

0 踩