我想在gke中运行redis图像.它工作,除了我得到可怕的"透明巨大的页面"警告:
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.
Redis目前太慢而无法使用......所以我关掉了THP:
sheena@gke-projectwaxd-cluster-default-pool-23593a74-wxrv ~ $ cat /sys/kernel/mm/transparent_hugepage/enabled always [madvise] never sheena@gke-projectwaxd-cluster-default-pool-23593a74-wxrv ~ $ echo never > /sys/kernel/mm/transparent_hugepage/enabled -bash: /sys/kernel/mm/transparent_hugepage/enabled: Permission denied sheena@gke-projectwaxd-cluster-default-pool-23593a74-wxrv ~ $ sudo echo never > /sys/kernel/mm/transparent_hugepage/enabled -bash: /sys/kernel/mm/transparent_hugepage/enabled: Permission denied
这些权限错误令人不安.Redis希望THP关闭,以便它可以正常工作.
我做了一点挖掘,发现谷歌使用了一个特殊的操作系统映像,它使/ sys /成为只读路径.有一个基于Debian 7的替代图像.它让我很兴奋,但最终我有完全相同的问题.
那么如何阻止redis受到Google容器引擎上THP的影响呢?
这不像我在这里做一些独特的事情.在容器中运行数据库是很正常的.当THP启用时,数据库出现故障是很正常的.那么......我在这里错过了什么?
您的命令略有不正确:echo
以root身份运行但重定向本身(>
)以用户身份运行,因此无法写入/sys/
.
下面的命令正常工作都在容器-VM(基于Debian)和GCI(基于ChromeOS的):
sudo sh -c 'echo never > /sys/kernel/mm/transparent_hugepage/enabled'
将此内核命令行参数添加到/etc/default/grub
(不要忘记运行sudo update-grub
及sudo reboot
之后):
GRUB_CMDLINE_LINUX="... transparent_hugepage=never"
首先,使用云控制台复制节点池正在使用的实例模板.
其次,在元数据下更改userdata的值:
#cloud-config write_files: - path: /etc/systemd/system/hugepage.service permissions: 0644 owner: root content: | [Unit] Description=Disable THP [Service] Type=oneshot ExecStart=/bin/sh -c "echo never > /sys/kernel/mm/transparent_hugepage/enabled" [Install] WantedBy=kubernetes.target ... runcmd: - ... - systemctl enable hugepage.service - systemctl start kubernetes.target
第三,将实例模板更改为新创建的模板:
gcloud compute instance-groups managed set-instance-template \ gke-YOUCLUSTER-YOURPOOL-grp \ --template=YOURNEWTEMPLATENAME \ --zone=...
第四,重新创建实例:
gcloud compute instance-groups managed recreate-instances \ gke-YOUCLUSTER-YOURPOOL-grp \ --zone=... \ --instances=...
实例将丢失所有数据并禁用THP.所有新实例也将禁用THP(在此节点池中).