mongodb.conf
我有 4 个 mongodb 实例正在运行(副本集),每个实例都有以下文件:
# 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: /root/mongodata/log/mongod.log
# Where and how to store data.
storage:
dbPath: /root/mongodata/db1 # also have db2 and so on for rest of the instances
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /root/mongodata/db1/mongod.pid # location of pidfile, different for 4 instances
# network interfaces
net:
port: 30000 #port different for 4 different instances
bindIp: 12.123.321.432(example ip, same for all 4 .conf files)
# security
security:
KeyFile: /path to my keyfile location
# authorization: enabled
#operationProfiling:
replication:
replSetName: testReplica #have this same for all 4
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
我还为内部身份验证创建了一个密钥文件,如下所示:
openssl rand -base64 756 > <path-to-keyfile>
chmod 400 <path-to-keyfile>
在所有实例运行后,我打开了 mongoShell,如下所示:
mongo --host 12.123.321.432 --port 30000
我可以打开 shell,但是当我尝试创建用户时,出现以下异常:
2016-12-22T20:55:38.396-0500 E QUERY [thread1] Error: couldn't add user: not authorized on test to execute command { createUser: "root", pwd: "xxx", roles: [ { role: "root", db: "admin" } ], digestPassword: false, writeConcern: { w: "majority", wtimeout: 30000.0 } } :
_getErrorWithCode@src/mongo/shell/utils.js:23:13
DB.prototype.createUser@src/mongo/shell/db.js:1230:11
@(shell):1:1
我尝试切换到管理数据库,但仍然说未经授权,我还尝试运行 rs.initiate() 命令来定义主数据库和辅助数据库,说未经授权。即使我开始mongod
使用身份验证禁用内部身份验证,我也会阅读keyfile
将强制基于角色的身份验证。我在这里缺少什么,我将如何解决它?提前致谢。