Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Mongodb ReplicaSet

No Arbiter Version

Run 3 mongod instances in local machine.

You would get 3 data nodes

Run the first one

mongod --replSet myreplset --rest

Make a new folder for second and thrid mongod and different port.

mongod --dbpath /usr/local/var/mongodb2 --port 27018  --replSet myreplset --rest
mongod --dbpath /usr/local/var/mongodb3 --port 27019  --replSet myreplset --rest

mongo for primary one ( Choose anyone you like ).

mongo --host 10.0.1.12
rs.initiate()
rs.add("10.0.1.12:27018")
rs.add("10.0.1.12:27019")
rs.status()

In Rails Part

It only work in mongoid3 for me

development:
  sessions:
    default:
      database: dev
      hosts:·
        - 10.0.1.12:27017
        - 10.0.1.12:27018
        - 10.0.1.12:27019

Use Arbiter

You could have 2 data node and 1 arbiter node

Run the first one

mongod --replSet myreplset --rest

Make a new folder for second and thrid mongod and different port.

mongod --dbpath /usr/local/var/mongodb2 --port 27018  --replSet myreplset --rest
mongod --dbpath /usr/local/var/mongodb-arbiter --port 27019  --replSet myreplset --rest

mongo for primary one ( Choose anyone you like ).

mongo --host 10.0.1.12
rs.initiate()
rs.add("10.0.1.12:27018")
rs.addArb("10.0.1.12:27019") 
rs.status()

In Rails Part

development:
  sessions:
    default:
      database: dev
      hosts:·
        - 10.0.1.12:27017
        - 10.0.1.12:27018

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.