操作更新安装了ubuntu20.04,结果由于内核启用了THB,导致redis无法启动,提示错误:
ARNING 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.
按照这个错误信息来更正,仅适用于ubuntu 14及以下,更新版本的无法通过rc.local来启动后关闭THP,在网上找到更简单的办法:
新建一个服务:
vi /etc/systemd/system/disable-thp.service
添加内容:
[Unit]
Description=Disable Transparent Huge Pages (THP)
[Service]
Type=simple
ExecStart=/bin/sh -c "echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled && echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag"
[Install]
WantedBy=multi-user.target
开启系统服务及开机自启动
systemctl daemon-reload
systemctl start disable-thp
systemctl enable disable-thp
成功后会输入结果:
Created symlink /etc/systemd/system/multi-user.target.wants/disable-thp.service → /etc/systemd/system/disable-thp.service.
重启即可。
参考网址:https://www.stephenrlang.com/2018/01/disabling-transparent-huge-pages-in-linux/