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

Solving Redis warnings on overcommit_memory and Transparent Huge Pages for Ubuntu 16.04 on EC2

在新的 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.

如何永久消除它们?

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

的内容

但是权限不允许您按照警告建议的那样编辑 THP,所以

sudo apt install hugepages

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

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

使用 Linux 和 Ubuntu,我在 运行 redis-server 之前这样做过,它似乎有效...

sudo add-apt-repository ppa:redislabs/redis
sudo apt-get update
sudo apt-get install redis

https://redis.io/download