在Rocky Linux 9 中使用systemctl 控制 nginx 和 php-fpm 总是失败,最后发现是SELinux的问题,禁用它即可正常使用systemctl 命令。
1、sestatus查看selinux工作模式
[root@localhost ~]# sestatus -v
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Memory protection checking: actual (secure)
Max kernel policy version: 33
2、getenforce查看selinux工作模式
[root@localhost ~]# getenforce
Enforcing
3、SELinux的三种工作模式
SELinux有Enforcing、Permissive、Disabled三种模式:
- Enforcing(强制模式):违法SELinux规则的行为将被阻止并记录到日志中。
- Permissive(宽容模式):违反SELinux规则的行为只会记录到日志中。一般调试时使用
- Disabled(关闭模式):SELinux并没有实际运行。
4、临时关闭SELinux
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
5、永久关闭SELinux
[root@localhost ~]# vi /etc/selinux/config
SELINUX=disabled
6、重启生效
reboot