i’m trying to setup a multi sharded mongoDB through an ansible script, and so far i’ve managed to set up a single replica sets on my hosts
The whole numbers of services i need to have running is
CFGSVR : 3 mongod instance
SHARD1 : 3 mongod instances in the same replica set
SHARD2 : 3 mongod instances in the same replica set
And additionnaly one mongo router that redirect the traffic between each of them.
i have at disposal 3 vm on a server and 3 other vm on another server
The issue :
I need more mongod instances than vm, hence i must have multiple instances with different configurations (like ports on which it’s running etc)
however the ansible system starting
name: start mongod
service:
name: mongod
state: started
such a task will always refer to the same service so if i run with another variables it will just alter the existing instance
I’d like to know if there a proper ways to tackle such issues, and if there are good practices concerning such maneuver like having a task that setup a service with for example a service named mongod_shrd1 that will run in /etc/shrd1 instead of the default mongod /var/lib/mongodb and all the other things such as where to seek the config file etc…
I thanks anyone for taking time to read this and wait for your inputs !
This is highly dependent on the service itself. If the service supports overriding default config path (/etc/something), listening port, data storage path (/var/lib/something), runtime path (/run/something) etc. then it can be run in multiple independent services. Override would be done through command line options, environment variables or configuration file options (or combination there off). If this is not possible, then running the service in container is the solution. Containers are also the only standardized way to do this. Without containers, you are on your own and there is no universal “proper” way to do it.
General tactic would be to start with the startup process (systemd unit) and follow the path of associated files, finding any options that are hardcoded or values that are assumed (default values) that can cause collisions like directory and file paths, ports, sockets etc. Once all the elements are identified, you can create a parallel dir and file structure, new startup scripts etc. This is mostly trial and error type of workflow. For large and complex services, this can be a considerate undertaking.
For the mongod itself, start with deep dive into documentation related to mongodb startup and configuration and study the startup process on your particular OS (this can widely vary).
You may want to make use of service templates to set up multiple mongodb services. I have used this on other applications (e.g. Tomcat, nginx) to run multiple instances of the same application.