MongoDB 的 SELinux 设置

MongoDB 的 SELinux 设置

我正在尝试从 mongodb.org 存储库在 CentOS 7.2 上安装 MongoDB。到目前为止一切顺利,但主机提供商为所有 MongoDB 数据文件创建了一个辅助磁盘 (/mongo)。这与 SELinux 权限冲突,导致 MongoDB 无法启动。我已通过运行 来启动它setenforce 0,但这并不是我真正想要运行生产服务器的方式。

我有相当多的 Linux 经验,但我所有的 SELinux 经验只是关闭它。我发现这个 CentOS SELinux 教程这让我想到跑步

[user@machine lib]$ sudo chcon -Rv --type mongod_var_lib_t /mongo
changing security context of ‘/mongo/mongod.lock’
changing security context of ‘/mongo/journal/WiredTigerLog.0000000001’
changing security context of ‘/mongo/journal/WiredTigerPreplog.0000000001’
changing security context of ‘/mongo/journal/WiredTigerPreplog.0000000002’
changing security context of ‘/mongo/journal’
changing security context of ‘/mongo/WiredTiger.lock’
changing security context of ‘/mongo/WiredTiger’
changing security context of ‘/mongo/WiredTiger.wt’
changing security context of ‘/mongo/WiredTiger.turtle’
changing security context of ‘/mongo/WiredTigerLAS.wt’
changing security context of ‘/mongo/sizeStorer.wt’
changing security context of ‘/mongo/_mdb_catalog.wt’
changing security context of ‘/mongo/storage.bson’
changing security context of ‘/mongo/collection-0-7567754672580995921.wt’
changing security context of ‘/mongo/index-1-7567754672580995921.wt’
changing security context of ‘/mongo/diagnostic.data/metrics.2016-04-14T06-51-54Z-00000’
changing security context of ‘/mongo/diagnostic.data/metrics.interim’
changing security context of ‘/mongo/diagnostic.data’
changing security context of ‘/mongo’
[user@machine lib]$ ls -Z /mongo
-rw-r--r--. mongod mongod system_u:object_r:mongod_var_lib_t:s0 collection-0-7567754672580995921.wt
drwxr-xr-x. mongod mongod system_u:object_r:mongod_var_lib_t:s0 diagnostic.data
-rw-r--r--. mongod mongod system_u:object_r:mongod_var_lib_t:s0 index-1-7567754672580995921.wt
drwxr-xr-x. mongod mongod system_u:object_r:mongod_var_lib_t:s0 journal
-rw-r--r--. mongod mongod system_u:object_r:mongod_var_lib_t:s0 _mdb_catalog.wt
-rw-r--r--. mongod mongod system_u:object_r:mongod_var_lib_t:s0 mongod.lock
-rw-r--r--. mongod mongod system_u:object_r:mongod_var_lib_t:s0 sizeStorer.wt
-rw-r--r--. mongod mongod system_u:object_r:mongod_var_lib_t:s0 storage.bson
-rw-r--r--. mongod mongod system_u:object_r:mongod_var_lib_t:s0 WiredTiger
-rw-r--r--. mongod mongod system_u:object_r:mongod_var_lib_t:s0 WiredTigerLAS.wt
-rw-r--r--. mongod mongod system_u:object_r:mongod_var_lib_t:s0 WiredTiger.lock
-rw-r--r--. mongod mongod system_u:object_r:mongod_var_lib_t:s0 WiredTiger.turtle
-rw-r--r--. mongod mongod system_u:object_r:mongod_var_lib_t:s0 WiredTiger.wt

可以解决问题。之后,我做了一个touch /.autorelabel并重新启动。不幸的是,这并没有解决手头的问题。我该如何解决这个问题?

当前错误为:[user@machine lib]$ systemctl status mongod ● mongod.service - SYSV: Mongo is a scaling, document-driven database. Loaded: loaded (/etc/rc.d/init.d/mongod) Active: failed (Result: exit-code) since Thu 2016-04-14 09:02:54 CEST; 2s ago Docs: man:systemd-sysv-generator(8) Process: 2180 ExecStart=/etc/rc.d/init.d/mongod start (code=exited, status=1/FAILURE)

Apr 14 09:02:54 LMG-TA-MONGO01.boolhosting.tld systemd[1]: Starting SYSV: Mongo is a scalable, document-oriented database....
Apr 14 09:02:54 LMG-TA-MONGO01.boolhosting.tld runuser[2187]: pam_unix(runuser:session): session opened for user mongod by (uid=0)
Apr 14 09:02:54 LMG-TA-MONGO01.boolhosting.tld runuser[2187]: pam_unix(runuser:session): session closed for user mongod
Apr 14 09:02:54 LMG-TA-MONGO01.boolhosting.tld mongod[2180]: Starting mongod: [FAILED]
Apr 14 09:02:54 LMG-TA-MONGO01.boolhosting.tld systemd[1]: mongod.service: control process exited, code=exited status=1
Apr 14 09:02:54 LMG-TA-MONGO01.boolhosting.tld systemd[1]: Failed to start SYSV: Mongo is a scalable, document-oriented database..
Apr 14 09:02:54 LMG-TA-MONGO01.boolhosting.tld systemd[1]: Unit mongod.service entered failed state.
Apr 14 09:02:54 LMG-TA-MONGO01.boolhosting.tld systemd[1]: mongod.service failed.

答案1

如果你想以简单的方式为 Mongo 配置 SELINUX - 尝试审计为什么在你的 /var/log/audit/audit.log 上查看哪些类型的违规行为会被拒绝,并使用audit2allow. 它在 80% 的事故中都有效。

如果仍然有问题 - 请运行 audit2why 并手动修复其他问题。也许我们可以在这一步为您提供帮助。

答案2

运行sudo sealert -a /var/log/audit/audit.log在这里提供了一些有用的见解和有关 SELinux 配置更改的建议。(我们还更改了 dbPath 值mongod.conf。)

答案3

chcon system_u:object_r:mongod_var_lib_t:s0 mongodb

是什么帮我解决了这个问题。2auditallow 和所有的 jazz 甚至按照输出都没有journalctl -xe起作用

相关内容