How To Install MongoDB 4.2 / 4.0 on CentOS 6 / RHEL 6

0

MongoDB is an open-source, document-oriented database designed with both scalability and developer agility in mind. Instead of storing your data in tables and rows as you would with a relational database, in MongoDB, you store JSON-like documents with dynamic schemas.

MongoDB is available for Windows, Linux, OS X, and Solaris, MongoDB is available for free under the GNU Affero General Public License. The language drivers are available under an Apache License.

Here, we will see how to install MongoDB on CentOS 6 / RHEL 6.

THIS DOCUMENT IS ALSO AVAILABLE FOR

Set up MongoDB Repository

We will now set up a MongoDB repository on the system to get the latest version of the MongoDB package.

Create a repository file under the /etc/yum.repos.d directory.

MongoDB 4.2

cat <<EOF > /etc/yum.repos.d/mongodb.repo
[mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/6/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
EOF

MongoDB 4.0

cat <<EOF > /etc/yum.repos.d/mongodb.repo
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/6/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
EOF

Install MongoDB

Install MongoDB package using the yum command.

yum install -y mongodb-org

Post Installation

XFS Filesystem

You can store databases in EXT4 or XFS filesystem. But, the use of the XFS filesystem is recommended.

Access Control

By default, MongoDB doesn’t offer an authentication mechanism to restrict access to its contents. To overcome this, we need to edit the configuration file and enable access control.

vi /etc/mongod.conf

Add below lines to the mongod.conf file.

security:
  authorization: enabled

Disable Huge Pages

It is recommended to disable transparent huge pages for the better performance of the MongoDB database.

Ulimit Settings

The default Linux user limit settings for processes, open files, etc are not enough for MongoDB to run. So, set ulimit values as recommended by MongoDB.

Create a limit file inside /etc/security/limits.d directory.

vi /etc/security/limits.d/99-mongodb-nproc.conf

Set the highest ulimit value for mongo user.

mongod soft nofile 64000
mongod hard nofile 64000
mongod soft nproc 64000
mongod hard nproc 64000

Control MongoDB Service

MongoDB can be started/stopped by easy known commands.

To start MongoDB service, run:

service mongod start

To check the status of MongoDB service, run:

service mongod status

Confirm the version of MongoDB.

mongod --version

Output:

db version v4.2.3
git version: 6874650b362138df74be53d366bbefc321ea32d4
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
    distmod: rhel62
    distarch: x86_64
    target_arch: x86_64

Access MongoDB

Run the below command to access MongoDB shell.

mongo

Output:

db version v4.2.3
git version: 6874650b362138df74be53d366bbefc321ea32d4
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
    distmod: rhel62
    distarch: x86_64
    target_arch: x86_64
[root@server-itzgeek-local ~]# mongo
MongoDB shell version v4.2.3
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("a2be871e-186e-4be8-ad51-b03ed5af1f15") }
MongoDB server version: 4.2.3
Welcome to the MongoDB shell.
>

Conclusion

That’s All. I hope you have learned how to install MongoDB on CentOS 6 / RHEL 6.

You might also like