linux禁止开机启动服务器,如何关闭SELinux并设置开机不启动

在安装和配置软件时遇到由于SELinux限制导致的服务启动失败,主要表现为无法绑定到指定端口。解决方法是临时关闭SELinux的强制执行模式,或者永久修改配置文件将SELinux设置为disabled,从而避免开机启动时的影响。
摘要由CSDN通过智能技术生成

在安装软件的过程中,经常遇到修改常用工具的默认端口时,会经常启动失败,失败原因是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就不会开机启用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值