猫 /etc/yum.repos.d/mongodb-org.repo

猫 /etc/yum.repos.d/mongodb-org.repo

MongoDb 在默认设置下运行良好。

当我将默认日志路径更改cat /etc/mongod.conf为以下内容时,会出现此问题:

systemLog:
  destination: file
  logAppend: true
  path: /var/www/logs/mongodb/mongod.log

以下是我的安装和启动步骤mongod

虽然安装显示成功,但mongod在日志路径更新后无法启动/etc/mongod.conf

猫 /etc/yum.repos.d/mongodb-org.repo

[mongodb-org-6.0]
name=MongoDB Repository
#baseurl=https://repo.mongodb.org/yum/redhat//mongodb-org/6.0/x86_64/
baseurl=https://repo.mongodb.org/yum/redhat/8Server/mongodb-org/6.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc

#安装并运行 mongod 的脚本

echo "Installing mongodb"
sudo yum install -y mongodb-org
mkdir -p "$log_location/mongodb"
sudo systemctl start mongod
echo "Status mongodb"
sudo systemctl status mongod --no-pager

输出:

Installing mongodb
MongoDB Repository                                                                                                                                       5.8 kB/s | 9.4 kB     00:01
Package mongodb-org-4.0.28-1.el8.x86_64 is already installed.
Dependencies resolved.
=========================================================================================================================================================================================
 Package                                                    Architecture                     Version                                     Repository                                 Size
=========================================================================================================================================================================================
Upgrading:
 mongodb-org                                                x86_64                           6.0.1-1.el8                                 mongodb-org-6.0                            11 k
 mongodb-org-tools                                          x86_64                           6.0.1-1.el8                                 mongodb-org-6.0                            11 k
Installing dependencies:
 cyrus-sasl                                                 x86_64                           2.1.27-6.el8_5                              baseos                                     96 k
 mongodb-database-tools                                     x86_64                           100.6.0-1                                   mongodb-org-6.0                            48 M
 mongodb-mongosh                                            x86_64                           1.5.4-1.el8                                 mongodb-org-6.0                            41 M
 mongodb-org-database                                       x86_64                           6.0.1-1.el8                                 mongodb-org-6.0                            11 k
 mongodb-org-database-tools-extra                           x86_64                           6.0.1-1.el8                                 mongodb-org-6.0                            16 k

Transaction Summary
=========================================================================================================================================================================================
Install  5 Packages
Upgrade  2 Packages

