info@solusidb.com

Install MongoDB on CentOS-7.x (64bit)

Configure the package management system (yum).

Create a /etc/yum.repos.d/mongodb-org-4.0.repo file so that you can install MongoDB directly using yum:

# vi /etc/yum.repos.d/mongodb-org-4.0.repo

name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc

Disable SeLinux.

# vi  /etc/sysconfig/selinux

#This file controls the state of SELinux on the system.
#SELINUX= can take one of these three values:
#enforcing - SELinux security policy is enforced.
#permissive - SELinux prints warnings instead of enforcing.
#disabled - No SELinux policy is loaded.
SELINUX=disabled
#SELINUXTYPE= can take one of three two values:
#targeted - Targeted processes are protected,
#minimum - Modification of targeted policy. Only selected processes are protected.
#mls - Multi Level Security protection.
SELINUXTYPE=targeted

Install the MongoDB packages.
To install the latest stable version of MongoDB, issue the following command:

# yum install -y mongodb-org

Before start service mongodb should have THP (Transparent Huge Pages)

step to disable THP

Create the init.d script.
Create the following file at /etc/init.d/disable-transparent-hugepages:

# vi /etc/init.d/disable-transparent-hugepages


#!/bin/bash
#BEGIN INIT INFO
#Provides: disable-transparent-hugepages
#Required-Start: $local_fs
#Required-Stop:
#X-Start-Before: mongod mongodb-mms-automation-agent
#Default-Start: 2 3 4 5
#Default-Stop: 0 1 6
#Short-Description: Disable Linux transparent huge pages
#Description: Disable Linux transparent huge pages, to improve database performance.
#END INIT INFO

case $1 in
start)
if [ -d /sys/kernel/mm/transparent_hugepage ]; then
thp_path=/sys/kernel/mm/transparent_hugepage
elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then
thp_path=/sys/kernel/mm/redhat_transparent_hugepage
else
return 0
fi


echo 'never' > ${thp_path}/enabled echo 'never' > ${thp_path}/defrag re='^[0-1]+$' if [[ $(cat ${thp_path}/khugepaged/defrag) =~ $re ]] then # RHEL 7 echo 0 > ${thp_path}/khugepaged/defrag else # RHEL 6 echo 'no' > ${thp_path}/khugepaged/defrag fi unset re unset thp_path ;;
;
;
esac

Make it executable.
Run the following command to ensure that the init script can be used:

# chmod 755 /etc/init.d/disable-transparent-hugepages

Configure your operating system to run it on boot.

# chkconfig --add disable-transparent-hugepages
# /etc/init.d/disable-transparent-hugepages start

Start service mongodb.

# systemctl start mongod

Login to mongodb.

# mongo

Done!!