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

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

问题描述

我有一个 MongoDB 副本集,其中包含 3 个服务器(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 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完整的db服务器:

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天全站免登陆