Total download size: 89 M
Downloading Packages:
(1/7): mongodb-mongosh-1.5.4.x86_64.rpm                                                                                                                   51 MB/s |  41 MB     00:00
(2/7): mongodb-database-tools-100.6.0.x86_64.rpm                                                                                                          50 MB/s |  48 MB     00:00
(3/7): mongodb-org-database-6.0.1-1.el8.x86_64.rpm                                                                                                        43 kB/s |  11 kB     00:00
(4/7): mongodb-org-database-tools-extra-6.0.1-1.el8.x86_64.rpm                                                                                            66 kB/s |  16 kB     00:00
(5/7): mongodb-org-6.0.1-1.el8.x86_64.rpm                                                                                                                 44 kB/s |  11 kB     00:00
(6/7): mongodb-org-tools-6.0.1-1.el8.x86_64.rpm                                                                                                           41 kB/s |  11 kB     00:00
(7/7): cyrus-sasl-2.1.27-6.el8_5.x86_64.rpm                                                                                                              6.5 kB/s |  96 kB     00:14
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                    5.8 MB/s |  89 MB     00:15
MongoDB Repository                                                                                                                                       660  B/s | 1.7 kB     00:02
Importing GPG key 0x64C3C388:
 Userid     : "MongoDB 6.0 Release Signing Key <[email protected]>"
 Fingerprint: 39BD 841E 4BE5 FB19 5A65 400E 6A26 B1AE 64C3 C388
 From       : https://www.mongodb.org/static/pgp/server-6.0.asc
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                 1/1
  Installing       : mongodb-org-database-tools-extra-6.0.1-1.el8.x86_64                                                                                                             1/9
  Installing       : mongodb-org-database-6.0.1-1.el8.x86_64                                                                                                                         2/9
  Installing       : mongodb-mongosh-1.5.4-1.el8.x86_64                                                                                                                              3/9
  Running scriptlet: cyrus-sasl-2.1.27-6.el8_5.x86_64                                                                                                                                4/9
  Installing       : cyrus-sasl-2.1.27-6.el8_5.x86_64                                                                                                                                4/9
  Running scriptlet: cyrus-sasl-2.1.27-6.el8_5.x86_64                                                                                                                                4/9
  Running scriptlet: mongodb-database-tools-100.6.0-1.x86_64                                                                                                                         5/9
  Installing       : mongodb-database-tools-100.6.0-1.x86_64                                                                                                                         5/9
  Running scriptlet: mongodb-database-tools-100.6.0-1.x86_64                                                                                                                         5/9
  Upgrading        : mongodb-org-tools-6.0.1-1.el8.x86_64                                                                                                                            6/9
  Upgrading        : mongodb-org-6.0.1-1.el8.x86_64                                                                                                                                  7/9
  Cleanup          : mongodb-org-4.0.28-1.el8.x86_64                                                                                                                                 8/9
  Cleanup          : mongodb-org-tools-4.0.28-1.el8.x86_64                                                                                                                           9/9
  Running scriptlet: mongodb-org-tools-4.0.28-1.el8.x86_64                                                                                                                           9/9
  Verifying        : cyrus-sasl-2.1.27-6.el8_5.x86_64                                                                                                                                1/9
  Verifying        : mongodb-database-tools-100.6.0-1.x86_64                                                                                                                         2/9
  Verifying        : mongodb-mongosh-1.5.4-1.el8.x86_64                                                                                                                              3/9
  Verifying        : mongodb-org-database-6.0.1-1.el8.x86_64                                                                                                                         4/9
  Verifying        : mongodb-org-database-tools-extra-6.0.1-1.el8.x86_64                                                                                                             5/9
  Verifying        : mongodb-org-6.0.1-1.el8.x86_64                                                                                                                                  6/9
  Verifying        : mongodb-org-4.0.28-1.el8.x86_64                                                                                                                                 7/9
  Verifying        : mongodb-org-tools-6.0.1-1.el8.x86_64                                                                                                                            8/9
  Verifying        : mongodb-org-tools-4.0.28-1.el8.x86_64                                                                                                                           9/9

Upgraded:
  mongodb-org-6.0.1-1.el8.x86_64                                                           mongodb-org-tools-6.0.1-1.el8.x86_64
Installed:
  cyrus-sasl-2.1.27-6.el8_5.x86_64                        mongodb-database-tools-100.6.0-1.x86_64     mongodb-mongosh-1.5.4-1.el8.x86_64     mongodb-org-database-6.0.1-1.el8.x86_64
  mongodb-org-database-tools-extra-6.0.1-1.el8.x86_64

Complete!
Job for mongod.service failed because the control process exited with error code.
See "systemctl status mongod.service" and "journalctl -xe" for details.
Status mongodb
● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Mon 2022-09-05 06:36:08 UTC; 75ms ago
     Docs: https://docs.mongodb.org/manual
  Process: 33739 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=1/FAILURE)
  Process: 33736 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 33735 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 33733 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)

Sep 05 06:36:08 DKERP systemd[1]: Starting MongoDB Database Server...
Sep 05 06:36:08 DKERP mongod[33739]: about to fork child process, waiting until server is ready for connections.
Sep 05 06:36:08 DKERP mongod[33740]: forked process: 33741
Sep 05 06:36:08 DKERP mongod[33739]: ERROR: child process failed, exited with error number 1
Sep 05 06:36:08 DKERP mongod[33739]: To see additional information in this output, start without the "--fork" option.
Sep 05 06:36:08 DKERP systemd[1]: mongod.service: Control process exited, code=exited status=1
Sep 05 06:36:08 DKERP systemd[1]: mongod.service: Failed with result 'exit-code'.
Sep 05 06:36:08 DKERP systemd[1]: Failed to start MongoDB Database Server.

