大网数据广告活动
服务器运维问答

SELinux preventing mongod search access

· 52CE 我爱测

I noticed I am getting some SELinux errors when running mongod for the UniFi controller program. Namely, I am getting: SELinux is preventing /usr/bin/mongod from search access on the directory /. SELinux is preventing /usr/bin/mo…

问题原文

原帖链接 · kwodzicki · CC BY-SA 4.0

I noticed I am getting some SELinux errors when running mongod for the UniFi controller program. Namely, I am getting:

SELinux is preventing /usr/bin/mongod from search access on the directory /.

SELinux is preventing /usr/bin/mongod from search access on the directory /var/lib/nfs

SELinux is preventing /usr/bin/mongod from search access on the directory fs

SELinux is preventing /usr/bin/mongod from search access on the directory /var/lib/snapd

I don't see any reason as to why mongod needs search access to any of these directories and I am wondering if/how I can disable it trying to search them and I don't think giving it access to my entire system is really a solution.

The actual database is stored, it is in the default location (config file below) and the SELinux types are set correctly for those directories as the service does seem to run and no errors are thrown about accessing /var/lib/mongo.

# mongod.conf                                                                   
                                                                                
# for documentation of all options, see:                                        
#   http://docs.mongodb.org/manual/reference/configuration-options/             
                                                                                
# where to write logging data.                                                  
systemLog:                                                                      
  destination: file                                                             
  logAppend: true                                                               
  path: /var/log/mongodb/mongod.log                                             
                                                                                
# Where and how to store data.                                                  
storage:                                                                        
  dbPath: /var/lib/mongo                                                        
  journal:                                                                      
    enabled: true                                                               
#  engine:                                                                      
#  wiredTiger:                                                                  
                                                                                
# how the process runs                                                          
processManagement:                                                              
  fork: true  # fork and run in background                                      
  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile               
  timeZoneInfo: /usr/share/zoneinfo                                             
                                                                                
# network interfaces                                                            
net:                                                                            
  port: 27017                                                                   
  bindIp: 127.0.0.1  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

已采纳解答

原帖链接 · jplc · CC BY-SA 4.0

I had the same issue with MongoDB-7 on RHEL9 and as @kwodzicki I don't want to modify SELinux creating a new policy and so on, because I don't need MongoDB access to NFS or retrieve statistic information because of FTDC for my DEV environment.

After read the documentation shared by @hq: Full Time Diagnostic Data Capture (FTDC) I solved this issue. Just in case, just add next lines to /etc/mongod.conf

setParameter:
  diagnosticDataCollectionEnabled: false

Then restart MongoDB:

# systemctl restart mongod

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-02-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。