So let’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
puppet apply -e “class {mongo:port => , replSet => ,master => ,master_port => ,}”
Command for installing master
puppet apply -e “class {mongo:port => 27017, replSet => sdrepsetcommon,master => master, master_port => 27017,}”
Command for installing slave
puppet apply -e “class {mongo:port => 27018, replSet => sdrepsetcommon,master => slave,master_port => 27017,}”
Before going into the details what all this module is doing I will share some details of mongo
- You can start mongo by executing mongod command
- You can provide a configration file which contains details such as
- log directory where mongo would be generating the logs
- port at which mongo would be listening for requests
- dbpath where mongo would be storing all the data
- pidfilepath containg process id of mongo instance, that would be used to check whether mongo is running or not
- replSet name of the replicaset
- You need to have a mongo as a service installed in you system to start an instance of mongo
- For replication you need to execute rs.initiate command on the master mongo
- For adding another instance into replication you need to execute rs.add(“:”) command on the master mongo
- As you can figure out this module is expecting few parameters :
- port : port at which mongo would be listening,
- replSet : name of replicaset which would be used for managing replication
- master : A string parameter which would signify whether the mongo setup is for master or slave
- master_port : Port at which master instance of mongo would be listening
- First of all we create a mongo user
- Parent Log directory for the mongo instance is created if it doesn’t exists with mongo user as owner.
- Mongo db directory is created under /data/mongo with a naming convention replSet_port, i.e if replSet parameter is sdrepsetcommon & port is 27017 then the data directory for this mongo instance would be /data/mongo/sdrepsetcommon_27017. This directory would be owned by mongo user.
- A mongo service would be installed if not already their.
- A mongo restart shell script is also placed at the mongo db directory
- 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.
- Finally the replication command is executed on mongo server & restart script is also executed
Just for more details to start mongo we are using mongod -f command, this configuration file is saved as a template & the mongo modules processes the template with the values passed & creates the desired mongod.conf. In our case we are evaluating following properties of mongod.conf : logpath, port, dbpath, pidfilepath, replSet