【问题标题】:Service mongod does not start on Centos8服务 mongod 没有在 Centos8 上启动
【发布时间】:2020-11-22 01:01:24
【问题描述】:

我试图在 Centos8 上安装 mongoDB,但是当我运行命令时

systemctl status mongod.service

我收到此错误:

● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sat 2020-08-01 14:26:53 CEST; 11min ago
     Docs: https://docs.mongodb.org/manual
  Process: 1875 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
  Process: 1873 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 1871 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 1869 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)

Aug 01 14:26:53 db.localhost systemd[1]: Starting MongoDB Database Server...
Aug 01 14:26:53 db.localhost mongod[1875]: about to fork child process, waiting until server is ready for>
Aug 01 14:26:53 db.localhost mongod[1875]: forked process: 1877
Aug 01 14:26:53 db.localhost mongod[1875]: ERROR: child process failed, exited with 14
Aug 01 14:26:53 db.localhost mongod[1875]: To see additional information in this output, start without th>
Aug 01 14:26:53 db.localhost systemd[1]: mongod.service: Control process exited, code=exited status=14
Aug 01 14:26:53 db.localhost systemd[1]: mongod.service: Failed with result 'exit-code'.
Aug 01 14:26:53 db.localhost systemd[1]: Failed to start MongoDB Database Server.

我尝试检查以下文件夹的权限:/var/lib/mongo 和 /var/log/mongodb

#/var/lib/
drwxr-xr-x.  4 mongod  mongod  4096 Aug  1 14:44 mongo
#/var/log/
drwxr-xr-x.  2 mongod  mongod    50 Aug  1 14:14 mongodb

在其他一些帖子中,人们告诉尝试这个命令:

sudo chown -R mongodb:mongodb /var/lib/mongodb/

但在没有用户 mongodb 时出现错误:无效用户:'mongodb:mongodb'!

在我的 /etc/passwd 文件中,mongo 的唯一用户是:

mongod:x:994:992:mongod:/var/lib/mongo:/bin/false

有什么问题? 为什么我无法运行 mongod.service?

感谢您的支持。


添加了更多信息: systemctl cat mongod

[root@db tmp]# systemctl cat mongod
# /usr/lib/systemd/system/mongod.service
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network.target

[Service]
User=mongod
Group=mongod
Environment="OPTIONS=-f /etc/mongod.conf"
EnvironmentFile=-/etc/sysconfig/mongod
ExecStart=/usr/bin/mongod $OPTIONS
ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb
ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb
ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb
PermissionsStartOnly=true
PIDFile=/var/run/mongodb/mongod.pid
Type=forking
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for mongod as specified in
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings

[Install]
WantedBy=multi-user.target

mongod.conf

[root@db tmp]# cat /etc/mongod.conf
# ..
# 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.


#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:

/usr/bin/mongod -f /etc/mongod.conf

[root@db mongodb]# /usr/bin/mongod -f /etc/mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 1959
child process started successfully, parent exiting

【问题讨论】:

  • 检查/tmp/mongodb-27017.sock 是否归root 所有。也请发帖systemctl cat mongod
  • 嗨@Valijon,感谢您的快速回答。是的 mongodb-27017.sock 归 root 所有。我在帖子末尾添加了有关 systemctl 的信息。
  • mongod.service 配置看起来不错。只需删除/tmp/mongodb-27017.sock,它应该会修复它(再次运行systemctl start mongod)。可能,当你第一次运行它时,mongodb 二进制文件是 root 所有者,现在这些是 mongod 所有者
  • 我删除了mongodb-27017.sock 并重新启动了机器。现在归 mongod 用户所有。但是服务再次失败并出现同样的错误。
  • 我明白了。然后/etc/mongod.conf请发帖

标签: mongodb service centos8


【解决方案1】:

出于某种原因,mongod想要文件夹 /data/db 并忽略文件 mongod.conf

创建这些文件夹后,如果我运行 mongod 命令(使用 sudo),程序会“正确”启动。 但是如果我重新启动系统,服务会在启动时失败并继续出现问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-07
    • 2017-03-25
    • 1970-01-01
    • 1970-01-01
    • 2019-03-08
    • 1970-01-01
    • 2011-08-01
    相关资源
    最近更新 更多