查看错误日志
使用命令 sudo ausearch -m avc -ts recent 或 sudo cat /var/log/audit/audit.log | grep avc 查看SELinux拒绝访问的详细信息。
临时禁用SELinux
执行 sudo setenforce 0 切换至Permissive模式(仅记录日志,不拦截操作),重启后失效。
永久修改SELinux模式
编辑 /etc/selinux/config 文件,将 SELINUX=enforcing 改为 disabled 或 permissive,重启系统生效。
调整策略或上下文
chcon -t 类型 文件路径 临时修改上下文,或用 semanage fcontext -a -t 类型 "路径" 永久设置,再执行 restorecon -Rv 路径 应用规则。semanage port -a -t 端口类型 -p 协议 端口号 开放端口,或通过 getsebool -a 查看并设置相关布尔值(如 setsebool -P httpd_can_network_connect on)。生成自定义策略模块
若需允许特定操作,用 audit2allow -a -M 模块名 生成策略文件,再执行 semodule -i 模块名.pp 加载。
注意:优先通过调整策略或上下文解决问题,避免直接禁用SELinux,以免降低系统安全性。若无法解决,建议备份配置并寻求专业支持。