MongoDB建议设置

##### https://docs.mongodb.com/v3.2/administration/production-notes/#prod-notes-ram

1.Turn off atime for the storage volume containing the database files.

2.Set the file descriptor limit, -n, and the user process limit (ulimit), -u, above 20,000, according to the suggestions in the ulimit reference. 
A low ulimit will affect MongoDB when under heavy use and can produce errors and lead to failed connections to MongoDB processes and loss of service.

3.Disable Transparent Huge Pages. MongoDB performs better with normal (4096 bytes) virtual memory pages. See Transparent Huge Pages Settings.

关闭大页内存
##### https://docs.mongodb.com/v3.2/tutorial/transparent-huge-pages/
Create the following file at /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

4.Disable NUMA in your BIOS. If that is not possible, see MongoDB on NUMA Hardware.

###### https://www.kernel.org/doc/Documentation/sysctl/vm.txt
###### https://docs.mongodb.com/v3.2/administration/production-notes/#production-numa
echo 0 | sudo tee /proc/sys/vm/zone_reclaim_mode

5.Problems have been reported when using MongoDB with SELinux enabled. To avoid issues, disable SELinux when possible.
If you are using SELinux on Red Hat, you must configure SELinux to be able to run MongoDB.

原文地址:https://www.cnblogs.com/hyming011/p/8251696.html