1. 查看selinux状态
SELinux的状态:
-
enforcing:强制,每个受限的进程都必然受限
-
permissive:允许,每个受限的进程违规操作不会被禁止,但会被记录于审计日志
-
disabled:禁用
相关命令:
-
getenforce: 获取selinux当前状态
-
sestatus :查看selinux状态
-
setenforce 0|1 0设置为 permissive 1设置为 enforcing
[root@localhost html]#getenforce
Enforcing
如果没有开启可以使用以下命令开启
[root@localhost html]#setenforce 1
永久开启需要修改 此处文件 /etc/selinux/config
vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing
2.文件类型 :
3.seinfo:
[root@localhost ~]# seinfo -a #查看上下文件的控制类型
4.修改文件类型:
4.1查看httpd进程:
[root@localhost html]# ls -Z
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html
[root@localhost html]#
[root@localhost html]# ps auxZ|grep httpd ###过滤httpd进程
system_u:system_r:httpd_t:s0 root 51859 0.0 0.2 221952 4996 ? Ss 13:50 0:00 /usr/sbin/httpd -DFOREGROUND
system_u:system_r:httpd_t:s0 apache 51860 0.0 0.1 224036 3104 ? S 13:50 0:00 /usr/sbin/httpd -DFOREGROUND
system_u:system_r:httpd_t:s0 apache 51861 0.0 0.1 224036 3104 ? S 13:50 0:00 /usr/sbin/httpd -DFOREGROUND
4.2.用7-1curl访问7-2:
4.3.在7-2中修改文件类型 :
[root@localhost html]# chcon -t var_t /var/www/html/index.html
[root@localhost html]#
[root@localhost html]# ls -Z
-rw-r--r--. root root unconfined_u:object_r:var_t:s0 index.html
[root@localhost html]#
更改查看:
4.4.开一下selinux:
4.5.用7-1再去访问index.html页面:
报错了
4.6.把selinux关掉:
又可以了
5.去7-3改端口:
1.先把selinux开启:
2.去主配置文件中加端口:
3.解决进程与端口绑定问题
6.selinux的配置文件:
[root@localhost html]# vim /etc/selinux/config