The following VMs have been deployed on the NVMe datastores to create the MongoDB cluster in this solution:
- One ConfigDB VM.
- One Mongos VM - this splits the workload, distributes it equally across the sharded cluster, and provides the interface between the client applications and the shaded cluster.
- Six primary shards (Mongod VMs) with two VMs on each compute node.
Steps to deploy a MongoDB cluster:
- Map the datastores which are created from the PowerFlex volumes for the ConfigDB and MongoDB VMs. These datastores can be used for storing metadata and MongoDB application data respectively.
- Log in to the VM and configure the MongoDB YUM repository. Save the following entry in the /etc/yum.repos.d/ directory:
[mongodb-enterprise-6.0]
name=MongoDB Enterprise Repository
baseurl="https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/6.0/$basearch/"
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc
- Install the MongoDB package.
# yum install mongodb-enterprise
Note: For more information, see MongoDB package installation.
- Create a file system on the mapped PowerFlex volumes and mount it.
- Identify the newly added disk by running the following command:
# lsblk
- Create an XFS file system for the device by running the following command:
# mkfs.xfs /dev/<disk-name>
Note: XFS is recommended for data bearing nodes to avoid the performance issues that may occur when using EXT4 with WiredTiger.
- Mount the disk to a directory where it stores the metadata, database, and so on.
# mount /dev/sdb /var/lib/mongo
- To configure the above mount point to be persistent across reboots, update the mount information in the /etc/fstab file and save it.
# /dev/sdb /var/lib/mongo xfs
- Update the mongod configuration file - mongod.conf, in all MongoDB VMs (Mongod, ConfigDB, and Mongos) as per the requirement.
Note: See the example configuration file Mongod Configuration files.
- Start the service with the --config option pointing to the configuration file path.
# mongod --config /etc/mongod.config *Run this on ConfigDB and Mongod VMs
# mongos --config /etc/mongod.config *Run this on Mongos VM
- Verify the status of mongo service by running either ps or lsof (for port utilization) commands:
# ps -aux | grep mongo
Or
# lsof -iTCP -sTCP:Listen | grep mongo
- Connect to the mongo shell on ConfigDB, Mongod and Mongos VM using below command for further configuration:
# mongosh --port <port_number>.
- Initialize replica set on ConfigDB and Mongod VMs using rs.initiate() method.
- To setup sharded cluster, connect to mongo shell on Mongos VM and add shards (mongod) using sh.addShard() method.
- Verify the sharded cluster deployment status using sh.status().
Note: For more information about the sharded cluster deployment, see Deploy a Sharded Cluster.