我在CentOS 7上运行Apache 2.4。已启用SE Linux。应用程序使用Laravel(Lumen),并连接到另一台服务器上的MongoDB。我们所有的服务器都在Google云中。应用程序无法加载网页,lumen.log有如下错误lumen.ERROR: MongoDB\Driver\Exception\ConnectionTimeoutException: No suitable servers found (
serverSelectionTryOnceset): [Failed to resolve 'mongo.***.***'] in /var/www/***/vendor/mongodb/mongodb/src/Collection.php:612
如果SE-Linux被禁用,它就会工作。我有以下的洗发水套装
httpd_can_network_connect --> on
httpd_can_network_connect_db --> on
httpd_can_network_relay --> on
还有什么要安排的吗?如何解决这个问题?
最佳答案
我安装了setroubleshoot和setoolsyum install setroubleshoot setools
并用来分析audit.log。sealert -a /var/log/audit/audit.log
结果是apache无法读取/etc/hosts并转到MongoDB服务器。ls -lZ /etc/hosts-rw-r--r--. root root system_u:object_r:unlabeled_t:s0 /etc/hosts
执行restorecon /etc/hosts
改成了-rw-r--r--. root root system_u:object_r:net_conf_t:s0 /etc/hosts
解决了这个问题。