可以看到系统会出现错误,这个情况就属于类型标识符的使用
查看一下/var/www/html的目录标识符
[root@localhost ~]# ll -dZ /var/www/html
drwxr-xr-x root root system_u:object_r:httpd_sys_content_t /var/www/html
再查看一下/html的目录标识符
[root@localhost ~]# ll -dZ /html
drwxr-xr-x root root root:object_r:default_t /html
可以看出/var/www/html的目录标识符属于httpd域,而/html则属于default_t,而httpd_t域运行的httpd程序只能监听httpd_port-t类型的端口,并限制此域的进程只能存取标记为httpd_sys_content_t的网页文件,所以httpd服务不能正常启动
但是并不是开启了SELinux就不能够改变主目录的位置,我们可以把/html目录修改为httpd_t的域,可以使用chcon命令来更改,我们把/html的域更改为httpd_t的域
[root@localhost ~]# chcon -t httpd_sys_content_t /html
[root@localhost ~]# ll -dZ /html
drwxr-xr-x root root root:object_r:httpd_sys_content_t /html
现在我们再次启动一次http服务
[root@localhost ~]# service httpd start
Starting httpd: [ OK ]
启动成功!!!!!!!
有时候我们又想改变http服务的端口,那么应该怎么办,可以直接启动吗,我们可以尝试着启动一次
把服务器端口更改为800
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
将Listen 80 改为: Listen 800
先安装一个调试工具
[root@localhost Server]# yum install setroubleshoot
启动setroubleshoot服务
[root@localhost Server]# service setroubleshoot start
Starting setroubleshootd: [ OK ]
启动http服务器
[root@localhost ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: (13)Permission denied: make_sock: could not bind to address [::]:800
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:800
no listening sockets available, shutting down
Unable to open logs [FAILED]
这次直接提示了:不能绑定本机的800端口,也可以查看日志
[root@localhost Server]# tail /var/log/messages 可以看到错误提示
Dec 27 00:51:56 localhost setroubleshoot: SELinux is preventing tpvmgp (cupsd_t) "execute_no_trans" to /usr/lib/vmware-tools/bin32/appLoader (lib_t). For complete SELinux messages. run sealert -l 383d449b-4b8c-49aa-b7f0-f19bb5499555
并且让运行代码查看清楚的错误信息:sealert -l 383d449b-4b8c-49aa-b7f0-f19bb5499555,我们可以自行查看其详细信息。
现在提示是不能绑定800端口,那是因为SELinux把httpd的端口固定了几个默认的端口
[root@localhost Server]# semanage port -l | grep http
http_cache_port_t tcp 3128, 8080, 8118, 11211, 10001-10010
http_cache_port_t udp 3130, 11211
http_port_t tcp 80, 443, 488, 8008, 8009, 8443
pegasus_http_port_t tcp 5988
pegasus_https_port_t tcp 5989
可以看到关于http的所有端口使用情况,但是800并没有在默认使用行列中,所以系统不能绑定这个端口,也就启动不了服务。
但是我们可以通过semanage命令来把这个端口添加到http可以使用的行列中
[root@localhost ~]# semanage port -a -t http_port-t _p tcp 800
再查看一次端口使用行列
[root@localhost ~]# semanage port -l | grep http
http_cache_port_t tcp 3128, 8080, 8118, 11211, 10001-10010
http_cache_port_t udp 3130, 11211
http_port_t tcp 800, 80, 443, 488, 8008, 8009, 8443
pegasus_http_port_t tcp 5988
pegasus_https_port_t tcp 5989
现在800端口已经可以被http服务使用了,我们可以正常启动http服务了
[root@localhost ~]# service httpd start
Starting httpd: [ OK ]
服务正常启动!!!!!!!
