Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

omvmike/mongo_replica_sandbox

Repository files navigation

Config MongoDB replica set in sandbox via docker

This repo can help you to run MongoDB replica faster then just using step to step leads from articles below. You can use this as quick to deploy test environment if you want to play with MongoDB replica in a sandbox.

This is an implementation of this article Create a MongoDB Replica Set

Additional links Build Database Clusters with MongoDB

Notes

  • mongo-keyfile - cluster key should be added to all servers in the cluster
  • Docker-configsrv - docker config for mongo instances

call openssl rand -base64 756 > mongo-keyfile to create new key file

  • configsrv-mongod.conf - mongod.conf file for replica set instances

How to run

  • Build and run cluster docker-compose up
  • Connect to instance docker-compose exec mongo-replica-1 bash
  • Log in to mongo mongo -u root -p --authenticationDatabase admin default password is example
  • From the mongo shell, initiate the replica set: rs.initiate()
  • While still connected to the mongo shell, add the other hosts to the replica set:
    1. Three replica hosts config
 rs.add("mongo-replica-2")
 rs.add("mongo-replica-3")
  1. Two replicas and arbiter config
rs.add("mongo-replica-2")
rs.addArb("mongo-replica-3")
  • In case you want to some server as master by default you can increase its priority
config = rs.config()
config.members[0].priority = 2
rs.reconfig(config)

Once all members have been added, check the configuration of your replica set:

rs.conf() This will display a replica set configuration object with information about each member as well as some metadata about the replica set.

If you need to do so in the future, you can also check the status of your replica set:

rs.status()

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published