标签为 replSet 的文章

MongoDB主从复制与副本集群实践

参考资料:
http://www.cnblogs.com/huangxincheng/archive/2012/03/04/2379755.html
http://blog.sina.com.cn/s/blog_a34f10a4010113df.html

一、部署主从复制

1、主服务器和从服务器必须开启安全认证:--auth
2、主服务器和从服务器的admin数据库中必须有全局用户。
3、主服务器的local数据库和从服务器的local数据均有名为repl且密码相同的用户名。

主服务器设置:
dongguo@mongodb:~$ mongo

MongoDB shell version: 2.2.0
connecting to: test
> use admin
switched to db admin
> db.addUser('rootm','rootm')
{
	"user" : "rootm",
	"readOnly" : false,
	"pwd" : "aa6526e3b7cbcecc18b2bd822f7c3547",
	"_id" : ObjectId("50659e14d2fe6be605337c18")
}
> db.addUser('repl','repl')
{
	"user" : "repl",
	"readOnly" : false,
	"pwd" : "c9f242649c23670ff94c4ca00ea06fe7",
	"_id" : ObjectId("5065a85eccf77b17681365b7")
}
> use cloud
switched to db cloud
> db.addUser('repl','repl')
{
	"_id" : ObjectId("5065a7cbb70f43c4d157e8ec"),
	"user" : "repl",
	"readOnly" : false,
	"pwd" : "c9f242649c23670ff94c4ca00ea06fe7"
}
> use local
switched to db local
> db.addUser('repl','repl')
{
	"user" : "repl",
	"readOnly" : false,
	"pwd" : "c9f242649c23670ff94c4ca00ea06fe7",
	"_id" : ObjectId("50659e2cd2fe6be605337c19")
}
> exit
bye

dongguo@mongodb:~$ sudo /etc/init.d/mongod stop

dongguo@mongodb:~$ sudo vim /opt/mongodb/etc/mongod.conf
修改如下设置:

master = true
auth = true

阅读全文 »

,

No Comments