RHEL7: How to install a MongoDB service.

Share this link

Presentation of MongoDB

MongoDB Server is an open-source, document database designed for ease of development and scaling.

Prerequisites

As the default MongoDB installation uses the /var/lib/mongo directory to store your databases, keep in mind that the partition or logical volume associated with /var needs adequate space.

Installation Procedure

To install, apply the following steps:

Create a file called /etc/yum.repos.d/mongodb-org-3.2.repo and paste the lines below into:

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

Then, install the MongoDB packages:

# yum install -y mongodb-org

Note: To prevent unintended upgrades, the official MongoDB documentation advises to pin the various packages by adding the following directive in the /etc/yum.conf file:

exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools

Configuration Procedure

Limit Change

The number of processes available for MongoDB in the system is not enough, you need to change the default settings by editing the /etc/security/limits.d/20-nproc.conf file and paste the following lines at the end (source: MongoDB website):

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

Transparent Hugepages Deactivation

To get better performances, it is also recommended to disable transparent hugepages by creating a tuned profile (it is perfectly possible to run MongoDB without the tuned daemon but, in this case, to get good performances will require much more efforts from you) (source: MongoDB website) (if you use an other method, be careful about this bug).

Create the /etc/tuned/no-thp directory:

# mkdir /etc/tuned/no-thp

Create the /etc/tuned/no-thp/tuned.conf file and paste the following lines into:

[main]
include=virtual-guest

[vm]
transparent_hugepages=never

Note1: virtual-guest is supposed to be your current active profile, change it if needed.
Note2: Additional tips are available here.

Enable the new profile:

# tuned-adm profile no-thp

Check the configuration:

# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]

Start and enable at boot time the MongoDB service:

# systemctl start mongod && systemctl enable mongod

Check that MongoDB is correctly working:

# tail /var/log/mongodb/mongod.log | grep "waiting for connections"
2016-12-06T23:02:59.853+0100 I NETWORK  [initandlisten] waiting for connections on port 27017

Access From Outside

Note: By default, the MongoDB service only listens to the local network interface (127.0.0.1). To be able to interact with any other server, comment the BindIP directive in the /etc/mongod.conf configuration file and update the Firewalld configuration with:

# firewall-cmd --permanent --add-port=27017/tcp
# firewall-cmd --reload

Authentication Mode

Then, you can create the root user (you could call it differently) for the mydb database:

# mongo 127.0.0.1/mydb
MongoDB shell version: 3.2.11
connecting to: 127.0.0.1/mydb
...
> db.createUser({ user: "root", pwd: "myPassword", roles: [{role: "root", db: "admin"}] })
Successfully added user: {
        "user" : "root",
        "roles" : [
                {
                        "role" : "root",
                        "db" : "admin"
                }
        ]
}
> exit
bye

To enable the authentication mode, paste the following lines into the /etc/mongod.conf file:

security:
  authorization: enabled

Restart the MongoDB service:

# systemctl restart mongod

Test the new authentication mechanism:

# mongo mydb --username root --password myPassword --authenticationDatabase mydb
MongoDB shell version: 3.2.11
connecting to: mydb
> exit
bye

Source: MongoDB website.

Advanced Optimizations

Besides the standard configuration previously described, they are additional steps to follow to get the best performances.

Kernel Configuration

Edit the /etc/tuned/no-thp/tuned.conf file and paste the following lines:

[sysctl]
vm.swappiness = 1             # almost no swap to disk (0=never swap, 100=always swap)
zone_reclaim_mode = 0         # no memory reclaimed (normally the default value)

Note: According to Percona, assigning 0 to the wm.swappiness kernel parameter doesn’t bring the expected behavior.

In case you are dealing with large-memory (64GB+) database servers, you can also add these recommended settings:

[sysctl]
vm.dirty_ratio = 15           # percentage of total system memory that can hold dirty pages
vm.dirty_background_ratio = 5 # threshold to start flushing dirty pages to disk in the background

Concerning the network side, Percona (see links below) advises to add the following configuration:

[sysctl]
net.core.somaxconn = 4096
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_time = 120
net.ipv4.tcp_max_syn_backlog = 4096

IO Scheduler and Read-Ahead Configuration

The IO Scheduler defines how disk Input/Output are managed (see tutorial).

The deadline IO scheduler should be chosen in all the cases except when dealing with virtual machines where the noop scheduler is the best: it is useless to ask a virtual machine to order its IO when all the work is done at the hypervisor level.

The Read-Ahead setting defines how much data is stored in the cache for each read. This is a way to increase efficiency in case of sequential reads.

As MongoDB reads are not sequential, this ends up wasting cache space.

Percona (see links below) provides a nice way to specify both configurations at the same time.

In the case of a physical server, create the /etc/udev/rules.d/60-sda.rules file and paste the following lines:

# set deadline scheduler and 16kb read-ahead for /dev/sda
ACTION=="add|change", KERNEL=="sda", ATTR{queue/scheduler}="deadline", ATTR{bdi/read_ahead_kb}="16"

Note: You can test the IO scheduler in place with # cat /sys/block/sda/queue/scheduler and the Read-Ahead parameter with # blockdev –getra /dev/sda

Filesystem Configuration

XFS is the best available option when choosing a filesystem, EXT4 being a second-best option.

Also, to avoid access-time metadata updates by default, add the flag noatime to the filesystem mount options in the /etc/fstab file. After a reboot or umount/mount operations with MongoDB stopped, this change will reduce the amount of useless disk IO activity.

Additional Resources

Several websites provide tutorials about installing MongoDB 3.2 on CentOS 7:

Guillaume Gelin provides a curated list of awesome MongoDB resources, libraries, tools and applications.

The Percona blog provides several very interesting posts about MongoDB performances:

The RackSpace developer blog offers two articles about MongoDB tips: part1 & part2.

If you are interested in sharding, the HowToForge website explains you How to Deploy a MongoDB Sharded Cluster on CentOS 7.

The Percona blog also offers many interesting articles about MongoDB:

The ScaleGrid blog provides many interesting articles about MongoDB:

(No Ratings Yet)
Loading...

Upcoming Events (Local Time)

There are no events.

Follow me on Twitter

Archives

vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |