NeevAI SuperCloud
LoginSIGN UP
  • NeevCloud Account
    • Getting Started with Neev account
      • Create & activate NeevCloud account
        • NeevCloud Account Signup
          • Email Verification
          • KYC Validation
          • Enter Billing Profile
          • Payment Validation
        • Customer Validation Process for Indian Customers
          • If you are the primary contact of the Organization
          • If you are not a Primary Contact in NeevCloud Account
      • Customer Validation Process FAQs
  • NeevCloud Products
    • Dashboard
    • Computes
      • Compute Flavors
      • Getting Started Launch VMs
        • Launch Alma Linux
        • Launch Window Server
        • Launch Instance using the Password
      • Launch instance by 1-click Marketplace platform
        • Create a Tally instance from the Neevcloud Marketplace
        • Create a PostgreSQL instance from Neevcloud Marketplace
        • Create a Nginx instance from Neevcloud Marketplace
        • Create a MariaDB instance from Neevcloud Marketplace
        • Create a Docker instance from Neevcloud Marketplace
        • Create a Nodejs Instance from Neevcloud Marketplace
        • Create a MongoDB Instance from the Neevcloud Marketplace
        • Create a CloudPanel Instance from the Neevcloud Marketplace
        • Create a GitLab Instance from the Neevcloud Marketplace
        • Create a Ubuntu RDP Instance from the Neevcloud Marketplace
        • Create a Clickhouse Instance from the Neevcloud Marketplace
        • Create an OpenLiteSpeed WordPress Instance from the NeevCloud Marketplace
        • Create a FortiGate instance from the Neevcloud Marketplace
      • Manage Cloud Instance
        • Overview
        • Volumes
        • Snapshots
        • Networking
        • Security Group
          • Add Rules to the Security group
        • Rescale
        • Pricing
      • Default username of operating systems
      • Volume-based instances and image-based instances.
      • How to Delete the Instance
    • GPU
      • Deploy GPU Instance with Tesla T4
    • Networking
      • Network
        • Create a Network
        • Create Network With Private IP
      • LoadBalancer
        • Configure Load Balancing
      • Floating IPs
        • Create Floating IPs
        • Assign Floating IPs
      • Routers
        • Create Router
      • Security Groups
        • Add Security Group
        • Allow SSH Port to Specific IP Address
        • Allow ICMP for ping
        • Allow RDP Port to Specific IP Address
      • Subnets
        • Create Subnets
    • Volumes
      • Create a volume
      • Delete a volume
      • Attach Volume to Instance
      • Extend Instance Volume Size
      • To create a server using volume
    • Backups
      • Here's a guide on how to create a backup.
    • Snapshots
      • Create snapshosts
      • Create an Instance using Snapshot
    • Storage
      • Object storage
        • Create Bucket
        • Service URLs for NeevCloud S3
      • Neevcloud S3 integration
        • Connect Acronis Backup Gateway With Neevcloud Storage
        • Connect Veeam Backup Gateway With Neevcloud Storage
        • Connect MSP360 Backup With Neevcloud Storage
        • Connect Vembu Backup with Neevcloud storage
        • Connect Ahsay cloud backup suite(ACBS) with NeevCloud Storage
        • Connect ARQ Backup Solution with NeevCloud Storage
        • Backup your WordPress Site to Neevcloud s3 storage with using Updraft plugin
        • Connect Bucket with S3 Client
        • Connect Bucket with Cyberduck
        • Connect S3 storage to CPanel
        • Connect S3 Drive to NeevCloud S3 Bucket
        • Mount S3 Bucket to Linux operating system
        • How To Mount NeevCloud S3 Bucket as a Window Drive
      • S3 data migrations
        • Migrate from AWS s3 storage to NeevCloud s3 storage
        • Migrate from Wasabi s3 storage to NeevCloud s3 storage
    • Kubernetes
      • Launch Kubernetes Cluster
    • Financial Information
      • Add Fund
      • Bill History
      • Billing Address
      • How Does NeevCloud Billing Works
    • Access Details
      • SSH KEY
        • Generate SSH_KEY
      • Application Credentials
      • S3/EC2 Credentials
        • Create S3/EC2 Credentials
    • Abuse Complaints
      • What is Phishing?
    • Support
    • Security
  • NeevCloud Guide
    • NeevCloud KnowledgeBase
      • Set up LEMP (Linux, Nginx, MySQL, PHP) in Ubuntu Linux
      • Set up LAMP (Linux, Apache, MySQL, PHP) in Ubuntu Linux
      • Set up WordPress in Linux instance
      • Set up Plesk in Ubuntu
      • Set up Cpanel in Linux Instance
      • Set up Grafana
        • Install Grafana and Prometheus on Ubuntu 22.04
      • Set up a MongoDB Cluster using 3 Linux Instances
        • MongoDB Cluster with 3 Linux Instances
      • Setup Ansible Linux Instance and Application deployment on Instances
        • Deployment Application on Instances
      • Install Node.js & NPM on Linux
        • Installation of Node.js and NPM in Alma Linux
      • How to use SFTP for Uploading & Downloading files
      • Two-factor Authentication
      • How to use PuTTY for SSH key-based authentication
      • How To Create VPC on NeevCloud
      • How to Install Nginx on Ubuntu 22.04
      • How To Install Apache on Ubuntu 22.04
      • How To Install MySQL on Ubuntu 22.04
        • Mysql database backup and restore by mysqldump
      • How To Install MariaDB on Ubuntu 22.04
      • How To Install PostgreSQL on Ubuntu 22.04
      • How To Install MongoDB on Ubuntu 22.04
      • How To Install phpMyAdmin on Ubuntu 22.04
      • How To Open Port on Linux
      • How to Install Metabase on Ubuntu 22.04
      • How to transfer data from a Windows server to a NeevCloud bucket using Rclone
      • How to Integrate QNAP NAS storage and Backup to Neevcloud
      • How to Install Remote Desktop (xrdp) on Ubuntu.
      • Setup MLflow in Neevcloud Instance
      • Docker
        • Docker Installation in Ubuntu/Debian
        • Some Best practices for using Docker in application development include:
          • Create a Docker File and using Docker file Build Images
          • Docker Container
          • Docker-Compose
      • Acronis Backup Gateway With Neevcloud
    • Kubernetes
      • Deploy Nginx Service in Kubernetes
      • Deploy Lamp in Kubernetes with using Helm.
      • Deploy WordPress in Kubernetes.
      • Deploy Argocd in Kubernetes
      • Deploy Jenkins in the Kubernetes cluster
    • Troubleshoot
      • How to Access Instances
        • Access Linux instance
        • Access with Password Authentication
        • Access Windows Instance
        • Change the RDP Port and access the windows server
      • How to change the SSH Port
      • Troubleshooting Steps If your Instance is not accessible
      • How to Monitor Server Load on a Windows Cloud Instance
      • Why cloud instance is Out Of disk space
      • High Processor Load on your cloud instance
      • Steps If your Website URL is down
      • Best Practices After Reboot.
      • Reset the root password.
    • Use case
      • High-Level Architecture with Load Balancer and Jump Server in a VPC Setup
    • FAQ
      • Setup Zabbix app
      • How to change the instance Password
      • How to Access a Server Using a Static IP Address
      • What is the billing process for NeevCloud?
      • What payment methods are accepted by NeevCloud?
      • What happens if I miss a payment?
      • What is YAML
      • How can I get support for billing-related issues?
      • Can I contact NeevCloud's technical support team?
      • How to raise the ticket in the NeevCloud
      • Where can I find additional information on pricing and billing?
      • What are the terms and conditions for using Neevcloud services
