解决EC2上Ubuntu 16.04的overcommit_memory和透明大页面上的Redis警告

leg*_*gel 7 ubuntu amazon-ec2 redis sysctl huge-pages

在新的Ubuntu 16.04 EC2实例上,警告如下所示:

WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
Run Code Online (Sandbox Code Playgroud)

如何永久消除它们?

leg*_*gel 6

如警告所示,只需将行添加vm.overcommit_memory=1到的底部即可/etc/sysctl.conf,例如sudo vi /etc/sysctl.conf

但是,权限不允许您按照警告的提示来编辑THP,而是这样做

sudo apt install hugepages
Run Code Online (Sandbox Code Playgroud)

并将命令添加sudo hugeadm --thp-never到.bashrc的底部,类似sudo vi ~/.bashrc

然后sudo reboot,下一次您运行SSH时redis-server,警告消失了!

  • 仅仅是使警告消失就根本危险吗?什么时候需要在内存不足的情况下“后台保存”失败?盲目地设置'vm.overcommit_memory = 1'会不会有问题? (3认同)
  • 如何在Docker容器中做到这一点? (2认同)