不加权限验证的时候,是可以连接上的。 启动时加上了 --auth
./mongod --dbpath /home/db --port 27017 --logpath /home/log/mongodb/mongdb.log --logappend --fork --auth
加了权限验证本地可以验证。
MongoDB shell version: 2.0.4-rc1
connecting to: test
> use node_club
switched to db node_club
> show collections
Thu Mar 15 06:20:27 uncaught exception: error: {
"$err" : "unauthorized db:node_club lock type:-1 client:127.0.0.1",
"code" : 10057
}
> db.auth("nodeclub","XXXXXXXXX")
1
> show collections
messages
replies
system.indexes
system.users
tagcollects
users
> quit()
但是这样连接不上: mongodb://nodeclub:XXXX@127.0.0.1:27017/node_club
日志显示是这样的
Thu Mar 15 06:30:53 [conn11] authenticate: { authenticate: 1, user: "nodeclub", nonce: "c9931b4d9c9162c9", key: "7545a53090daa76c96a032aa9eb6fc5e" }
Thu Mar 15 06:30:55 [conn11] end connection 222.128.130.173:63499
Thu Mar 15 06:30:56 [initandlisten] connection accepted from 222.128.130.173:64287 #12
Thu Mar 15 06:30:56 [conn12] authenticate: { authenticate: 1, user: "nodeclub", nonce: "551b9ac7ab0cab16", key: "88bab8ea983dc26a1e29e40502d09b09" }
Thu Mar 15 06:30:56 [conn12] end connection 222.128.130.173:64287
Thu Mar 15 06:34:23 [clientcursormon] mem (MB) res:43 virt:153 mapped:64
大家看看是什么原因。
8 回复
db nodeclub 加用户 nodeclub 了么?
和mysql的用户校验不太一样,mongo的权限在每个db中配置用户权限
admin库中的用户具有管理员权限,在admin验证通过之后,可以管理别的db,给别的db添加用户账号
嗯,就是在node_club这个里面加的。 shell命令是通的。 MongoDB shell version: 2.0.4-rc1 connecting to: test > use node_club switched to db node_club > show collections Thu Mar 15 06:20:27 uncaught exception: error: { “$err” : "unauthorized db:node_club lock type:-1 client:127.0.0.1", “code” : 10057 } > db.auth(“nodeclub","XXXXXXXXX”) 1 > show collections messages replies system.indexes system.users tagcollects users > quit()