MongoDB Replica Set

Azure Public Test Date Azure Public Test Result

Azure US Gov Last Test Date Azure US Gov Last Test Result

Best Practice Check Cred Scan Check

Deploy To Azure Deploy To Azure US Gov Visualize

This template deploys a MongoDB Replica Set on CentOS and enables Zabbix monitoring, and allows user to define the number of secondary nodes. The replica set has a primary node, 2 secondary nodes by default.

This template also allows you to input your existing zabbix server IP address to monitor these MongoDB nodes.

The replica set nodes are exposed on public IP addresses that you can access through SSH on the standard port, also mongodb port 27017 open.

The nodes are under the same subnet The primary node ip is, the secondary nodes ip address start from For example:

  • primary node ip:

  • secondary node 1 ip:

  • secondary node 2 ip:

##Important Notice Each VM of the replica set uses raid0 to improve performance. We use 4 data disks on each VM for raid0. The size of data disks(setup raid0) on each VM are determined by yourself. However, there is size of data disks limit per the VM size. Before you set the size of data disks, please refer to the link for the correct choice.

##After deployment, you can do below to verify if the replica set really works or not:

  1. SSH connect to primary node, execute below
$mongo -u "<mongouser>" -p "<mongopassword>" "admin"



Upper rs.status() command will show the replica set details.

  1. You can also check the data replication status. SSH connect to primary node, execute below:
$mongo -u "<mongouser>" -p "<mongopassword>" "admin"

use test

db.mycol.insert({"title":"MongoDB Overview"})

  • 2.1 SSH connect to secondary nodes, execute below

    $mongo -u "<mongouser>" -p "<mongopassword>" "admin"
    use test
    show collections
  • 2.2 If db.mycol.find() command can show the result like primary node does, then means the replica set works.

##Known Limitations

  • The MongoDB version is 3.2.
  • We expose all the nodes on public addresses so that you can access MongoDB service through internet directly.
  • MongoDB suggests that the replica set has an odd number of voting members. So the number of secondary nodes is better to set to even number, like 2, 4 or 6, then plus the primary node, fill the requirement that the replica set has an odd number of voting members.
  • A replica set can have up to 50 members, but only 7 voting members. So the maximum number of secondary nodes is 6.
  • The replica set doesn't have arbiter nodes.
  • The replica set enables internal authentication. Check /etc/mongokeyfile for details.
  • More MongoDB usage details please visit MongoDB website .

Tags: Microsoft.Resources/deployments, Microsoft.Network/networkSecurityGroups, Microsoft.Network/publicIPAddresses, Microsoft.Network/networkInterfaces, Microsoft.Compute/virtualMachines, Microsoft.Compute/virtualMachines/extensions, CustomScript, Microsoft.Storage/storageAccounts, Microsoft.Compute/availabilitySets, Microsoft.Network/virtualNetworks