您的位置:首页 > 运维架构 > Apache

修改APACHE端口后启动出错,原来是SELINUX安全问题。

2012-07-03 09:20 477 查看
更改/etc/httpd/conf/httpd.conf端口号80为81后

[root@localhost tool]# service httpd restart
停止 httpd:[确定]
正在启动 httpd:(13)Permission denied: make_sock: could not bind to address [::]:81  //许可被拒绝,不能绑定这个端口
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:81
no listening sockets available, shutting down
Unable to open logs
[失败]
[root@localhost tool]#
将端口更改为80可以正常启动。于是考虑到安全方面的权限问题,首先看SELINUX
[root@localhost tool]# getenforce
Enforcing   //已开启
[root@localhost tool]# setenforce 0   //暂时关掉它
[root@localhost tool]# getenforce
Permissive
root@localhost tool]# service httpd start
正在启动 httpd:[确定]   //可以正常启动。于是确定是SELINUX的安全问题。但这种关闭的方法实在不是安全的选择。那就要考虑如何设置它的权限。
[root@localhost tool]#
思路:
首先查找make_sock相关的文件,查看是否这个文件的SE安全问题。但并没有找到这个文件。于是上网求助。搜索Permission denied: make_sock: could not bind to address关键字。结果查到以下信息:
semanage port -l|grep http

semanage port -a -t http_port_t -p tcp 81

可我的本机并没有semanage这个命令。于是又有个新的问题。
考虑是否没有安装yum install semagage  没有找到此包。
于是上网求助:semanage安装

# yum provides /usr/sbin/semanage
or
#yum whatprovides /usr/sbin/semanage  //我用的这种方法。

#yum -y install policycoreutils-python
#semanage

root@localhost src]# semanage port -l | grep http  //查看现在支持的httpd端口。发现并没有80
http_cache_port_t tcp 3128, 8080, 8118, 8123, 10001-10010
http_cache_port_t udp 3130
http_port_t tcp 80, 443, 488, 8008, 8009, 8443
pegasus_http_port_t tcp 5988
pegasus_https_port_t tcp 5989
[root@localhost src]# semanage port -a -t http_port_t -p tcp 81  //添加81端口
[root@localhost tool]# service httpd start
正在启动 httpd:
[root@localhost tool]# netstat -tunlp | grep 81  //此时已成功启动
tcp 0 0 :::81 :::* LISTEN 13737/httpd
问题解决。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Apache