Official MongoDB documentation gives several solutions for this issue. You can also try this solution, which worked for me:
Note: Try official documentation directives if MongoDB version is greater than 3.0
-
Open
/etc/init.d/mongodfile.
(if no such file you might check/etc/init.d/mongod,/etc/init/mongod.conffiles – credit: the below comments) -
Add the lines below immediately after
chown $DAEMONUSER /var/run/mongodb.pidand beforeend script. - Restart
mongod(service mongod restart).
Here are the lines to add to /etc/init.d/mongod:
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
That’s it!