问题描述
任何人都可以使用rmongodb
连接到MongoDB副本集吗?不管我如何配置mongo.create
,即使通过mongo
shell连接时,相同的主机/用户名/密码也可以正常工作,但仍会收到身份验证错误.
Has anyone been able to connect to a MongoDB replica set using rmongodb
? No matter how I configure mongo.create
I get an authentication error, even though the same host/username/password work fine when connecting via the mongo
shell.
我的代码等效于:
> mongo.create(c("rs-1.mysite.com:12345","rs-2.mysite.com:12345"), "rsName", "user", "password", "my_db")
Unable to connect to replset
Authentication failed.
更新:
查看副本集中所有节点的日志,当我运行上述代码时,我没有看到任何尝试进行身份验证的尝试.因此,这可能是rmongodb
错误.
Looking at the logs of all the nodes in the replica set, I do not see any attempt to authenticate when I run the code above. Therefore, this may be a rmongodb
bug.
推荐答案
正如Sim所指出的, rmongodb 1.0.3无法解析主机名.
As Sim has noted, rmongodb 1.0.3 does not resolve hostnames.
但是,可以通过一些警告从rmongodb连接到副本集:
It is, however, possible to connect to replica sets from rmongodb with with a few caveats:
- 您必须包括所有主机名(如果在种子主机列表中未找到主要主机名,则rmongodb将无法连接)
- 主机名必须作为IP提供
- 如果使用管理员用户,则必须首先对管理员数据库进行身份验证(至少为预期行为,但值得注意)
- 我只能通过不能提供一个replSet名称来使连接正常工作
- you must include all hostnames (if the primary isn't found in the seed host list, rmongodb will fail to connect)
- hostnames must be provided as IPs
- if using an admin user, you must first auth to the admin database (this, at least, is expected behaviour but worth noting)
- I could only get the connection to work by not providing a replSet name
所以我的工作连接字符串如下:
So my working connect string looks like:
mongo.create(c("192.168.1.123:27017","192.168.1.124:27018","192.168.1.125:27017"),"","user","password", "thedb")
注意:我只在MongoDB 2.2.0上进行过测试.
NB: I only tested this with MongoDB 2.2.0.
这篇关于使用rmongodb连接到MongoDB副本集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!