具有简单密码身份验证的MongoDB副本集 [英] MongoDB replica set with simple password authentication

查看:236
本文介绍了具有简单密码身份验证的MongoDB副本集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个服务器的MongoDB副本集(1个主服务器,1个辅助服务器,1个仲裁器;这是Google Cloud一键安装创建的默认副本集).主服务器和辅助服务器的2个配置文件(mongod.conf)已更改,并添加了"security.authorization:enabled".

I have a MongoDB replica set of 3 servers (1 primary, 1 secondary, 1 arbiter; this is the default replica set created by Google Cloud 1-click install). The 2 config files (mongod.conf) of primary server and secondary server have been changed with "security.authorization: enabled" added.

使用以下MongoDB shell命令添加root用户:

Root user is added with the following MongoDB shell command:

use admin
db.createUser({user:"root",pwd:"root",roles:["root"]})

在通过"sudo service mongod restart"重新启动主服务器和辅助服务器上的MongoDB服务之后,与副本集的连接变得不稳定.

After restarting MongoDB services on the primary and secondary servers with "sudo service mongod restart", connection to the replica set turns unstable.

rs.status()有时将结果表示为

rs.status() sometimes give the result as

  • 1个主要,1个无法访问,1个仲裁器
  • 1个次要,1个次要,1个仲裁器
  • 1个中学,1个无法访问,1个仲裁器

如何为MongoDB复制副本设置基本密码身份验证(不使用密钥文件)?

推荐答案

我终于找到了答案. MongoDB副本集需要用户帐户和密钥文件.密钥文件似乎是用于副本集中服务器之间的身份验证,而不是用于登录.

I finally found the answer. MongoDB replica set needs both user account and keyfile. Keyfile seems for authentication between servers in the replica set, not for logging in.

在linux上创建mongodb密钥文件,并以完整模式600复制到所有数据库服务器:

Create mongodb key file on linux, copy to all db servers with mode 600 intact:

cd
openssl rand -base64 741 > mongodb.key
chmod 600 mongodb.key

mongod.conf文件:

mongod.conf file:

replication:
  replSetName: rs0

security:
  authorization: enabled
  keyFile: /home/USERNAME/mongodb.key

管理员用户:

(just like in question content)

这篇关于具有简单密码身份验证的MongoDB副本集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