简体   繁体   English

mongodb副本集身份验证不起作用

[英]mongodb replicaset auth not working

I have a problem with replica sets 我的副本集有问题

After I add keyFile path to mongodb.conf I can connect, this is my mongo.conf: 将keyFile路径添加到mongodb.conf之后,我可以连接了,这是我的mongo.conf:

logpath=/path/to/log

logappend=true

replSet = rsname

fork = true

keyFile = /path/to/key

And this is what is showed in the command line: 这就是命令行中显示的内容:

XXXX@XXXX:/etc$ sudo service mongodb restart
stop: Unknown instance:
mongodb start/running, process 10540
XXXX@XXXX:/etc$ mongo
MongoDB shell version: 2.4.6
connecting to: test
Mon Sep 30 18:44:20.984 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed
XXXX@XXXX:/etc$

if I comment the keyFile line in mongo.conf it works fine. 如果我在mongo.conf中评论keyFile行,则可以正常工作。

I solve the problem. 我解决了问题。

It was related with the key file permissions, I fixed the permissionas and ownership and work like charm: 这与密钥文件的权限有关,我修复了Permissionas和所有权,并像charm一样工作:

As a root user I did: 作为root用户,我这样做:

$ chmod 700 keyfile
$ chown monogdb:mongodb keyfile

If the authentication would be the problem you should get a different message (and should be able to start the shell without the authenticated session just prevent you to run most of the commands). 如果验证是问题所在,您应该收到另一条消息(并且应该能够在不通过验证会话的情况下启动外壳程序,只是阻止您运行大多数命令)。

This one means more like a socket exception that where you likely to connect there is no service listening. 这更像是套接字异常,即您可能连接的地方没有服务监听。 You can check with netstat if the process is listening that ip:port which is in the message. 您可以使用netstat来检查进程是否正在监听消息中的ip:port。 I assume that the mongod process have not started which can be for several reasons check the logs for the current one. 我认为mongod进程尚未启动,可能由于多种原因,请检查当前日志。 One thing can be that the keyfile is not exists at the specified path or not the appropriate privileges have set on. 一件事可能是密钥文件在指定路径上不存在,或者没有设置适当的特权。

Adding a keyfile automaticly turns on the auth option too. 添加密钥文件也会自动打开auth选项。 This means you have to use a user to authenticate, but you can bypass this authentication with a localhost exception: . 这意味着您必须使用用户进行身份验证,但是可以使用localhost异常绕过此身份验证:。 Read the documentation . 阅读文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM