mongodb - Mongo auth fails to login when using mongod.conf
问题描述
So this is the weirdest thing.
I have two centOS 7 servers running mongo. I now wanted to enforce authentication so I added the security.authorization: enabled to the mongod.conf file.
I already have a user on database "buzzztv".
So when I ran mongod --conf /etc/mongod.conf
on the first server everything went fine.
Then I did the exact same thing on the second server and whenever I try to connect with one of the users I get the following error:
connecting to: mongodb://127.0.0.1:27017/?authSource=buzzztv&compressors=disabled&gssapiServiceName=mongodb
2020-02-20T13:02:35.166+0000 E QUERY [js] Error: Authentication failed. :
connect@src/mongo/shell/mongo.js:341:17
@(connect):2:6
2020-02-20T13:02:35.168+0000 F - [main] exception: connect failed
2020-02-20T13:02:35.168+0000 E - [main] exiting with code 1
Now if I run mongod --fork --logpath /var/log/mongodb/mongod.log --auth
the login works perfectly fine.
So obiously I could just run this command, but I want to use the mongod.conf.
Here is my mongod.conf file, I checked and it is a perfect copy of the file from the server in which it does work.
Any ideas?
# 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: 0.0.0.0 # 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:
authorization: enabled
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
解决方案
所以经过几个小时的研究,我需要改变
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
显然我的有问题,/var/lib/mongo
所以我备份了数据,并创建了一个新文件夹/var/lib/mongodb
然后将 mongod.conf 文件编辑为:
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
然后一切正常。现在我将重新创建用户并重新插入所有数据,一切顺利。
希望这可以节省我浪费的时间
推荐阅读
- django - 如何让 REMOTE_USER 在 Pycharm 和 Firefox 中使用 Django 进行 Windows 身份验证?
- python - 有没有办法在 asyncio 构建的预分叉多进程 TCP 服务器上进行负载平衡?
- c++ - c++中字符和整数数组的不同行为
- scala - Lagom:是否可以跨多个集群拆分服务实例?
- javascript - 一个输入字段上的多个 javascript 函数
- python - 如何在 Python 上使用正则表达式从字符串中删除除日期和时间之外的所有数字?
- python-3.x - 导入tensorflow时没有名为“tensorflow.python.platform”的模块|| python shell 上的 tflearn
- gem5 - 在 gem5 上运行 ARM-fullsystem
- c# - 错误 ORA-00907:调用 command.ExecuteReader() 时缺少右括号
- vb.net - 如何将流转换为图像?