Mongodb Installation Required Read System Optimization

Posted by comtek on Thu, 09 Apr 2020 23:24:20 +0200

Mongodb released two available service versions: Community and Enterprise

The Monodb we use is a community version
Official Recommendation:
For the best installation experience, MongoDB provides packages for popular Linux distributions.These packages are the preferred way to run MongoDB.
1. linux platform support

Install on Red Hat

Supports the installation of MongoDB Community Edition on Red Hat Enterprise and related Linux systems.

Install on Ubuntu

Supports the installation of MongoDB Community Edition on Ubuntu Linux systems.

Install on Debian

Supports the installation of MongoDB Community Edition on Debian systems.

Install on SUSE

Supports the installation of MongoDB Community Edition on SUSE Linux systems.

Install on Amazon

Supports the installation of MongoDB Community Edition on Amazon Linux AMI systems.

MongoDB does not support Linux's Windows Subsystem (WSL).

2. Mac OS Platform Support
MongoDB 4.2 Community Edition supports macOS 10.12 or later.

3. Windos Platform Support
MongoDB 4.2 Community Edition supports the following 64-bit versions of Windows on the x86_64 architecture:

Windows Server 2019
Windows 10 / Windows Server 2016
Windows 8.1 / Windows Server 2012 R2
Windows 8 / Windows Server 2012
Windows 7 / Windows Server 2008 R2

MongoDB only supports 64-bit versions of these platforms.

Centos System Optimization Before Mongodb Installation

1. System Prohibits THP
2. Set up system ulimit
3. Turn off iptables and SElinux

1. Why should THP be prohibited

Transparent Huge Pages(THP) has been introduced since version 6 of [CentOS], and this feature is enabled by default starting with version 7 of CentOS.Although THP is meant to improve memory performance, some database vendors recommend turning off THP directly (e.g. [Oracle], MariaDB, MongoDB, etc.). Transparent Huge Pages can cause memory allocation delays at runtime. Transparent Large Pages (THP) is a Linux memory management system that reduces the overhead of backup buffer (TLB) lookups on the machine.

View the startup status of THP:

[root@master ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
[root@master ~]# cat /sys/kernel/mm/transparent_hugepage/defrag
[always] madvise never

Run the following command to disable THP immediately

[root@master ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@master ~]# echo never > /sys/kernel/mm/transparent_hugepage/defrag
[root@master ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
[root@master ~]# cat /sys/kernel/mm/transparent_hugepage/defrag
always madvise [never]
However, a system restart will not take effect.

Use services to control THP

Either way
systemd (systemctl)

[root@master ~]# cat /etc/systemd/system/disable-transparent-huge-pages.service

[Unit]
Description=Disable Transparent Huge Pages (THP)
DefaultDependencies=no
After=sysinit.target local-fs.target
Before=mongod.service

[Service]
Type=oneshot
ExecStart=/bin/sh -c 'echo never | tee /sys/kernel/mm/transparent_hugepage/enabled > /dev/null'
ExecStart=/bin/sh -c 'echo never | tee /sys/kernel/mm/transparent_hugepage/defrag > /dev/null'
[Install]
WantedBy=basic.target

[root@master ~]# systemctl daemon-reload
[root@master ~]# systemctl enable disable-transparent-huge-pages
[root@master ~]# systemctl start disable-transparent-huge-pages

System V Init (service)
[root@master ~]# /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' | tee ${thp_path}/enabled > /dev/null

    unset thp_path
    ;;
esac

[root@master ~]# chmod 755 /etc/init.d/disable-transparent-hugepages
[root@master ~]# chkconfig --add disable-transparent-hugepages
[root@master ~]# /etc/init.d/disable-transparent-hugepages start

2. UNIX ulimit settings

Most UNIX-like operating systems, including Linux and macOS, provide a way to limit and control the use of process- and user-based system resources such as threads, files, and network connections.These ulimit s prevent an individual user from using too many system resources.Sometimes, the default values for these restrictions are low and can cause many problems during normal MongoDB operations.
mongod and mongos track connections and manage internal operations each time using threads and file descriptors.This section outlines the general resource utilization patterns of MongoDB.Use these numbers in conjunction with actual information about your deployment and its use to determine the ideal ulimit settings.

Typically, all mongod and mongos instances:

  • Use file descriptors and threads to track each incoming connection.
  • Track each internal thread or pthread as a system process

ulimit refers to various resource constraints for each user.Therefore, if your [mongod] instance executes as a user running multiple or more [mongod] processes at the same time, you may see contention for these resources.Also, note that the processes value (that is, -u) refers to the number of combinations of different processes and child process threads.

You can ulimit change settings by issuing commands in the following format:

ulimit -n <value>

Hard and soft ulimit settings affect Mongodb's performance. Hard ulimit is the maximum number of processes a user can activate.

Red Hat Enterprise Linux and entOS 6 and 7 enforce a single maximum process limit nproc that overrides the ulimit setting.This value is defined in the following configuration file, depending on the version:
System Version value file
RHEL / CentOS 7 4096 /etc/security/limits.d/20-nproc.conf
RHEL / CentOS 6 1024 /etc/security/limits.d/90-nproc.conf

Modify ulimit two methods

1,Add configuration information:

[root@master ~]# vim /etc/security/limits.d/20-nproc.conf

*          soft    nproc     64000
*          soft    nofile     64000

Restart the mongodb service

2,Add Configuration

[root@master ~]#vim  /etc/security/limits.conf
mongod soft nofile 64000
mongod hard nofile 64000
mongod soft nproc 32000
mongod hard nproc 32000

Restart the mongodb service:

3. Turn off iptables and SElinux

systemctl status firewalld.service
systemctl stop firewalld.service
systemctl disable firewalld.service

Configuration file: /etc/selinux/config
Set the parameter to: SELINUX=disabled

Server time zone: We want to configure the time service to ensure that the server time is consistent.

Topics: Database MongoDB Linux Windows CentOS