win7下MongoDB集群告别裸奔
MongoDB默认是不需要用户密码就可以登录的,就好像在局域网中裸奔一样。在《10分钟配置MongoDB集群》一文中配置的集群就是在裸奔,本文将解决这一问题。单节点配置用户认证比较容易,打开auth开关即可。参考网址(跑题了~~):http://docs.mongodb.org/manual/tutorial/control-access-to-mongodb-with-authentication/
回归正题,集群配置用户认证稍复杂一些。需要做如下工作:
第一步:配置并启动一个裸奔的集群,参见《10分钟配置MongoDB集群》
第二步:创建N+1个用户,例如:本例在shard1/shard2/mongos各建一个,共建三个用户
[*]mongos> use admin
[*]mongos> db.addUser("mongoAdmin","123456")
[备注] 三个用户可以不同,这样就可以避免mongos用户直接访问shard
第三步:创建key文件,配置keyFile参数
本文创建了machine.key文件,configsvr/shard/mongos都配置keyFile=I:\mongodb\cluster\machine.key
第四步:重启mongoDB集群
打开mongo客户端,提示符不再是“mongos>”,而是“>”,完整登录过程示例如下:
[*]I:\mongodb\tools>call I:\mongodb\driver\bin\mongo.exe localhost:27100
[*]MongoDB shell version: 2.2.2
[*]connecting to: localhost:27100/test
[*]> use admin
[*]switched to db admin
[*]> db.auth("mongoAdmin","123456")
[*]1
[*]mongos> show collections
[*]system.indexes
[*]system.users
[*]mongos>
页:
[1]