Open In App

How to Run MongoDB on Google Cloud Platform?

Improve
Improve
Like Article
Like
Save
Share
Report

MongoDB, the most popular NoSQL database in the technical world, is not based on a table-like relational database structure but provides different mechanisms for storing and retrieving data. This storage format is called BSON (similar to JSON). The term “NoSQL” means “non-relational”. A relational database management system (RDBMS) is not the right choice when it comes to controlling big data by design because it is not horizontally expandable. If the database is running on a single server, it will reach a scaling limit. NoSQL databases are more expandable or adaptable. MongoDB is such a NoSQL database that scales by adding more and more servers and increases productivity with a flexible document model.

Using MongoDB on Google Cloud Platform

Here are the Reasons:

  • GCP has the most Dominant network of any cloud provider. Running MongoDB on Google’s cloud platform means you’ll benefit from the low-latency infrastructure Google provides.
  • GCP supports live migration – which means you can migrate your existing VMs from one host to another without downtime.
  • Google has its security built into its culture. You’ll benefit from all the security practices Google has learned and implemented over the years. 

Choosing Right Instance Type

Firstly, you need a compute instance to run MongoDB on, and you should examine how much data you have, what questions you have, and what service level agreements you have with your customers. Ideally, you have to make sure that your chosen instance has enough RAM to support your workload and it has fast enough persistent storage. In general, databases do well with fast persistent storage. Let’s Create New Instance.

Creating the Instance in GCP

Step 1: Go to Compute Engine in GCP and click Create Instance.

Creating-instance

 

Step 2: Fill in your instance type details and click Create. This may take a few seconds – if so, don’t worry.

Filling-details

 

Clicking-create

 

Step 3: MongoDB listens on port 27017. You have to make sure that this port is allowed in your firewall rules for the specific IP addresses you want to grant access to. Be careful, don’t open this port to the world. One way to restrict access is to create a new firewall rule in your VPC like this: Source IP address ranges are allowed server IP addresses that allow access, protocols, and ports. At this point, you have set up your instance. The next step is the installation of MongoDB on the google cloud Platform.

Installation of MongoDB in GCP

Step 1: Firstly, you need SSH in the Ubuntu instance you have created. You can do this in many ways. One way is to use SSH from the browser option that GCP provides. From the command line, run the command below to import the GPG MongoDB public key:

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

Importing-GPG-MongoDB

 

Step 2: Create a file using this command:

echo “deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse” |

sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list

Creating-file

 

Finally, the installation of  MongoDB begins using this command:

sudo apt-get update

Step 3: Installation of MongoDB:

sudo apt-get install -y mongodb-org

Installing-mongoDB

 

And then, you should have MongoDB installed. At this point, if  MongoDB is installed but not running. Start MongoDB with this command:

sudo systemctl start mongod

Command-to-install-mongoDB

 

Now you’ll want to take a moment to verify that MongoDB has been installed properly. To do this, You have to run this command:

sudo systemctl status mongod

If everything is well, you will have a screen like this:

MongoDB-instance-installed

 


Last Updated : 23 Sep, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads