登陆mongodb 数据库:显示报警信息如下:

2018-09-12T05:41:06.390+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-09-12T05:41:06.390+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'

原因:

就是允许hugepage可以动态分配,而不是系统启动时预先分配,对内存消耗很大的服务都不喜欢它,坑人无数。

这个配置会在多个服务上都是坑 :hdfs 、elasticsearch ,mongodb ,oracle ,推荐默认系统初始化就关掉。

关闭方法:

centos上的关闭方法是
echo never > /sys/kernel/mm/transparent_hugepage/enabled

ubuntu:

echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never> /sys/kernel/mm/transparent_hugepage/defrag

永久关闭

写入文件 :/etc/rc.local

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi

或者

1: Create the init.d script.
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

2

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

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

参考信息:
http://www.mongoing.com/docs/tutorial/transparent-huge-pages.html
https://blog.csdn.net/csfreebird/article/details/49307935