<p>在CentOS6.2 中安装intel 的c++和fortran 的编译器时,遇到来一个关于SELinux的强制模式不可执行的情况,</p><p>需要关闭SELinux 或者 将enforcing改为 permissive 模式,查询来一些资料后,先对SELinux的几种模式,以及其之间的关系和转换方法做一小结,以备以后查看和学习。</p><p>SELinux 的启动、关闭与查看</p><p>1、并非所有的 Linux distributions 都支持 SELinux</p><p>目前 SELinux 支持三种模式,分别如下:</p><p>•enforcing:强制模式,代表 SELinux 运作中,且已经正确的开始限制 domain/type 了; •permissive:宽容模式:代表 SELinux 运作中,不过仅会有警告讯息并不会实际限制 domain/type 的存取。这种模式可以运来作为 SELinux 的 debug 之用;</p><p>•disabled:关闭,SELinux 并没有实际运作。</p><p>2,查看SELinux的模式</p><p># getenforce Enforcing &lt;==就显示出目前的模式为 Enforcing</p><p>3,查看 SELinux 的政策 (Policy)?</p><p>[root@master oracle]# sestatus</p><p>SELinux status: enabled &lt;==是否启动 SELinux</p><p>SELinuxfs mount: /selinux &lt;==SELinux 的相关文件资料挂载点</p><p>Current mode: enforcing &lt;==目前的模式</p><p>Mode from config file: enforcing &lt;==设定档指定的模式</p><p>Policy version: 21</p><p>Policy from config file: targeted &lt;==目前的政策为何?</p><p>4,通过配置文件调整SELinux的参数</p><p>[root@www ~]# vi /etc/selinux/config</p><p>SELINUX=enforcing &lt;==调整 enforcing|disabled|permissive</p><p>SELINUXTYPE=targeted &lt;==目前仅有 targeted 与 strict</p><p>5,SELinux 的启动与关闭</p><p>【重要常识】上面是预设的政策与启动的模式!你要注意的是,如果改变了政策则需要重新开机;如果由 enforcing 或 permissive 改成 disabled ,或由 disabled 改成其他两个,那也必须要重新开机。这是因为 SELinux 是整合到核心里面去的, 你只可以在 SELinux 运作下切换成为强制 (enforcing) 或宽容 (permissive) 模式,不能够直接关闭 SELinux 的!</p><p>同时,由 SELinux 关闭 (disable) 的状态到开启的状态也需要重新开机啦!所以,如果刚刚你发现 getenforce 出现 disabled 时, 请到上述文件修改成为 enforcing 吧!</p><p>【重点】如果要启动SELinux必须满足以下两个点:</p><p>所以,如果你要启动 SELinux 的话,请将上述的 SELINUX=enforcing 设定妥当,并且指定 SELINUXTYPE=targeted 这一个设定, 并且到 /boot/grub/menu.lst 这个文件去,看看核心有无关闭 SELinux 了呢?</p><p>[root@www ~]# vi /boot/grub/menu.lst</p><p>default=0</p><p>timeout=5</p><p>splashimage=(hd0,0)/grub/splash.xpm.gz</p><p>hiddenmenu</p><p>title CentOS (2.6.18-92.el5)</p><p> root (hd0,0)</p><p> kernel /vmlinuz-2.6.18-92.el5 ro root=LABEL=/1 rhgb quiet selinux=0</p><p> initrd /initrd-2.6.18-92.el5.img</p><p># 如果要启动 SELinux ,则不可以出现 selinux=0 的字样在 kernel 后面!</p><p>【问题】通过上面的学习我们知道,如果将启动着的SELinux改为禁用,需要重启电脑,我们不想重启电脑又不想开启SELinux该怎么办呢?</p><p>【答案】将强制模式改为宽松模!</p><p>[root@www ~]# setenforce [0|1]</p><p>选项与参数:</p><p>0 :转成 permissive 宽容模式;</p><p>1 :转成 Enforcing 强制模式</p><p>范例一:将 SELinux 在 Enforcing 与 permissive 之间切换与查看</p><p>[root@www ~]# setenforce 0</p><p>[root@www ~]# getenforce Permissive</p><p>[root@www ~]# setenforce 1</p><p>[root@www ~]# getenforce Enforcing</p><p>6,查看已启动程序的type设定</p><p>[root@master oracle]# ps aux -Z</p><p>LABEL USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND</p><p>system_u:system_r:init_t root 1 0.0 0.4 2060 520 ? Ss May07 0:02 init [5 system_u:system_r:kernel_t root 2 0.0 0.0 0 0 ? S&lt; May07 0:00 [migra] system_u:system_r:kernel_t root 11 0.0 0.0 0 0 ? S&lt; May07 0:00 [kacpi] system_u:system_r:auditd_t root 4022 0.0 0.4 12128 560 ? S&lt;sl May07 0:01 auditd system_u:system_r:auditd_t root 4024 0.0 0.4 13072 628 ? S&lt;sl May07 0:00 /sbin/a system_u:system_r:restorecond_t root 4040 0.0 4.4 10284 5556 ? Ss May07 0:00 /usr/sb</p><p>说明:其实这些东西我们都不用管,都是SELinux内置的。只要学会在强制和宽松模式间转换就行了!</p><p>小结附:</p><p>关闭SELinux的方法:</p><p>修改/etc/selinux/config文件中的SELINUX=&quot;&quot; 为 disabled ,然后重启。</p><p>如果不想重启系统,使用命令setenforce 0</p><p>注:</p><p>setenforce 1 设置SELinux 成为enforcing模式</p><p>setenforce 0 设置SELinux 成为permissive模式</p><p>在lilo或者grub的启动参数中增加:selinux=0,也可以关闭selinux</p><p>#---------------------------------------------------------------</p><p>查看selinux状态:</p><p>/usr/bin/setstatus -v</p><p>如下:</p><p>SELinux status: enabled</p><p>SELinuxfs mount: /selinux</p><p>Current mode: permissive</p><p>Mode from config file: enforcing</p><p>Policy version: 21</p><p>Policy from config file: targeted</p><p></p><p>getenforce/setenforce查看和设置SELinux的当前工作模式</p><p>#-----------------------------------------------------------------------</p><p> 发现服务一启动,马上停止,在网上查找资料,找到安装时要先禁用SELinux,再安装MySQL,步骤是:</p><p>1. 关闭SELinux,重启系统;</p><p>2. 安装MySQL(MySQL server应该可以启动了);</p><p>3. 启用SELinux,重启系统,之后MySQL server就可以正常启动了。</p><p> 启用禁用SELinux的方法是:</p><p> vi /etc/selinux/config(也有人说是/etc/sysconfig/selinux文件,其实两个之间是链接关系,随便改其中一个,另一个也改了)</p><p> SELINUX=disable 禁用SeLinux</p><p> SELINUX=enforcing 启用SeLinux</p><p>CentOS系统如何快速关闭SELINUX</p><p>SELinux是一种基于 域-类型 模型(domain-type)的强制访问控制(MAC)安全系统,它由NSA编写并设计成内核模块包含到内核中,相应的某些安全相关的应用也被打了 SELinux的补丁,最后还有一个相应的安全策略。虽然CentOS系统相比较而言相对安全稳定。我在长期的linux实践中总结的经验 是:SElinux是php的天敌。</p><p>  我们经常由于CentOS系统默认系统的安全性配置导致些莫名其妙的问题,比如SElinux本来是用于安全子系统的权限控制,可是搞不好就发现限制多多,我们可以用如下方法快速关闭SElinux。</p><p>  /usr/sbin/setenforce 0 立刻关闭SELINUX</p><p>  /usr/sbin/setenforce 1 立刻启用 SELINUX</p><p>  加到系统默认启动里面</p><p>  echo &quot;/usr/sbin/setenforce 0&quot; &gt;&gt; /etc/rc.local</p><p>  这样,我们在不需要在CentOS系统中开启SELINUX的时候,就可以快速的去关闭了,以及在需要的时候,在开启它。</p>
RangeTime:0.003360s
RangeMem:203.24 KB
返回顶部 留言