How to install MongoDB on Ubuntu 16.04

Introduction

MongoDB is a free and open source NoSQL document database commonly used in modern web applications. This tutorial will help you set up MongoDB for a production application environment on the server.

Preparation

To follow this tutorial, you need:

An Ubuntu** server** with a non-root account that can use the sudo command has been set up, and the firewall has been turned on. Students who don’t have a server can buy it from here, but I personally recommend you to use the free Tencent Cloud Developer Lab for experimentation, and then buy server.

Step 1-Add MongoDB repository

MongoDB has been included in the Ubuntu package repository, but the official MongoDB repository provides the latest version, which is the recommended way to install the software. In this step, we add this official repository to our server.

Ubuntu ensures the authenticity of the packages by verifying that they are signed with GPG keys, so we must first import their keys into the official MongoDB repository.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80--recv EA312927

After successfully importing the key, you will see:

gpg: Total number processed:1
gpg:               imported:1(RSA:1)

Next, we must add the MongoDB repository details so that apt knows where to download the package.

Issue the following command to create a listing file for MongoDB.

echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse"| sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

After adding the repository details, we need to update the package list.

sudo apt-get update

Step 2-Install and verify MongoDB

Now we can install the MongoDB package ourselves.

sudo apt-get install -y mongodb-org

This command will install multiple packages containing the latest stable version of MongoDB and useful management tools for the MongoDB server.

Next, start MongoDB with systemctl.

sudo systemctl start mongod

You can also use systemctl to check whether the service has started correctly.

sudo systemctl status mongod
● mongodb.service - High-performance, schema-free document-oriented database
 Loaded:loaded(/etc/systemd/system/mongodb.service; enabled; vendor preset: enabled)
 Active:active(running) since Mon 2016-04-2514:57:20 EDT; 1min 30s ago
 Main PID:4093(mongod)
 Tasks:16(limit:512)
 Memory:47.1M
  CPU:1.224s
 CGroup:/system.slice/mongodb.service
   └─4093/usr/bin/mongod --quiet --config /etc/mongod.conf

The last step is to enable MongoDB at system startup.

sudo systemctl enable mongod

The MongoDB server is now configured and running. You can use the systemctl command to manage MongoDB services (for example, sudo systemctl stop mongod, sudo systemctl start mongod).

Step 3-Adjust the firewall (optional)

Assuming that you have enabled a firewall on the server, you cannot access the MongoDB server from the Internet.

If you plan to only use the MongoDB server locally and the application running on the same server, it is recommended to use security settings. However, if you want to be able to connect to the MongoDB server from the Internet, we must allow incoming connections in ufw.

To allow 27017 to access MongoDB on the default port from anywhere, you can use sudo ufw allow 27017. However, enabling Internet access to the MongoDB server on the default installation allows unrestricted access to the entire database server.

In most cases, MongoDB can only be accessed from certain trusted locations, such as another server hosting the application. To accomplish this task, you can allow access to MongoDB's default port, while specifying the IP address of another server that will explicitly allow connections.

sudo ufw allow from your_other_server_ip/32 to any port 27017

You can use the following ufw command to verify the firewall settings changes.

sudo ufw status

You should see the port traffic allowed by 27017 in the output. If you decide to only allow a certain IP address to connect to the MongoDB server, the IP address of the allowed location will be listed in the output instead of Anywhere.

Status: active
​
To                         Action      From
- - - - - - - - - - - - 27017      ALLOW       Anywhere
OpenSSH                    ALLOW       Anywhere
27017( v6)                 ALLOW       Anywhere(v6)OpenSSH(v6)               ALLOW       Anywhere(v6)

in conclusion

You have successfully installed MongoDB on Ubuntu 16.04.

For more Ubuntu tutorials, please go to [Tencent Cloud + Community] (https://cloud.tencent.com/developer?from=10680) to learn more.

Reference: "How to Install MongoDB on Ubuntu 16.04"

Recommended Posts

How to install MongoDB on Ubuntu 16.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Apache on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install Vagrant on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install Memcached on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install Go on Ubuntu 20.04
How to install Mailpile on Ubuntu 14.04
How to install PrestaShop on Ubuntu 16.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Prometheus on Ubuntu 16.04
How to install Jenkins on Ubuntu 18.04
How to install Apache on Ubuntu 20.04
How to install R on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04
How to install MariaDB on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Mono on Ubuntu 20.04
How to install Go on Ubuntu 20.04
How to install Zoom on Ubuntu 20.04
How to install Nginx on Ubuntu 16.04
How to install MongoDB on CentOS 7
How to install OpenCV on Ubuntu 20.04
How to install Spotify on Ubuntu 20.04
How to install Postman on Ubuntu 18.04
How to install Go 1.6 on Ubuntu 16.04
How to install Go on Ubuntu 18.04
How to install MySQL on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 20.04
How to install VLC on Ubuntu 18.04
How to install MongoDB on CentOS 8
How to install TeamViewer on Ubuntu 20.04
How to install Webmin on Ubuntu 20.04
How to install Docker Compose on Ubuntu 18.04
How to install Ubuntu on Raspberry Pi
How to install Bacula Server on Ubuntu 14.04
How to install MySQL on Ubuntu 18.04 (linux)
How to install Ubuntu 19.10 on Raspberry Pi 4
How to install Apache Kafka on Ubuntu 18.04
How to install Apache Maven on Ubuntu 20.04
How to install Apache Tomcat 8 on Ubuntu 16.04