关于小城镇建设的网站做平台外卖的网站需要什么资质
2026/4/18 7:38:13 网站建设 项目流程
关于小城镇建设的网站,做平台外卖的网站需要什么资质,吉林省建设监理协会网站,陕西省西安市建设工程信息网SELinux 介绍 基本原理SELinux默认策略允许apache进程访问在/var/www/html文件夹下的文件和文件夹#xff0c;以及其 他一些具有httpd_sys_content_t上下文的文件夹#xff0c;禁止访问具有其他不匹配标签的目录。在 SELinux 的保护下#xff0c;apache进程不允许访问/tmp和…SELinux 介绍基本原理SELinux默认策略允许apache进程访问在/var/www/html文件夹下的文件和文件夹以及其他一些具有httpd_sys_content_t上下文的文件夹禁止访问具有其他不匹配标签的目录。在 SELinux 的保护下apache进程不允许访问/tmp和/var/tmp目录。因为/tmp、/var/tmp目录的标签是tmp_t与默认策略不匹配。命令选项 -Z许多处理文件的命令都一个-Z 选项用于显示和设置SELinux上下文。[rootcentos7 ~]# ps -C sshd -ZLABEL PID TTY TIME CMD system_u:system_r:sshd_t:s0-s0:c0.c1023951? 00:00:00 sshd system_u:system_r:sshd_t:s0-s0:c0.c10231261? 00:00:00 sshd unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c10231276? 00:00:00 sshd system_u:system_r:sshd_t:s0-s0:c0.c10232455? 00:00:00 sshd unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c10232459? 00:00:00 sshd[rootcentos7 ~]# ls -Z /homeunconfined_u:object_r:user_home_dir_t:s0 laoma# 其他命令中 -Z 选项# cp -Z set SELinux security context of destination file to defaulttype# mkdir -Z set SELinux security context of each created directoryto the defaulttypeSELinux 模式enforcing 模式 SELinux强制执行访问控制规则。 在强制模式下如果规则没有明确允许访问则拒绝访问并写入日志。此模式是默认模式。Permissive 模式SELinux 加载策略并处于活动状态但不强制执行访问控制规则⽽是记录访问违规。此模式有助于对应用和规则进行测试和故障排除。disable 模式完全关闭 SELinux。不拒绝任何SELinux违规不予记录。查看当前模式[rootcentos7 ~]# getenforce更改当前模式[rootcentos7 ~]# setenforceusage: setenforce[Enforcing|Permissive|1|0]# 强制模式临时切换为允许模式[rootcentos7 ~]# setenforce 0# 或者[rootcentos7 ~]# setenforce Permissive# 允许模式临时切换为强制模式[rootcentos7 ~]# setenforce 1# 或者[rootcentos7 ~]# setenforce Enforcing模式切换注意事项强制模式和允许模式之间变更不需要重启系统。从强制模式或者允许模式变更到禁用模式或者从禁用模式变更到强制模式或者允许模式都需要重启系统。更改 SELinux 默认模式[rootcentos7 ~]# vim /etc/selinux/configSELINUXenforcingSELINUXTYPEtargeted在启动时通过将向内核传递参数来设置SELinux 模式enforcing1设置强制模式。enforcing0设置许可模式。selinux0来彻底禁用 SELinux。selinux1启用 SELinux当设置enforcing参数是该参数可以省略。实验 selinux模式为enforcing情况下破解root密码。破解完成后不执行 touch /.autorelabel命令。重启测试使用正确的密码登录。结果登录失败。原因用户验证程序无法访问/etc/shadow因为破解密码过程中/etc/shadow文件标签被破坏了。处理方法系统启动时内核添加参数 selinux1 enforcing0控制文件 SELinux 上下文新文件默认 SELinux 上下文新文件通常从父目录继承其SELinux上下文从而确保它们具有适当的上下文。[rootcentos7 ~]# touch /tmp/laoma[rootcentos7 ~]# ls -1dZ /tmp /tmp/laomasystem_u:object_r:tmp_t:s0 /tmp unconfined_u:object_r:user_tmp_t:s0 /tmp/laoma[rootcentos7 ~]# cp /tmp/laoma /root/laoma[rootcentos7 ~]# ls -1dZ /tmp /tmp/laoma /root /root/laomasystem_u:object_r:admin_home_t:s0 /root unconfined_u:object_r:admin_home_t:s0 /root/laoma system_u:object_r:tmp_t:s0 /tmp unconfined_u:object_r:user_tmp_t:s0 /tmp/laoma以下两种情况文件的 SELinux 上下文保持不变cp -a 命令复制移动文件[rootcentos7 ~]# cp -a /tmp/laoma /root/laoma-a[rootcentos7 ~]# ls -1dZ /tmp /tmp/laoma /root /root/laoma*system_u:object_r:admin_home_t:s0 /root unconfined_u:object_r:admin_home_t:s0 /root/laoma unconfined_u:object_r:user_tmp_t:s0 /root/laoma-a system_u:object_r:tmp_t:s0 /tmp unconfined_u:object_r:user_tmp_t:s0 /tmp/laoma[rootcentos7 ~]# mv /tmp/laoma /root/laoma-mv[rootcentos7 ~]# ls -1dZ /tmp /root /root/laoma*system_u:object_r:admin_home_t:s0 /root unconfined_u:object_r:admin_home_t:s0 /root/laoma1 unconfined_u:object_r:user_tmp_t:s0 /root/laoma-a unconfined_u:object_r:user_tmp_t:s0 /root/laoma-mv system_u:object_r:tmp_t:s0 /tmp设置文件 SELinux 上下文设置文件上下文命令chcon 命令直接更改文件SELinux上下文。但是它不会将上下文更改保存到 SELinux 上下文数据库中。系统下一次对所有文件进行 relabel 操作时将导致该上下文恢复。它对于测试和实验很有用。restorecon 命令根据 SELinux上下文数据库中规则恢复文件SELinux上下文。原先通过chcon命令所做的更改将失效。示例[rootcentos7 ~]# mkdir /www[rootcentos7 ~]# ls -Zd /wwwunconfined_u:object_r:default_t:s0 /www[rootcentos7 ~]# chcon -t httpd_sys_content_t /www[rootcentos7 ~]# ls -Zd /wwwunconfined_u:object_r:httpd_sys_content_t:s0 /www[rootcentos7 ~]# restorecon -v /wwwRelabeled /www from unconfined_u:object_r:httpd_sys_content_t:s0 to unconfined_u:object_r:default_t:s0[rootcentos7 ~]# ls -Zd /wwwunconfined_u:object_r:default_t:s0 /wwwsemanage fcontext 命令用于管理SELinux上下文数据库中规则restorecon 命令根据这些规则恢复文件上下文。semanage fcontext命令使用扩展的正则表达式指定路径和文件名。比较常见的扩展正则表达式(/.*)?表示随意匹配/后面接任意数量字符递归匹配文件夹下的子文件和子文件夹。示例[rootcentos7 ~]# echo Hello World /www/index.html[rootcentos7 ~]# ls -Zd /www/index.htmlunconfined_u:object_r:default_t:s0 /www/index.html# 安装 semanage 工具[rootcentos7 ~]# yum install -y policycoreutils-python# 添加默认规则[rootcentos7 ~]# semanage fcontext -a -t httpd_sys_content_t/www(/.*)?[rootcentos7 ~]# semanage fcontext -l |grep ^/www(/.*)?/www(/.*)? all files system_u:object_r:httpd_sys_content_t:s0# 只查看非默认策略[rootcentos7 ~]# semanage fcontext -lCSELinux fcontexttypeContext /www(/.*)? all files system_u:object_r:httpd_sys_content_t:s0# 恢复文件上下文[rootcentos7 ~]# restorecon -Rv /www/Relabeled /www from unconfined_u:object_r:default_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0 Relabeled /www/index.html from unconfined_u:object_r:default_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0[rootcentos7 ~]# ls -1Zd /www/ /www/index.htmlunconfined_u:object_r:httpd_sys_content_t:s0 /www/ unconfined_u:object_r:httpd_sys_content_t:s0 /www/index.html# 删除默认规则[rootcentos7 ~]# semanage fcontext -d -t httpd_sys_content_t/www(/.*)?# 删除目录[rootcentos7 ~]# rm -fr /www示例配置 web 站点主目录# 准备目录[rootcentos7 ~]# mkdir /www[rootcentos7 ~]# echo Hello World /www/index.html[rootcentos7 ~]# semanage fcontext -a -t httpd_sys_content_t/www(/.*)?[rootcentos7 ~]# restorecon -Rv /www/restorecon reset /www context unconfined_u:object_r:default_t:s0-unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /www/index.html context unconfined_u:object_r:default_t:s0-unconfined_u:object_r:httpd_sys_content_t:s0# 安装 httpd[rootcentos7 ~]# yum install -y httpd[rootcentos7 ~]# systemctl enable httpd --now[rootcentos7 ~]# vim /etc/httpd/conf/httpd.conf# 注释122 行DocumentRoot在122行后添加如下内容# DocumentRoot /var/www/htmlDocumentRoot/wwwDirectory/wwwAllowOverride None# Allow open access:Require all granted/Directory# 重启服务[rootcentos7 ~]# systemctl restart httpd# 访问验证[rootcentos7 ~]# curl http://server.laoma.cloud/Hello World控制端口 SELinux 上下文端口 SELinux 上下文SELinux还可以对端口标记。当某个进程希望侦听端口时 SELinux将检查是否允许与该进程相关联的标签绑定该端口标签。 这可以阻止恶意服务控制本应由其他网络服务使用的端口。在 targeted 策略中端口 22/TCP 具有标签 ssh_port_t。端口 80/TCP 和 443/TCP 具有标签 http_port_t。# 查看端口标记[rootcentos7 ~]# semanage port -l | grep http_port_thttp_port_t tcp80,81,443,488,8008,8009,8443,9000pegasus_http_port_t tcp5988# 添加端口标记[rootcentos7 ~]# semanage port -a -t http_port_t -p tcp 18020[rootcentos7 ~]# semanage port -l|grep 18020http_port_t tcp18020,80,81,443,488,8008,8009,8443,9000# 修改网络端口标记[rootcentos7 ~]# semanage port -m -t ssh_port_t -p tcp 18020[rootcentos7 ~]# semanage port -l | grep 18020ssh_port_t tcp18020,22# 删除端口标记[rootcentos7 ~]# semanage port -d -t ssh_port_t -p tcp 18020[rootcentos7 ~]# semanage port -l | grep 108020示例配置 web 站点监听端口[rootcentos7 ~]# vim /etc/httpd/conf/httpd.conf# 修改原先的 Listen 80 为 Listen 18020Listen18020# 重启服务[rootcentos7 ~]# systemctl restart httpdJobforhttpd.service failed because the control process exited with error code. Seesystemctl status httpd.serviceandjournalctl -xefordetails[rootcentos7 ~]# systemctl status httpd.service |cat |grep Per......Nov2911:55:26 rocky.laoma.cloud httpd[3939]:(13)Permission denied: AH00072: make_sock: could notbindto address0.0.0.0:18020......# 配置端口[rootcentos7 ~]# semanage port -a -t http_port_t -p tcp 18020[rootcentos7 ~]# semanage port -l | grep 18020http_port_t tcp18020,80,81,443,488,8008,8009,8443,9000# 只查看改动标签[rootcentos7 ~]# semanage port -lCSELinux Port Type Proto Port Number http_port_t tcp18020# 重启服务并访问[rootcentos7 ~]# systemctl restart httpd# 访问验证[rootcentos7 ~]# curl http://server.laoma.cloud:18020/Hello World控制 SELinux 布尔值SELinux 布尔值SELinux 布尔值是可更改SELinux策略行为的开关可以启用和禁用。# 查看SELinux布尔值[rootcentos7 ~]# getsebool -a |grep httpd_enable_homedirshttpd_enable_homedirs --off[rootcentos7 ~]# getsebool httpd_enable_homedirshttpd_enable_homedirs --off# 设置SELinux布尔值[rootcentos7 ~]# setseboolUsage: setsebool[-NPV]boolean value|bool1val1bool2val2...# 启用value为1或者on或者true# 禁用value为0或者off或者false[rootcentos7 ~]# setsebool httpd_enable_homedirs1或者on或者true[rootcentos7 ~]# setsebool httpd_enable_homedirs0或者off或者false# 持久化设置布尔值使用-P选项修改将写入SELinux数据库。[rootcentos7 ~]# setsebool httpd_enable_homedirs1[rootcentos7 ~]# setsebool -P httpd_enable_homedirs1还可以semanage boolean 命令管理 SELinux 布尔值。[rootcentos7 ~]# semanage booleanusage: semanage boolean[-h][-n][-N][-S STORE][--extract|-- deleteall|--list -C|--modify(--on|--off)boolean]# 查看 SELinux 布尔值[rootcentos7 ~]# semanage boolean -l# 只查看非默认的 SELinux 布尔值[rootcentos7 ~]# semanage boolean -l -C# 设置 SELinux 布尔值[rootcentos7 ~]# semanage boolean -m -1|--on use_nfs_home_dirs[rootcentos7 ~]# semanage boolean -m -0|--off use_nfs_home_dirs# 相当于setsebool -P# 删除原先自定义的 SELinux 布尔值[rootcentos7 ~]# semanage boolean -D示例允许 httpd 访问用户家目录[rootcentos7 ~]# vim /etc/httpd/conf.d/userdir.conf# 修改以下两个参数UserDir enabled UserDir public_html# 重启服务[rootcentos7 ~]# systemctl restart httpd# 设置权限[laomarocky ~]$mkdirpublic_html[laomarocky ~]$echoWelcome to laoma homepublic_html/index.html[laomarocky ~]$ ll /home/ total0drwx------.3laoma laoma81Nov2911:34 laoma[laomarocky ~]$chmodox /home/laoma/# 未启用布尔值访问[rootcentos7 ~]# curl http://server.laoma.cloud:18020/~laoma/!DOCTYPE HTML PUBLIC-//IETF//DTD HTML 2.0//ENhtmlheadtitle403Forbidden/title/headbodyh1Forbidden/h1pYou dont have permission to access this resource./p/body/html# 启用布尔值访问[rootcentos7 ~]# setsebool httpd_enable_homedirs1[rootcentos7 ~]# curl http://server.laoma.cloud:18020/~laoma/Welcome to laoma home调查和解决 SELinux 问题SELinux 文档selinux-policy-doc 软件包附带SELinux man page介绍了 SELinux 使用方法。[rootcentos7 ~]# yum install -y selinux-policy-doc[rootcentos7 ~]# mandb[rootcentos7 ~]# man -k _selinux......httpd_selinux(8)- Security Enhanced Linux Policyforthe httpd processes......[rootcentos7 ~]# man httpd_selinuxsetroubleshoot-server 软件包setroubleshoot-server 软件包中的 setroubleshoot 服务提供了诊断 SELinux 问题的⼯具。当SELinux 拒绝某一操作时会在 /var/log/audit/audit.log 安全⽇志文件中记录一条Access Vector Cache (AVC) 消息。SELinux 故障排除服务会监控 AVC 事件并将事件摘要发送到/var/log/messages 文件。示例基于上述实验环境模拟。# 安装软件包[rootcentos7 ~]# yum install -y httpd setroubleshoot-server# 关闭 httpd_enable_homedirs布尔值[rootcentos7 ~]# setsebool httpd_enable_homedirs0# 监控日志 /var/log/messages[rootcentos7 ~]# tail -f /var/log/messages# 访问站点[rootcentos7 ~]# curl http://server.laoma.cloud:18020/~laoma/Welcome to laoma home# 此时日志显示[rootcentos7 ~]# tail -f /var/log/messages......Nov3010:39:34 server setroubleshoot[4035]: SELinux is preventing /usr/sbin/httpd from getattr access on thefile/home/laoma/public_html/index.html. For complete SELinux messages run: sealert -l bb10b03c-bed2-4853-85cb-92c1824fd75d......# 根据提示进一步查看 SELinux 消息[rootcentos7 ~]# sealert -l bb10b03c-bed2-4853-85cb-92c1824fd75dSELinux is preventing /usr/sbin/httpd from getattr access on thefile/home/laoma/public_html/index.html. ***** Plugin public_content(32.5confidence)suggests ******************** If you want to treat index.html as public content Then you need to change the label on index.html to public_content_t or public_content_rw_t. Do# semanage fcontext -a -t public_content_t/home/laoma/public_html/index.html# restorecon -v /home/laoma/public_html/index.html***** Plugin catchall_boolean(32.5confidence)suggests ****************** If you want to allow httpd toenablehomedirs Then you must tell SELinux about this by enabling thehttpd_enable_homedirsboolean. Do setsebool -P httpd_enable_homedirs1***** Plugin catchall_boolean(32.5confidence)suggests ****************** If you want to allow httpd to unified Then you must tell SELinux about this by enabling thehttpd_unifiedboolean. Do setsebool -P httpd_unified1***** Plugin catchall(4.5confidence)suggests *************************** If you believe that httpd should be allowed getattr access on the index.htmlfileby default. Then you should report this as a bug. You can generate alocalpolicy module to allow this access. Do allow this accessfornow by executing:# ausearch -c httpd --raw | audit2allow -M my-httpd# semodule -X 300 -i my-httpd.pp......提示给出了多种解决方法修改文件上下文。设置布尔值。SELinux 问题处理思路确定是否是 SELinux 引起的。在做调整前首先考虑 SELinux 是否正确的阻止了访问。例如web服务器尝试访问/home目录如果web的内容不是用户发布的那么发生阻止信号是正确的阻止。如果这个访问是被允许的参考下面步骤。最常见的 SELinux 问题是不正确的文件上下文。当文件是另外一个地方创建的然后移动到新的地方而新的地方需要新的上下文。在大多数情况执行restorecon可以修复这个问题。这种修复问题方式对系统其他部分安全影响非常小。另外一个问题可能是布尔值设置不当导致拒绝访问。例如ftpd_anon_write布尔值控制匿名ftp用户是否可以上传文件。如果如需匿名用户上传文件需要打开这个布尔值。调整布尔值需要小心因为对系统影响范围比较大。还有可能是 端口上下文不匹配。还有可能是 SELinux bug。

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询