Powered by GitBook
On this page
  • Setup MongoDB Cluster
  • Prerequisite
  • Configuration and installation
  • Update && Upgrade the system
  • Set the Hostname in each server
  • Server Hostname Configuration
  • To add the MongoDB GPG key
  • Install MongoDB
  • Start MongoDB Service
  • Enable Replication in Each Server's
  • Starting the Replica Set and Adding Members:
  • Conclusion
  1. NeevCloud Guide
  2. NeevCloud KnowledgeBase
  3. Set up a MongoDB Cluster using 3 Linux Instances

MongoDB Cluster with 3 Linux Instances

Setup MongoDB Cluster

Prerequisite

Require two or more servers to set cluster

Ubuntu 22.04

Follow the below steps to set up a 3-node MongoDB cluster:

Configuration and installation

Update && Upgrade the system

Before processing, update and upgrade all packages.

sudo apt-get update -y && sudo apt-get upgrade -y

Check your current hostname by running the following command:

hostname

Set the Hostname in each server

To change the hostname, you can use the hostnamectl command. For example, to set the hostname to "hostname", you would run.

sudo hostnamectl set-hostname myhostname

On Linux and Unix-like systems, the hosts file is located in the /etc/ directory. To edit this file on each of your three servers, use your preferred text editor.

