{"id":27243439,"url":"https://github.com/dalee/mongodb-ha-playground","last_synced_at":"2026-04-29T17:04:12.833Z","repository":{"id":67450043,"uuid":"102638868","full_name":"Dalee/mongodb-ha-playground","owner":"Dalee","description":"Minimal MongoDB 3.2 High Availability setup with failover and correct load balancing.","archived":false,"fork":false,"pushed_at":"2018-10-21T19:30:48.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T20:50:46.237Z","etag":null,"topics":["example","high-availability","mongodb","setup"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Dalee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-09-06T17:35:44.000Z","updated_at":"2023-07-12T14:09:18.000Z","dependencies_parsed_at":"2023-06-11T06:30:24.069Z","dependency_job_id":null,"html_url":"https://github.com/Dalee/mongodb-ha-playground","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Dalee/mongodb-ha-playground","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dalee%2Fmongodb-ha-playground","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dalee%2Fmongodb-ha-playground/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dalee%2Fmongodb-ha-playground/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dalee%2Fmongodb-ha-playground/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dalee","download_url":"https://codeload.github.com/Dalee/mongodb-ha-playground/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dalee%2Fmongodb-ha-playground/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32435122,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T13:34:34.882Z","status":"ssl_error","status_checked_at":"2026-04-29T13:34:29.830Z","response_time":110,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["example","high-availability","mongodb","setup"],"created_at":"2025-04-10T20:36:55.430Z","updated_at":"2026-04-29T17:04:12.828Z","avatar_url":"https://github.com/Dalee.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Minimal MongoDB 3.2 High Availability setup\n\nVagrant based playground for setting up two MongoDB instances with\nreplication, failover and correct load balancing.\n\n## setting up\n\n```\n$ vagrant up\n$ vagrant ssh\n$ /vagrant/setup.sh\n```\n\nInitial configuration:\n* domains `db1.example.com`, `db2.example.com` and `arbiter1.example.com` are aliases for `127.0.0.1`\n* mongodb on `db1.example.com:27017` is `primary`\n* mongodb on `db2.example.com:27018` is `secondary`\n* mongodb on `arbiter1.example.com:47017` is `arbiter`\n* haproxy on port `27016` is mongodb balancer\n* `replSetName` is `rs0` (it's just name for mongo-ha replication instances)\n* `electionTimeoutMillis` is set to 2s\n\n\u003e Each run of setup.sh script, reverts state to initial configuration.\n\n## checking setup\n\ncheck current `primary` node:\n```\n$ mongo --quiet --port 27016 --eval \"db.isMaster()\"\n{\n\t\"hosts\" : [\n\t\t\"db1.example.com:27017\",\n\t\t\"db2.example.com:27018\"\n\t],\n\t\"arbiters\" : [\n\t\t\"arbiter1.example.com:47017\"\n\t],\n\t\"setName\" : \"rs0\",\n\t\"setVersion\" : 1,\n\t\"ismaster\" : true,\n\t\"secondary\" : false,\n\t\"primary\" : \"db1.example.com:27017\",\n\t\"me\" : \"db1.example.com:27017\",\n\t\"electionId\" : ObjectId(\"7fffffff0000000000000001\"),\n\t\"maxBsonObjectSize\" : 16777216,\n\t\"maxMessageSizeBytes\" : 48000000,\n\t\"maxWriteBatchSize\" : 1000,\n\t\"localTime\" : ISODate(\"2017-09-06T17:22:16.887Z\"),\n\t\"maxWireVersion\" : 4,\n\t\"minWireVersion\" : 0,\n\t\"ok\" : 1\n}\n```\n\ncreate sample database and collection via `haproxy`:\n```\n$ mongo --quiet --port 27016 --eval 'db.hello.insert({\"name\":\"world\"});' test-db\nWriteResult({ \"nInserted\" : 1 })\n```\n\nensure test collection is exists and accessible via `haproxy`:\n```\n$ mongo --quiet --port 27016 --eval \"db.hello.find()\" test-db\n{ \"_id\" : ObjectId(\"59b04b541e80cc01f7d66afd\"), \"name\" : \"world\" }\n```\n\n## testing failover\n\nkill current `primary` node:\n```bash\n$ kill -9 $(mongo --quiet --port 27017 --eval \"JSON.stringify(db.serverStatus())\" | jq '.pid.floatApprox')\n```\n\nwait for few seconds (should happen within `electionTimeoutMillis`)...\n\nensure current `primary` node is on port `27018` and accessible via `haproxy`:\n```\n$ mongo --quiet --port 27016 --eval \"db.isMaster()\"\n{\n\t\"hosts\" : [\n\t\t\"db1.example.com:27017\",\n\t\t\"db2.example.com:27018\"\n\t],\n\t\"arbiters\" : [\n\t\t\"arbiter1.example.com:47017\"\n\t],\n\t\"setName\" : \"rs0\",\n\t\"setVersion\" : 1,\n\t\"ismaster\" : true,\n\t\"secondary\" : false,\n\t\"primary\" : \"db2.example.com:27018\",\n\t\"me\" : \"db2.example.com:27018\",\n\t\"electionId\" : ObjectId(\"7fffffff0000000000000002\"),\n\t\"maxBsonObjectSize\" : 16777216,\n\t\"maxMessageSizeBytes\" : 48000000,\n\t\"maxWriteBatchSize\" : 1000,\n\t\"localTime\" : ISODate(\"2017-09-06T17:23:38.045Z\"),\n\t\"maxWireVersion\" : 4,\n\t\"minWireVersion\" : 0,\n\t\"ok\" : 1\n}\n```\n\nensure test collection and database exists and accessible via `haproxy`:\n```\n$ mongo --quiet --port 27016 --eval \"db.hello.find()\" test-db\n{ \"_id\" : ObjectId(\"59b0305101c76adf9a0cb8ee\"), \"name\" : \"world\" }\n```\n\n## return failed mongodb node back\n\nstart killed node:\n```\n$ sudo systemctl start mongodb-27017\n```\n\nensure mongodb node on port `27017` is `secondary`:\n```\n$ mongo --quiet --port 27017 --eval \"db.isMaster()\"\n{\n\t\"hosts\" : [\n\t\t\"db1.example.com:27017\",\n\t\t\"db2.example.com:27018\"\n\t],\n\t\"arbiters\" : [\n\t\t\"arbiter1.example.com:47017\"\n\t],\n\t\"setName\" : \"rs0\",\n\t\"setVersion\" : 1,\n\t\"ismaster\" : false,\n\t\"secondary\" : true,\n\t\"primary\" : \"db2.example.com:27018\",\n\t\"me\" : \"db1.example.com:27017\",\n\t\"maxBsonObjectSize\" : 16777216,\n\t\"maxMessageSizeBytes\" : 48000000,\n\t\"maxWriteBatchSize\" : 1000,\n\t\"localTime\" : ISODate(\"2017-09-06T19:29:12.940Z\"),\n\t\"maxWireVersion\" : 4,\n\t\"minWireVersion\" : 0,\n\t\"ok\" : 1\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdalee%2Fmongodb-ha-playground","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdalee%2Fmongodb-ha-playground","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdalee%2Fmongodb-ha-playground/lists"}