在 CentOS(以及 RHEL 系列)中,“context” 通常和 SELinux 有关,常见场景有:
下面按常见需求说明。
setenforce 0
查看状态:
getenforce
# Permissive
编辑配置文件:
vi /etc/selinux/config
修改为:
SELINUX=disabled
重启系统:
reboot
⚠️ 生产环境不建议直接 disabled,可用 permissive
如果你是看到类似:
Permission denied (SELinux context)
setenforce 0
SELinux 仍记录但不阻止。
chcon -t httpd_sys_content_t /var/www/html/index.html
或恢复默认:
restorecon -Rv /var/www
例如 HTTP:
setsebool -P httpd_disable_trans 1
(部分新版 CentOS 已移除该布尔值)
查看拒绝日志:
ausearch -m AVC -ts recent
或:
journalctl -t setroubleshoot
| 需求 | 建议 |
|---|---|
| 测试环境 | SELINUX=disabled |
| 生产环境 | permissive + 修复 context |
| 单文件问题 | chcon / restorecon |
| 服务问题 | setsebool |
如果你能具体说:
我可以给你更精确的命令。