sudo vi /etc/hosts

Server Hostname Configuration

Configuring your servers with descriptive hostnames is advisable as it enhances clarity and ease of management.

  • mongo0.replset.member

  • mongo1.replset.member

  • mongo2.replset.member

Using these hostnames, your /etc/hosts files would look similar to the following highlighted lines:

To add the MongoDB GPG key

Import the MongoDB GPG Key

First, import the MongoDB GPG key to verify the authenticity of the software packages:

To get the latest version of the software, add MongoDB’s dedicated package repository to your APT sources. Then, install the meta-package that always points to the newest MongoDB version.

First, import the public GPG key for the latest stable version of MongoDB using the following command:

sudo wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -

Add MongoDB Repository

Next, add the MongoDB repository to your system's list:

APT (Advanced Package Tool) uses two main locations for finding online package repositories: the sources.list file and the sources.list.d directory. The sources.list file lists repository sources line-by-line, placing the most preferred at the top. The sources.list.d directory allows for modular and organized management by maintaining additional repository sources in separate files.

Execute the following command to create a file named mongodb-org-4.4.list in the sources.list.d directory:

sudo echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu $(lsb_release -sc)/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list

After executing this command, refresh your server’s local package index to ensure APT can locate the MongoDB-org package:

sudo apt-get update -y

Install MongoDB

Now, you can install MongoDB using the following command:

sudo apt-get install mongodb-org -y

This command will install the MongoDB package and its dependencies.

Start MongoDB Service

After installing MongoDB, it should start automatically. To check the service status, run:

sudo systemctl start mongod
sudo systemctl status mongod

Enable MongoDB to Start on the Boot

sudo systemctl enable mongod

Verify Installation

To verify that MongoDB is installed successfully, open the MongoDB shell by following these steps:

sudo mongo --version
sudo mongo

Enable Replication in Each Server's

MongoDB Configuration File:-

You have successfully configured the /etc/hosts file on your servers to map hostnames to their respective IP addresses.

To change MongoDB settings, edit the primary configuration file found at /etc/mongod.conf. This file is created automatically during installation.

Use a text editor vi to open and modify the file. Here’s the command:

sudo vi /etc/mongod.conf

In MongoDB, various configuration options allow you to customize the server's behavior. The system log option manages the database’s logging settings, enabling you to specify what gets logged and where. Conversely, the net option is essential for configuring network-related settings, providing control over parameters such as port configuration and network interfaces.

Update the IP address in each server from 127.0.0.0 to 0.0.0.0.

Create a mongo key file in each server

sudo mkdir -p /etc/mongodb/key-files/

Now create an OpenSSL and run these commands

sudo openssl rand  -base64  756 > /etc/mongodb/key-files/mongo-key

Copy these mongo-key files in another 2 vms

$ sftp root@your_IP_address

Enabling Replication in Each Server's MongoDB Configuration File

After copying the necessary files, proceed by adding the specified keys to the /etc/mongod.conf file on each server.

sudo vi /etc/mongod.conf

Uncomment the security option and add the key

Add the key

keyFile: /etc/mongodb/key-files/mongo-key

Configure the file permissions and ownership in each server

sudo chmod 400 /etc/mongodb/key-files/mongo-key
sudo chown -R mongodb:mongodb /etc/mongodb

Before executing the following command, ensure the Mongod service is stopped.

sudo systemctl stop mongod

Replication runs these commands in all nodes for set replace

sudo /usr/bin/mongod --replSet "evermight" --config /etc/mongod.conf --fork 

Also, add replication of all nodes

sudo systemctl start mongod

Starting the Replica Set and Adding Members:

After setting up your three MongoDB instances, initiate replication by opening a MongoDB shell and adding each instance as a replication member.

sudo mongo

To begin the replication process, execute these commands:

mongo> rs.initiate({_id: "evermight", members: [{_id: 1, host: "mongo1"},{_id: 2, host: "mongo2"}] });

Conclusion

MongoDB is a free, open-source NoSQL database management system (DBMS) popular for large-scale websites or applications. Since it doesn’t use a fixed schematic structure to store data, it is more flexible and scalable than SQL.

PreviousSet up a MongoDB Cluster using 3 Linux InstancesNextSetup Ansible Linux Instance and Application deployment on Instances

Last updated 5 months ago