情景描述
我在CentOS 7.2中安裝完redis胸囱,初次啟動(dòng)時(shí)出現(xiàn)了三個(gè)警告:
第一個(gè)警告:The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
第二個(gè)警告: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.
第三個(gè)警告:you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix thisissue 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 thesetting after a reboot. Redis must be restarted after THP is disabled.
解決方案
考慮到redis一般都是部署在服務(wù)器上作為服務(wù)存在的雾袱。所以,本文的解決方案都是持久性配置,不是臨時(shí)配置步脓。
第一個(gè)警告
將net.core.somaxconn = 1024
添加到/etc/sysctl.conf
中堡僻,然后執(zhí)行sysctl -p
生效配置。
第二個(gè)警告
將vm.overcommit_memory = 1
添加到/etc/sysctl.conf
中实撒,然后執(zhí)行sysctl -p
生效配置姊途。
第三個(gè)警告
將echo never > /sys/kernel/mm/transparent_hugepage/enabled
添加到/etc/rc.local
中,然后執(zhí)行source /etc/rc.local
生效配置知态。
總結(jié)
redis想的挺周全的捷兰,其實(shí)解決方案已經(jīng)寫(xiě)在警告里了,除了第一個(gè)警告的解決方案稍作了一些修改外负敏,其他警告的解決方案其實(shí)只是對(duì)redis的提示做了一個(gè)精簡(jiǎn)贡茅。