Install MongoDB on CentOS 7

  Uncategorized

Introduction

MongoDB is a versatile NoSQL database that stores data objects as JSON documents.

Requirements

  • Single server instance with external connectivity
  • CentOS 7 or Red Hat Enterprise Linux 7
  • MongoDB 2.6

Add the Repository

Some Linux distributions may already provide the MongoDB packages in the default distribution repository. The following steps will describe adding a new repository provided by the MongoDB project which provides the latest version available.

Create a /etc/yum.repos.d/mongodb.repo file using any text editor and add the following repository configuration for the 64-bit packages:

[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1

Note: It is recommended that production environments deploy the above 64-bit packages whenever possible. The 32-bit packages are available using the below repository configuration if required:

[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686/
gpgcheck=0
enabled=1

Install MongoDB Packages

Five packages are available from the above repositories.

  • mongodb-org – Meta package that will install the following four packages.
  • mongodb-org-server – MongoDB server, configuration file, and startup/shutdown scripts.
  • mongodb-org-mongos – MongoDB service for a shard cluster.
  • mongodb-org-shell – MongoDB shell used for interacting with MongoDB.
  • mongodb-org-tools – Various MongoDB tools such as mongoexport, mongodump, mongorestore, etc.

All packages will be installed by installing the mongodb-org package:

sudo yum -y install mongodb-org

Specific versions of MongoDB can be installed by including version suffix. When using a specific version, it is recommended that the above package names be excluded in the repository configuration to prevent accidental updates.

Any required changes to MongoDB configuration file should be made after the install is complete. This includes changing the bind IP, enabling the service for replica sets, etc.

Start MongoDB Server

The MongoDB daemon should be enabled to start on boot.

sudo /usr/sbin/chkconfig mongod on

The server can then be started.

sudo /etc/init.d/mongod start

The above commands are still compatible with Red Hat Enterprise Linux 7 and CentOS 7, however, the new systemd commands can also be used.

sudo systemctl enable mongod
sudo systemctl start mongod

You should verify the process is successfully running:

ps auxw | grep mongod
sudo systemctl status mongod

Connect to MongoDB

You should now be able to connect to MongoDB using the mongo client.

mongo

Visits: 15

LEAVE A COMMENT

What is the capital of Egypt? ( Cairo )