诊断CentOS中SELinux问题可按以下步骤操作:
getenforce或sestatus命令确认是否启用及当前模式(Enforcing/Permissive/Disabled)。/var/log/audit/audit.log,用ausearch -m avc -ts recent过滤最近的拒绝事件。audit2why解析日志,了解操作被拒绝的原因。setenforce 0(切换至Permissive模式,仅记录不阻止)。setenforce 1。semanage管理策略,如添加端口、文件上下文规则:semanage port -a -t http_port_t -p tcp 8080(允许HTTP服务使用8080端口)。restorecon恢复文件默认上下文:restorecon -R /path/to/directory。setenforce 1恢复强制模式,验证问题是否解决。/etc/selinux/config,设置SELINUX=disabled/enforcing并重启。工具推荐:
sealert:图形化分析日志,提供解决方案。audit2allow:根据日志生成自定义策略模块。操作前建议备份重要数据,优先通过调整策略而非直接禁用SELinux解决问题。