开启授权后,MongoDB无法在Ubuntu 16.04中启动

时间:2018-10-03 11:40:23

标签: mongodb

我试图向mongodb添加密码,但是在将authorization更改为enabled之后,但是尝试sudo service mongod start之后mongodb无法启动。我遵循this tutorial进行了同样的操作。我什至关闭了防火墙。 sudo service mongod status的结果如下:

● mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)    
Active: failed (Result: exit-code) since Wed 2018-10-03 16:56:31 IST; 1s ago
Docs: https://docs.mongodb.org/manual
Process: 17641 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=2)  Main PID: 17641 (code=exited, status=2)

Oct 03 16:56:31 dev-76 systemd[1]: Started High-performance, schema-free document-oriented database. 
Oct 03 16:56:31 dev-76 systemd[1]: mongod.service: Main process exited, code=exited, status=2/INVALIDARGUMENT 
Oct 03 16:56:31 dev-76 systemd[1]: mongod.service: Unit entered failed state. 
Oct 03 16:56:31 dev-76 systemd[1]: mongod.service: Failed with result 'exit-code'.

如果我尝试登录,那么我得到以下信息:

sam@dev-76:/etc$ mongo -u admin -p mongoadmin admin
MongoDB shell version v3.6.8
connecting to: mongodb://127.0.0.1:27017/admin
2018-10-03T17:06:09.418+0530 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-10-03T17:06:09.418+0530 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:251:13
@(connect):1:6
exception: connect failed

更新

我的mongod.conf如下:

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1


# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

#security:
  authorization: enabled

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:

1 个答案:

答案 0 :(得分:0)

我忘了取消注释

#security:
  authorization: enabled

取消注释该行后,

security:
  authorization: enabled

也为了在我的应用程序中使用mongodb来实现持久性,我如下更改了我的uri,

mongodb://username:password@localhost:27017/mycollection?authSource=admin&authMechanism=SCRAM-SHA-1