MongoDB -无法运行,因为SELinux阻止mongod对文件/proc/sys/net/ipv4/tcp_fastopen进行开放访问

k10s72fa  于 2023-05-06  发布在  Go
关注(0)|答案(5)|浏览(185)

安装后,我的mongod服务器运行良好。我已经创建了用户并重新启动服务器,没有问题。
但是现在当通过将www.example.com添加到bindip来修改gonfi文件0.0.0.0时,服务器不会重新启动。错误消息为

Jan 24 11:59:53 localhost.localdomain setroubleshoot[4656]: failed to retrieve rpm info for /proc/sys/net/ipv4/tcp_fastopen
Jan 24 11:59:54 localhost.localdomain setroubleshoot[4656]: SELinux is preventing mongod from open access on the file /proc/sys/net/ipv4/tcp_fastopen. For complete SELinux messag>
Jan 24 11:59:54 localhost.localdomain setroubleshoot[4656]: SELinux is preventing mongod from open access on the file /proc/sys/net/ipv4/tcp_fastopen.
                                                            
                                                            *****  Plugin catchall (100. confidence) suggests   **************************
                                                            
                                                            If you believe that mongod should be allowed open access on the tcp_fastopen file by default.
                                                            Then you should report this as a bug.
                                                            You can generate a local policy module to allow this access.
                                                            Do
                                                            allow this access for now by executing:
                                                            # ausearch -c 'mongod' --raw | audit2allow -M my-mongod
                                                            # semodule -X 300 -i my-mongod.pp

提供的“解决方案”

# ausearch -c 'mongod' --raw | audit2allow -M my-mongod
# semodule -X 300 -i my-mongod.pp

并不能解决问题
Mongodb文档说版本4默认使用tcp_fastopen激活,我找不到如何应用semanage permissive来使用tcp_fastopen。
先谢谢你了

rryofs0p

rryofs0p1#

如果您在RHEL、CentOS或Oracle Linux上运行,请按照MongoDB服务器的官方SELinux策略的说明进行操作:

sudo yum install -y git make checkpolicy policycoreutils selinux-policy-devel

git clone https://github.com/mongodb/mongodb-selinux
cd mongodb-selinux
make
sudo make install
but5z9lq

but5z9lq2#

验证您的操作系统是否受MongoDB支持。
安装一个普通版本的操作系统,不要更改任何设置,使用已发布的MongoDB文档安装MongoDB并使其工作。
确定当前安装和普通安装之间的差异。
用调查结果更新您的问题。

58wvjzkj

58wvjzkj3#

我找不到这个确切错误的答案。我都快把头发拔光了。最后我查看了mongod.log文件。它有一个权限被拒绝的错误。journalctl显示了tcp_fastopen,所以我正在排除SELinux的故障,而它实际上是一个权限拒绝错误。希望这能帮助其他遇到这个错误的人。

r8xiu3jd

r8xiu3jd4#

我把mongod升级到4.4.6后也遇到了同样的问题。我最终应用了建议的here,手动编译模块。现在起作用了!我做了很多尝试,所以我不能100%肯定我所做的是超过必要的。audit 2allow命令不包括规则
allow mongod_t sysctl_net_t:file { getattr read open };

# cat > mongodb_sysctl_net.te << EOF
module mongodb_sysctl_net 1.0;

require {
    type mongod_t;
    type sysctl_net_t;
    class dir search;
    class file { getattr read open };
}

#============= mongod_t ==============
allow mongod_t sysctl_net_t:dir search;
allow mongod_t sysctl_net_t:file { getattr read open };
EOF

# checkmodule -M -m -o  mongodb_sysctl_net.mod mongodb_sysctl_net.te
# semodule_package -o mongodb_sysctl_net.pp -m mongodb_sysctl_net.mod
# semodule -i mongodb_sysctl_net.pp
# systemctl start mongod.service

注意:我已经安装了以前根据mongodb documentation编写的安装中的策略模块

dvtswwa3

dvtswwa35#

我在使用mongo 4.4 replica-set配置时遇到了同样的问题(关于访问tcp_fastopen的semodule错误)。这不可能是操作系统(oracle linux 8)的问题,因为我在三个相同的复制集节点(相同的更新状态)中的一个节点上出现了错误。系统已经有了官方文档中建议的selinux配置,

semodule -l | grep mongo

返回

mongodb
mongodb_cgroup_memory
mongodb_proc_net

在mongod.log中,我终于找到了:

"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Operation not permitted"}}

我不知道是哪个条件导致了这个状态,但是当我解除套接字的链接时(作为root),mongo守护进程再次启动,到目前为止没有错误。

相关问题