Skip to content

Instantly share code, notes, and snippets.

@JakubOboza
Created August 10, 2011 20:47
Show Gist options
  • Save JakubOboza/1138212 to your computer and use it in GitHub Desktop.
Save JakubOboza/1138212 to your computer and use it in GitHub Desktop.
MongoDB ReplicaSet
#!/bin/bash
# My single node ReplicaSet quick test script
mkdir -p /tmp/rs1
mkdir -p /tmp/rs2
mongod --rest --replSet myset &
mongod --rest --replSet myset --dbpath /tmp/rs1 --port 30000 &
mongod --rest --replSet myset --dbpath /tmp/rs2 --port 40000 &
/*
Go to mongo and start replicaset
*/
config = {_id: 'myset', members: [
{_id: 0, host: 'localhost:27017'},
{_id: 1, host: 'localhost:30000'},
{_id: 2, host: 'localhost:40000'}]
}
rs.initiate(config)
rs.status()
rs.slaveOk() // reads from slaves
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment