Several mongod servers with systemd

To experiment, I am trying to figure out how to start multiple servers from the mongod.service in systemd.

Is this possible? Or do I need to set multiple services?

I never done it.

Should be easy with an understanding of systemd unit file.

Basically, just like you would need a different configuration file for each instances you will need a different systemd unit file, most likely by copying and editing the one for mongod. For example, you would end up with services like

  • mongod-s1-rs1 (mongod shard 1 replica set 1)
  • mongod-s1-rs2 (mongod shard 1 replica set 2)
  • mongod-s1-rs3 (…)
  • mongod-s2-rs1 (mongod shard 2 replica set 1)
  • mongod-s2-rs2 (…)
  • mongod-s2-rs3 (…)
  • mongod-cs-rs1 (mongod config server replica set 1)
  • mongod-cs-rs2 (…)
  • mongod-cs-rs3 (…)
  • mongos

However, since replication is there to make a system more available, having all members of a replica set running on the same hardware does not make a system that much more available. One hardware failure and the whole thing is down, not a good architecture. And I wrote same hardware, because running all the members of a replica set on different VM on the same hardware is almost as bad as 3 processes on the same hardware.

For further question on this, I think it would be more appropriate to use the developper’s forum at

1 Like

OK, I will go and have a look there.