Skip to content

Instantly share code, notes, and snippets.

@ilake
Last active December 16, 2015 01:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilake/5355509 to your computer and use it in GitHub Desktop.
Save ilake/5355509 to your computer and use it in GitHub Desktop.

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