在CentOS中调试SELinux可按以下步骤进行:
getenforce或sestatus确认当前模式(Enforcing/Permissive/Disabled)。sudo ausearch -m avc -ts recent查看最近的拒绝记录,或sudo tail -f /var/log/audit/audit.log实时监控日志。audit2why分析拒绝原因,或通过audit2allow生成自定义策略模块:sudo ausearch -m avc -ts recent | audit2allow -M mypol,再加载模块:sudo semodule -i mypol.pp。sudo setenforce 0切换到宽容模式(Permissive),测试后用sudo setenforce 1恢复强制模式。semanage管理文件/端口上下文,例如:sudo semanage fcontext -a -t httpd_sys_content_t "/path/to/directory",然后执行restorecon -R /path/to/directory。sealert分析日志并获取解决方案,或用setroubleshoot辅助排查。注意:修改配置前建议备份重要数据,复杂操作需谨慎,可参考官方文档或寻求专业支持。