【问题标题】:MongoDb doesn't start Amazon LinuxMongoDb 不启动 Amazon Linux
【发布时间】:2021-10-01 11:30:43
【问题描述】:

当我写这个命令时 sudo service mongod start

这给了我这个错误 Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details. 我在stackoverflow上搜索并找到它Mongodb not able to start in Ubuntu 15.04 但这对我不起作用,这个问题在 5 年前问过 当我写这个命令时 sudo service mongod status

给我

Redirecting to /bin/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 2021-07-24 22:49:47 UTC; 3min 49s ago
     Docs: https://docs.mongodb.org/manual
  Process: 4126 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=2)
  Process: 4123 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 4120 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 4119 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)

Jul 24 22:49:47 ip-172-31-46-146.eu-central-1.compute.internal systemd[1]: Starting MongoDB Database Server...
Jul 24 22:49:47 ip-172-31-46-146.eu-central-1.compute.internal mongod[4126]: Error parsing YAML config: duplicate key: replication.rep...Name
Jul 24 22:49:47 ip-172-31-46-146.eu-central-1.compute.internal mongod[4126]: try '/usr/bin/mongod --help' for more information
Jul 24 22:49:47 ip-172-31-46-146.eu-central-1.compute.internal systemd[1]: mongod.service: control process exited, code=exited status=2
Jul 24 22:49:47 ip-172-31-46-146.eu-central-1.compute.internal systemd[1]: Failed to start MongoDB Database Server.
Jul 24 22:49:47 ip-172-31-46-146.eu-central-1.compute.internal systemd[1]: Unit mongod.service entered failed state.
Jul 24 22:49:47 ip-172-31-46-146.eu-central-1.compute.internal systemd[1]: mongod.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

还有这个命令 sudo systemctl disable mongod

给我 Removed symlink /etc/systemd/system/multi-user.target.wants/mongod.service.

而我在启用时会发生这种情况 sudo systemctl enable mongod

Created symlink from /etc/systemd/system/multi-user.target.wants/mongod.service to /usr/lib/systemd/system/mongod.service.

这是我的 mongod.conf 文件

  GNU nano 2.9.8                                                 /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: 34418
  bindIp: 127.0.0.1,172.31.46.146  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll settin$

#security:
   #authorization: "enabled"

#operationProfiling:

replication:
  replSetName: "rs0"

#sharding:

## Enterprise-Only Options

#auditLog:

【问题讨论】:

  • 你的 /etc/mongod.conf 是什么样子的?
  • 我只分享绿色内容 systemLog: 目的地: 文件 logAppend: true path: /var/log/mongodb/mongod.log storage: dbPath: /var/lib/mongo journal: enabled: true processManagement: fork: true # fork 并在后台运行 pidFilePath: /var/run/mongodb/mongod.pid # pidfile 的位置 timeZoneInfo: /usr/share/zoneinfo net: port: 34418 bindIp: 127.0.0.1,172.31.46.146 # Enter 0.0 .0.0,:: 绑定到所有 IPv4 和 IPv6 地址,或者,使用 net.bindIpAll settin$ security: authorization: "enabled" @R2D2
  • 你需要在 yaml 中了解它的来源:重复键:复制
  • 当我禁用授权时问题已解决,但我必须使用授权@R2D2
  • 添加完整的 conf 内容,以便我们检查问题出在哪里,但它肯定在 yaml 中

标签: linux mongodb amazon-web-services amazon-ec2


【解决方案1】:

根据您的 conf 文件来启用简单的身份验证/授权,您需要执行以下操作:

  1. 未经授权启动(您说它未经授权即可工作)仅绑定到 127.0.0.1 并创建管理员用户并初始化 repicaSet(如果尚未初始化):

     mongo --port 34418
    
     db.createUser({user:"admin" ,pwd:"someStrongOne" ,roles:[{role:"root",db:"admin" }]})
    
     rs.initiate()
    
  2. 停止mongod服务

  3. 生成密钥文件:

     mkdir /work/dbtest/key
     openssl rand -base64 756 > /work/dbtest/key
    
  4. 更改密钥文件的权限为 mongod 用户只读:

     chmod 400 /work/dbtest
    
  5. 取消注释授权配置并添加密钥文件,如下所示:

    security:
     authorization: "enabled"
     keyFile: /work/dbtest/key
    
  6. 启动mongod进程

  7. 现在您可以访问如下:

    mongo --port 34418 admin -u admin -p someStrongOne
    

顺便说一句,在粘贴的 conf 文件中,需要在“dbPath”和“port”之前添加一些新行,因此它是有效的 yaml 文件......请注意建议的安全配置,它是用于测试目的只是,如果您通过网络公开此服务,强烈建议您添加传输加密(X.509 等,这在官方 mongodb 文档中有很好的解释)

【讨论】:

  • 我仍然得到同样的错误。在第 6 步Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.
  • 您可以从控制台运行并检查mongod进程,如下所示:mongod --config xxx.conf
【解决方案2】:

当我写这个命令时,我仍然得到同样的错误 sudo systemctl status mongod 我明白了

● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sun 2021-08-01 16:24:16 UTC; 3min 52s ago
     Docs: https://docs.mongodb.org/manual
  Process: 32109 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=1/FAILURE)
  Process: 32106 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 32103 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 32101 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
 Main PID: 13177 (code=exited, status=0/SUCCESS)

Aug 01 16:24:16 ip-172-31-18-25.eu-central-1.compute.internal systemd[1]: Starting MongoDB Database Server...
Aug 01 16:24:16 ip-172-31-18-25.eu-central-1.compute.internal mongod[32109]: about to fork child process, waiting until server is ready for connections.
Aug 01 16:24:16 ip-172-31-18-25.eu-central-1.compute.internal mongod[32109]: forked process: 32112
Aug 01 16:24:16 ip-172-31-18-25.eu-central-1.compute.internal systemd[1]: mongod.service: control process exited, code=exited status=1
Aug 01 16:24:16 ip-172-31-18-25.eu-central-1.compute.internal systemd[1]: Failed to start MongoDB Database Server.
Aug 01 16:24:16 ip-172-31-18-25.eu-central-1.compute.internal systemd[1]: Unit mongod.service entered failed state.
Aug 01 16:24:16 ip-172-31-18-25.eu-central-1.compute.internal systemd[1]: mongod.service failed.```

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-08
    • 2014-01-19
    • 1970-01-01
    • 2022-06-18
    • 2015-08-03
    • 2012-01-13
    • 2018-05-17
    • 2018-10-07
    相关资源
    最近更新 更多