MongoDb 不启动 Amazon Linux



当我写这个命令时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无法在Ubuntu 15.04中启动但这对我不起作用,这个问题在5年前就提出了当我写这个命令时sudo service mongod status

give me to

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:

根据您的配置文件启用简单的身份验证/授权,您需要做以下操作:

  1. 未经授权启动(您说它正在未经授权工作)仅绑定到127.0.0.1,并创建admin用户,如果尚未初始化则初始化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. 将keyfile修改为mongod用户只读权限:

    chmod 400 /work/dbtest
    
  5. 取消授权配置的注释并添加密钥文件,使其看起来如下:

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

  7. 现在可以按如下方式访问:

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

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

当我写这个命令时,我仍然得到相同的错误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.```

最新更新