在安装软件的过程中,经常遇到修改常用工具的默认端口或者修改默认配置时,会经常启动失败,失败原因是SELinux限制了修改默认端口和配置,导致启动服务时,抛出了异常。

[root@bigdata2 var]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2018-04-04 09:48:22 CST; 12s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 24040 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
  Process: 24038 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 24038 (code=exited, status=1/FAILURE)

Apr 04 09:48:22 bigdata2 httpd[24038]: (13)Permission denied: AH00072: make_sock: could not bind to address [::]:9104
Apr 04 09:48:22 bigdata2 httpd[24038]: (13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:9104
Apr 04 09:48:22 bigdata2 httpd[24038]: no listening sockets available, shutting down
Apr 04 09:48:22 bigdata2 httpd[24038]: AH00015: Unable to open logs
Apr 04 09:48:22 bigdata2 systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Apr 04 09:48:22 bigdata2 kill[24040]: kill: cannot find process ""
Apr 04 09:48:22 bigdata2 systemd[1]: httpd.service: control process exited, code=exited status=1
Apr 04 09:48:22 bigdata2 systemd[1]: Failed to start The Apache HTTP Server.
Apr 04 09:48:22 bigdata2 systemd[1]: Unit httpd.service entered failed state.
Apr 04 09:48:22 bigdata2 systemd[1]: httpd.service failed.

通过服务的状态,可以看出服务没权限去绑定我们设置的端口。

即时解决不重启服务器的方式如下:

[root@bigdata2 var]# setenforce 0

永久生效设置如下,编辑/etc/selinux/config 的配置文件:

[root@bigdata2 var]# vi /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
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
                                                                                                                                   
~                                                                                                                                    
"/etc/selinux/config" 15L, 565C 

将SELINUX的值设置为:disabled

退出保存,下次重启服务器,SELinux就不会开机启用。

 

 

 

Logo

更多推荐