一个建议是在尝试此命令后开始,sudo systemctl daemon-reload但这对我来说也不起作用。

不幸的是,日志中没有显示任何内容,如以下输出所示:

[root@vultr ~]# grep log /etc/mongod.conf
# where to write logging data.
  logAppend: true
  path: /var/www/logs/mongodb/mongod.log
[root@vultr ~]# cat /var/www/logs/mongodb/mongod.log | wc -l
cat: /var/www/logs/mongodb/mongod.log: No such file or directory
0

我在centos8上做mongo 6

[root@vultr ~]# uname -a
Linux DKERP 4.18.0-408.el8.x86_64 #1 SMP Mon Jul 18 17:42:52 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
[root@vultr ~]# hostnamectl
   Static hostname: DKERP
         Icon name: computer-vm
           Chassis: vm
        Machine ID: c07ca36f4c37437f8c6c6cbb7d73daf1
           Boot ID: 83ee4a5872024054be50448423a9f5e7
    Virtualization: microsoft
  Operating System: CentOS Stream 8
       CPE OS Name: cpe:/o:centos:centos:8
            Kernel: Linux 4.18.0-408.el8.x86_64
      Architecture: x86-64

从配置文件中删除了该fork选项,这是详细调试信息:

[root@vultr ~]# journalctl -xe
Sep 05 10:20:26 DKERP systemd[1]: Starting MongoDB Database Server...
-- Subject: Unit mongod.service has begun start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit mongod.service has begun starting up.
Sep 05 10:20:26 DKERP mongod[34825]: 2022-09-05T10:20:26.596+0000 F CONTROL  [main] Failed global initialization: FileNotOpen: Failed to open "/var/www/logs/mongodb/mongod.log"
Sep 05 10:20:26 DKERP systemd[1]: mongod.service: Control process exited, code=exited status=1
Sep 05 10:20:26 DKERP dbus-daemon[775]: [system] Activating via systemd: service name='org.fedoraproject.Setroubleshootd' unit='setroubleshootd.service' requested by ':1.239' (uid=0 pi>
Sep 05 10:20:26 DKERP systemd[1]: mongod.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- The unit mongod.service has entered the 'failed' state with result 'exit-code'.
Sep 05 10:20:26 DKERP systemd[1]: Failed to start MongoDB Database Server.
-- Subject: Unit mongod.service has failed
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit mongod.service has failed.
--
-- The result is failed.
Sep 05 10:20:26 DKERP systemd[1]: Starting SETroubleshoot daemon for processing new SELinux denial logs...
-- Subject: Unit setroubleshootd.service has begun start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit setroubleshootd.service has begun starting up.
Sep 05 10:20:26 DKERP sudo[34814]: pam_unix(sudo:session): session closed for user root
Sep 05 10:20:27 DKERP dbus-daemon[775]: [system] Successfully activated service 'org.fedoraproject.Setroubleshootd'
Sep 05 10:20:27 DKERP systemd[1]: Started SETroubleshoot daemon for processing new SELinux denial logs.
-- Subject: Unit setroubleshootd.service has finished start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit setroubleshootd.service has finished starting up.
--
-- The start-up result is done.
Sep 05 10:20:28 DKERP setroubleshoot[34827]: AnalyzeThread.run(): Cancel pending alarm
Sep 05 10:20:28 DKERP dbus-daemon[775]: [system] Activating service name='org.fedoraproject.SetroubleshootPrivileged' requested by ':1.917' (uid=995 pid=34827 comm="/usr/libexec/platfo>
Sep 05 10:20:28 DKERP dbus-daemon[775]: [system] Successfully activated service 'org.fedoraproject.SetroubleshootPrivileged'
Sep 05 10:20:29 DKERP setroubleshoot[34827]: SELinux is preventing /usr/bin/mongod from read access on the file memory.limit_in_bytes. For complete SELinux messages run: sealert -l 8a0>
Sep 05 10:20:29 DKERP setroubleshoot[34827]: SELinux is preventing /usr/bin/mongod from read access on the file memory.limit_in_bytes.

                                             *****  Plugin catchall (100. confidence) suggests   **************************

                                             If you believe that mongod should be allowed read access on the memory.limit_in_bytes 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

Sep 05 10:20:29 DKERP setroubleshoot[34827]: AnalyzeThread.run(): Set alarm timeout to 10

然后我决定暂时禁用selinux,但是我仍然收到以下错误:

[root@vultr ~]# journalctl -xe
Sep 05 10:26:43 DKERP systemd[1]: Started SETroubleshoot daemon for processing new SELinux denial logs.
-- Subject: Unit setroubleshootd.service has finished start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit setroubleshootd.service has finished starting up.
--
-- The start-up result is done.
Sep 05 10:26:43 DKERP setroubleshoot[34922]: AnalyzeThread.run(): Cancel pending alarm
Sep 05 10:26:43 DKERP dbus-daemon[775]: [system] Activating service name='org.fedoraproject.SetroubleshootPrivileged' requested by ':1.949' (uid=995 pid=34922 comm="/usr/libexec/platfo>
Sep 05 10:26:44 DKERP dbus-daemon[775]: [system] Successfully activated service 'org.fedoraproject.SetroubleshootPrivileged'
Sep 05 10:26:44 DKERP setroubleshoot[34922]: SELinux is preventing /usr/bin/mongod from read access on the file memory.limit_in_bytes. For complete SELinux messages run: sealert -l 8a0>
Sep 05 10:26:44 DKERP setroubleshoot[34922]: SELinux is preventing /usr/bin/mongod from read access on the file memory.limit_in_bytes.

                                             *****  Plugin catchall (100. confidence) suggests   **************************

                                             If you believe that mongod should be allowed read access on the memory.limit_in_bytes 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

Sep 05 10:26:44 DKERP setroubleshoot[34922]: AnalyzeThread.run(): Set alarm timeout to 10
Sep 05 10:26:44 DKERP setroubleshoot[34922]: AnalyzeThread.run(): Cancel pending alarm
Sep 05 10:26:44 DKERP setroubleshoot[34922]: SELinux is preventing /usr/bin/mongod from read access on the file memory.limit_in_bytes. For complete SELinux messages run: sealert -l 8a0>
Sep 05 10:26:44 DKERP setroubleshoot[34922]: SELinux is preventing /usr/bin/mongod from read access on the file memory.limit_in_bytes.

                                             *****  Plugin catchall (100. confidence) suggests   **************************

                                             If you believe that mongod should be allowed read access on the memory.limit_in_bytes 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

Sep 05 10:26:44 DKERP setroubleshoot[34922]: AnalyzeThread.run(): Set alarm timeout to 10
Sep 05 10:26:44 DKERP setroubleshoot[34922]: AnalyzeThread.run(): Cancel pending alarm
Sep 05 10:26:44 DKERP setroubleshoot[34922]: failed to retrieve rpm info for /sys/fs/cgroup/memory/memory.limit_in_bytes
Sep 05 10:26:44 DKERP setroubleshoot[34922]: SELinux is preventing /usr/bin/mongod from getattr access on the file /sys/fs/cgroup/memory/memory.limit_in_bytes. For complete SELinux mes>
Sep 05 10:26:44 DKERP setroubleshoot[34922]: SELinux is preventing /usr/bin/mongod from getattr access on the file /sys/fs/cgroup/memory/memory.limit_in_bytes.

                                             *****  Plugin catchall (100. confidence) suggests   **************************

                                             If you believe that mongod should be allowed getattr access on the memory.limit_in_bytes 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

Sep 05 10:26:44 DKERP setroubleshoot[34922]: AnalyzeThread.run(): Set alarm timeout to 10

你能建议我如何让 mongod 运行吗?

相关内容