{"id":1476,"date":"2014-03-21T13:00:34","date_gmt":"2014-03-21T12:00:34","guid":{"rendered":"http:\/\/www.unicoda.com\/?p=1476"},"modified":"2020-04-29T22:03:39","modified_gmt":"2020-04-29T20:03:39","slug":"easily-deploy-a-local-mongodb-cluster","status":"publish","type":"post","link":"https:\/\/www.unicoda.com\/?p=1476","title":{"rendered":"Easily deploy a local MongoDB cluster"},"content":{"rendered":"<p>When working with MongoDB, it surely comes a time when you want to try to make it scale. First, by adding replica set, then sharding and at least mix it together to create a simple cluster with replication on each shard. Then, you might want to test monitoring or other functionality, so you will need to launch your cluster, configure it.<\/p>\n<p>If everything goes right, you&rsquo;ll only need to start all your MongoDB instances. Not a big deal, easy to do it at each restart of your computer, just copy paste the right commands. But what if I need a fresh clean cluster to make my test? To answer this question, I wrote a simple script to easily deploy a local mongo cluster composed of one query router, three configuration routers and two shards, each being a replica set composed of one primary mongod and two secondary mongod.<\/p>\n<p>This simple project is on my Github under the name <a href=\"https:\/\/github.com\/vvision\/simple-mongo-cluster\">simple-mongo-cluster<\/a>. The readme describes on which port you&rsquo;ll find which mongo. The script provides 5 operations: <em>{init|start|configure|stop|clean}. <\/em>I will quickly describe each of it.<\/p>\n<p>The <em>init<\/em> operation creates all directories needed to store logs and data. All mongo instances will be started with the <em>start<\/em> parameter. To configure the cluster, use <em>configure.<\/em> For the cluster to be configured, you might need to call <em>configure<\/em> twice, because of shards sometimes not being added at first call. The <em>stop<\/em> operation is just about shutting down the whole cluster. At last, <em>clean<\/em> deletes all directories containing the cluster configuration files, data and logs so that you can start a fresh new cluster.<\/p>\n<p>I hope it will help other developers who want to easily test and discover MongoDB cluster possibilities in a local environment as it helps me. If you have any suggestions, just let me know or fork the project, add your script and send me a pull request.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When working with MongoDB, it surely comes a time when you want to try to make it scale. First, by adding replica set, then sharding and at least mix it together to create a simple cluster with replication on each shard. Then, you might want to test monitoring or other functionality, so you will need &hellip; <a href=\"https:\/\/www.unicoda.com\/?p=1476\" class=\"more-link\">Continuer la lecture<span class=\"screen-reader-text\"> de &laquo;&nbsp;Easily deploy a local MongoDB cluster&nbsp;&raquo;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,506,5],"tags":[168,156,169],"class_list":["post-1476","post","type-post","status-publish","format-standard","hentry","category-code","category-projets-2","category-terminal","tag-cluster","tag-mongodb","tag-script"],"_links":{"self":[{"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/posts\/1476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1476"}],"version-history":[{"count":1,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/posts\/1476\/revisions"}],"predecessor-version":[{"id":1477,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/posts\/1476\/revisions\/1477"}],"wp:attachment":[{"href":"https:\/\/www.unicoda.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}