Installing MongoDB
This section provides a step-by-step guide to installing MongoDB.
Prerequisites
Make sure the following things are in place, before you start installation:
- Create a mount point on the instance volume (nvme).
- Attach the additional SSD to the newly created mount point, so that the initial nvme volume size can be expanded.
To install the MongoDB, follow the steps below:
- Edit the /etc/yum.repos.d/mongodb-org-6.0.repo with the following
content.
vi /etc/yum.repos.d/mongodb-org-6.0.repo [mongodb-org-6.0] name=MongoDB Repository baseurl= https://repo.mongodb.org/yum/redhat/8/mongodb-org/6.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://pgp.mongodb.com/server-6.0.asc - Install the
MongoDB.
yum install -y mongodb-org - Update the yum.conf with bind IP address, port number, storage db
path.
Use the following the mongodb.conf file.echo "exclude=mongodb-org,mongodb-org-database,mongodb-org-server,mongodb-mongosh,mongodb-org-mongos,mongodb-org-tools" >> /etc/yum.conf sed -i "s|OPTIONS=-f /etc/mongod.conf|OPTIONS=--replSet cdprsg -f /etc/mongod.conf" /usr/lib/systemd/system/mongod.service vi /etc/mongod.conf# mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # where to write logging data. systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log # Where and how to store data. storage: dbPath: /sdd journal: enabled: true # engine: # wiredTiger: # network interfaces net: port: 51090 bindIp: puapso1ahxcdmgodbs1001.hxcd.aws.hclsw.internal # how the process runs processManagement: timeZoneInfo: /usr/share/zoneinfo security: authorization: disabled operationProfiling: mode: all slowOpThresholdMs: 200 #replication: # replSetName: "cdprsg" #sharding: ## Enterprise-Only Options: #auditLog: #snmp: - Now, change the file ownership and reload deamon usng the following commands.
chown -R mongod: /sdd chcon -R --reference=/var/lib/mongo /sdd semanage port -a -t mongod_port_t -p tcp 51090 systemctl daemon-reload systemctl restart mongod systemctl status mongod - Validate the connectivity with other
nodes.
nc -zv puapso1bhxcdmgodbs1002.hxcd.aws.hclsw.internal 5190 nc -zv puapso1ahxcdmgodbs1003.hxcd.aws.hclsw.internal 5190 nc -zv puapso1bhxcdmgodbs1004.hxcd.aws.hclsw.internal 5190 nc -zv puapso1ahxcdmgodbs1005 5190 - Connect the MongoDB cluster with the specified hostname.
mongosh --host puapso1ahxcdmgodbs1001.axcd.aws.hclsw.internal --port 51090 - Configure replica set and initiate
it.
use admin; conf={ _id: "cdprsg", members: [ { _id: 0, host: "puapso1ahxcdmgodbs1001.hxcd.aws.hclsw.internal:51090", tags: {usage: "schedule"} }, { _id: 1, host: "puapso1bhxcdmgodbs1002.hxcd.aws.hclsw.internal:51090", tags: {usage: "schedule" }}, { _id: 2, host: "puapso1ahxcdmgodbs1003.hxcd.aws.hclsw.internal:51090", tags: {usage: "segloader" }}, { _id: 3, host: "puapso1bhxcdmgodbs1004.hxcd.aws.hclsw.internal:51090", tags: {usage: "analytics" }}] } rs.initiate(conf); rs.addArb("puapso1ahxcdmgodbs1005:51090"); conf = rs.conf() conf.members[3].hidden = true rs.status() - Create three users in the admin database with specific roles and
privileges.
use admin; db.createUser( { user: "rtsms", pwd: "<password>", roles: [{ role: "readWrite", db: "segmentation" }, { role: 'dbAdmin', db: 'segmentation' }] }); db.createUser( { user: "segdbconnector", pwd: "<password>", roles: [{ role: "readWrite", db: "segmentation" }] }); db.createUser( { user: "pmm", pwd: "Vism6lUIkw5O6BX7fxJB9w", roles: [ { role: 'backup', db: 'admin' }, { role: 'clusterMonitor', db: 'admin' }, { role: 'read', db: 'local' }, { role: 'readWrite', db: 'admin' }, { role: 'restore', db: 'admin' }] });
Installing Node Exporter
To install the node exporter, follow the steps below:
- Download the latest node exporter package, and extract the
package.
wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz tar xfz node_exporter-*.*-amd64.tar.gz - Move the extracted binary from the extracted directory to the local bin
location.
sudo mv node_exporter-*.*-amd64/node_exporter /usr/local/bin/ - Optionally, create a
user.
sudo useradd -rs /bin/false node_exporter - Update the service file as shown
below:
vi /etc/systemd/system/node_exporter.service [Unit] Description=Node Exporter After=network.target [Service] User=node_exporter Group=node_exporter Type=simple ExecStart=/usr/local/bin/node_exporter [Install] WantedBy=multi-user.target - Reload Daemon to ensure the Node Exporter service is properly configured and
running.
restorecon -Rv /usr/local/bin systemctl daemon-reload systemctl start node_exporter systemctl status node_exporter systemctl enable node_exporter curl -kv http://localhost:9100/metrics
Installing MongoDB Exporter
To install the MongoDB exporter, follow the steps below:
- Download the MongoDB exporter, a tool for collecting metrics about your MongoDB
cluster.
wget https://github.com/percona/mongodb_exporter/releases/download/v0.40.0/mongodb_exporter-0.40.0.linux-64-bit.rpm - Install the MongoDB
package.
rpm -Uhv mongodb_exporter-0.40.0.linux-64-bit.rpm - Update the MongoDB exporter service
file.
vi /etc/systemd/system/mongodb_exporter.service [Unit] Description=Prometheus MongoDB Exporter Documentation= https://github.com/percona/mongodb_exporter After=network.target [Service] Type=simple User=mongodb_exporter Group=mongodb_exporter Environment="OPTIONS=--mongodb.uri=mongodb://pmm:Wrtu9v0UGaqgohsYePtiMQ==@puapso1ahxcdmgodbs1001.hxcd.aws.hclsw.internal:51090 --compatible-mode" EnvironmentFile=-/etc/default/mongodb_exporter ExecStart=/usr/bin/mongodb_exporter $OPTIONS SyslogIdentifier=mongodb_exporter Restart=always [Install] WantedBy=multi-user.target - Reload Daemon to ensure the MongoDB exporter service is properly configured and
running.
systemctl daemon-reload systemctl start mongodb_exporter systemctl status mongodb_exporter systemctl enable mongodb_exporter curl -kv http://localhost:9216/metrics