Mongodb /var/log/mongodb/mongod.log阻止mongod启动

时间:2018-03-16 15:31:10

标签: database mongodb amazon-web-services amazon-ec2 centos7

我在centos 7 aws ec2实例上使用mongodb 3.6.3。

2个问题(只需要回答一个问题):

  1. 如果使用sudo mongod --storageEngine etc
  2. 通过cli手动完成,为什么--logpath会阻止mongod命令
  3. 为什么sudo service mongod status显示失败?
  4. 当我运行以下命令时,(因为目前,sudo service mongod start不起作用,但下面的工作正常),当我指定--logpath但它将在没有它的情况下运行时它会失败。不幸的是,当我在没有它的情况下运行它时,我的所有日​​志最终都在/,这绝对是错误的位置。

    sudo mongod --storageEngine wiredTiger --dbpath /data --bind_ip 127.0.0.1,apiIP --logpath /var/log/mongodb/mongod.log --auth --fork

    下面是当我尝试按原样运行上面的行时发生的情况。

    I CONTROL [main] log file "/var/log/mongodb/mongod.log" exists; moved to "/var/log/mongodb/mongod.log.2018-03-16T15-16-01".

    据我所知,它与目前存在的

    相矛盾

    仅供参考,sudo service mongod status返回:

    mongod.service - mongodb database
       Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
       Active: failed (Result: exit-code) since Fri 2018-03-16 15:11:53 UTC; 9min ago
      Process: 26620 ExecStart=/usr/bin/mongod $OPTIONS run (code=exited, status=2)
     Main PID: 26620 (code=exited, status=2)
    
    Mar 16 15:11:53 ip-* systemd[1]: Started mongodb database.
    Mar 16 15:11:53 ip-* systemd[1]: Starting mongodb database...
    Mar 16 15:11:53 ip-* mongod[26620]: F CONTROL  [main] Failed global initialization: FileNotOpen: Failed to open "/var/log/mongodb/mongod.log"
    Mar 16 15:11:53 ip-* systemd[1]: mongod.service: main process exited, code=exited, status=1/FAILURE
    Mar 16 15:11:53 ip-* systemd[1]: Unit mongod.service entered failed state.
    Mar 16 15:11:53 ip-* systemd[1]: mongod.service failed.
    

    /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: /data
    #  logpath: /log/mongod.log
      journal:
        enabled: true
       engine: wiredTiger
    #  mmapv1:
    #  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, apiIP
    

    感谢@AlexBlex注意yaml文件中的间距问题。

    如果已排序,则状态错误具有此行 Unrecognized option: storage.wiredTiger

2 个答案:

答案 0 :(得分:0)

  1. cd /var/log
  2. sudo mkdir -m 777 mongodb
  3. sudo service mongod start
  4. sudo service mongod status

希望如此!

答案 1 :(得分:0)

sudo systemctl enable mongod
sudo systemctl restart mongod
sudo journalctl -u mongod.service

希望如此!

参考:https://stackoverflow.com/a/51286526/122441