If you don't want to read the whole thing, here are some quick notes:
- install MongoDB on all your servers;
- decide on which one will be the master;
- edit /etc/mongodb.conf on the master and set the following parameters:
logappend = true
bind_ip =
port = 27017
fork = true
auth = true
master = true
- edit /etc/mongodb.conf on the slaves and set the following parameters:
logappend = true
bind_ip =
port = 27017
fork = true
auth = true
slave = true
source =
# slavedelay = 7200
autoresync = true
- start MongoDB on your master and slave servers
Note: the "slavedelay" parameter can be used to lag the sync process on the slaves. This can be really useful to maintain different historical versions of your databases!
The tutorial also mentioned you should probably run "mongod" with "--fastsync" during your first sync process to speed up the initial synchronization.
For debugging purposes, I suggest trying it out with "noauth=true" (instead of "auth=true") on both your master and slaves (otherwise you'll also need to setup a rep1.
When MongoDB's authentication mode is active, the slave database will use the repl user in the local.system.users collection to authenticate to the source (master) database. If the repl user is absent, MongoDB tries the first user record in the local.system.users collection.
And that's about it! Every time you add a collection or a document to a collection, it will be automatically synced across the slave servers.

thank you :)
ReplyDeletei've a question (beginner):
what the difference between this technique and adding to the driver (pymongo) a value w=3 for 3 copies.
(db.users.insert(user, w=3))
Aliane,
DeleteI'm no expert myself but...here are my two cents... :o)
The setup I describe makes all collections be automatically replicated across ALL your slaves.
What this means is that, no matter if you have 3 or 100 slaves, all of them will always be in sync with the exact same data and you can read from any of them.
This also allows you to use the exact same application without having to make changes to it to specify how many copies of the data to make.
Now, I'm still learning about sharding and replica sets (I actually planned on playing around with it this afternoon).
According to the tests I did so far, it seems sharding can be used to spread your collection across different sharding servers.
So, instead of making several copies, it actually splits it across multiple servers.
As for replica sets, I haven't read enough about them so I do not know much about what they are used for.
Also, it is actually the first time I came across your example so, at this point, I do not even know if that is a flag specific to the pymongo driver OR if it is a default setting (that somehow relates to replica sets).
Anyway, what I can tell you right now is that, if you just want to maintain backups of your copy (copies that you can read from with a normal connection to the mongodb server), use the setup I described here.
Thanks,
Luis
thank you :D
Deleteam a newbie, and because i use python to interract with mongodb, i've found some things that are independent from user input, for example making index, i thought that i just add it to the user so everytime he updates the DB then the indexes will be created (yes i know, i'm to naive to explose the database server ^_^ ), so this why i was asking between making this directly from the server, or adding it to the driver and get "triggered" for each client operation (using the python driver)