{"id":456,"date":"2013-04-03T08:38:00","date_gmt":"2013-04-03T08:38:00","guid":{"rendered":"https:\/\/opstree.com\/blog\/\/2013\/04\/03\/puppet-module-for-setting-up-multiple-mongos-with-replication\/"},"modified":"2025-11-27T15:59:14","modified_gmt":"2025-11-27T10:29:14","slug":"puppet-module-for-setting-up-multiple-mongos-with-replication","status":"publish","type":"post","link":"https:\/\/opstree.com\/blog\/2013\/04\/03\/puppet-module-for-setting-up-multiple-mongos-with-replication\/","title":{"rendered":"Puppet module for setting up Multiple mongo&#8217;s with replication"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\n<p>In this blog I&#8217;ll be talking about a puppet module, that can be used to installing multiple mongo&#8217;s with replication on a single machine. Since I&#8217;m very new to puppet so you may find this module very crude, but it works :). Their were couple of puppet module already available but most of them are only for installing a single instance of mongo at a machine &amp; I&#8217;ve a specific requirement of installing multiple instances of mongo having master slave replication between them. As I already said that this module may be quiet crude or basic so please bear with that &amp; my approach may also seem a bit unconventional so please let me know what all can be improved in this module or how things could have been done in a better way.<\/p>\n<p>So let&#8217;s start with the actual details first of this module is hosted on github(https:\/\/github.com\/sandy724\/Mongo), if you want to look at the source code you can clone it from github. For installing mongo you would be executing the command<br \/>\n<i>puppet apply -e &#8220;class {mongo:port =&gt; , replSet =&gt; ,master =&gt; ,master_port =&gt; ,}&#8221;<\/i><\/p>\n<p>Command for installing master<br \/>\n<i>puppet apply -e &#8220;class {mongo:port =&gt; 27017, replSet =&gt; sdrepsetcommon,master =&gt; master, master_port =&gt; 27017,}&#8221;<\/i><\/p>\n<p>Command for installing slave<br \/>\n<i>puppet apply -e &#8220;class {mongo:port =&gt; 27018, replSet =&gt; sdrepsetcommon,master =&gt; slave,master_port =&gt; 27017,}&#8221;<\/i><\/p>\n<p>Before going into the details what all this module is doing I will share some details of mongo<\/p>\n<ul style=\"text-align: left;\">\n<li>You can start mongo by executing mongod command<\/li>\n<li>You can provide a configration file which contains details such as\n<ul>\n<li>log directory where mongo would be generating the logs<\/li>\n<li>port at which mongo would be listening for requests<\/li>\n<li>dbpath where mongo would be storing all the data<\/li>\n<li>pidfilepath containg process id of mongo instance, that would be used to check whether mongo is running or not<\/li>\n<li>replSet name of the replicaset<\/li>\n<\/ul>\n<\/li>\n<li>You need to have a mongo as a service installed in you system to start an instance of mongo<\/li>\n<li>For replication you need to execute <i>rs.initiate<\/i> command on the master mongo<\/li>\n<li>For adding another instance into replication you need to execute <i>rs.add(&#8220;:&#8221;)<\/i>\u00a0 command on the master mongo<\/li>\n<\/ul>\n<div style=\"text-align: left;\">Now let&#8217;s go into more details what all this component does, I&#8217;ll be listing down all the steps in bulleted points<\/div>\n<ul style=\"text-align: left;\">\n<li>As you can figure out this module is expecting few parameters :\n<ul>\n<li>port : port at which mongo would be listening,<\/li>\n<li>replSet : name of replicaset which would be used for managing replication<\/li>\n<li>master : A string parameter which would signify whether the mongo setup is for master or slave<\/li>\n<li>master_port : Port at which master instance of mongo would be listening<\/li>\n<\/ul>\n<\/li>\n<li>First of all we create a mongo user<\/li>\n<li>Parent Log directory for the mongo instance is created if it doesn&#8217;t exists with mongo user as owner.<\/li>\n<li>Mongo db directory is created under \/data\/mongo with a naming convention replSet_port, i.e if replSet parameter is sdrepsetcommon &amp; port is 27017 then the data directory for this mongo instance would be\u00a0 \/data\/mongo\/sdrepsetcommon_27017. This directory would be owned by mongo user.<\/li>\n<li>A mongo service would be installed if not already their.<\/li>\n<li>A mongo restart shell script is also placed at the mongo db directory<\/li>\n<li>A file is also placed under the mongo db directory that have a mongo command to setup replication, this file is created conditionally depending on whether we are setting up a master or slave instance.<\/li>\n<li>Finally the replication command is executed on mongo server &amp; restart script is also executed<\/li>\n<\/ul>\n<div style=\"text-align: left;\">\n<p>This concludes the setting up of a mongo instance on a machine.<\/p>\n<p>Just for more details to start mongo we are using <i>mongod -f <\/i> command, this configuration file is saved as a template &amp; the mongo modules processes the template with the values passed &amp; creates the desired mongod.conf. In our case we are evaluating following properties of mongod.conf : logpath, port, dbpath, pidfilepath, replSet<\/p>\n<\/div>\n<div style=\"text-align: left;\"><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this blog I&#8217;ll be talking about a puppet module, that can be used to installing multiple mongo&#8217;s with replication on a single machine. Since I&#8217;m very new to puppet so you may find this module very crude, but it works :). Their were couple of puppet module already available but most of them are &hellip; <a href=\"https:\/\/opstree.com\/blog\/2013\/04\/03\/puppet-module-for-setting-up-multiple-mongos-with-replication\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Puppet module for setting up Multiple mongo&#8217;s with replication&#8221;<\/span><\/a><\/p>\n","protected":false},"author":171775670,"featured_media":29900,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[28070474,3548],"tags":[44070,30871489,551126,768739288],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2025\/11\/DevSecOps-1.jpg","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pfDBOm-7m","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/456"}],"collection":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/users\/171775670"}],"replies":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/comments?post=456"}],"version-history":[{"count":2,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/456\/revisions"}],"predecessor-version":[{"id":30074,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/456\/revisions\/30074"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/media\/29900"}],"wp:attachment":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/media?parent=456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/categories?post=456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/tags?post=456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}