解决redis启动时的警告
如果我們什么都不修改,redis啟動(dòng)時(shí)會(huì)有三個(gè)警告
警告1 :?WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128
解釋:上面寫的很清晰,意思是配置 /proc/sys/net/core/somaxconn的值是128,雖然redis.conf中配置的是511,但是linux內(nèi)核會(huì)以無(wú)提示的方式將其截?cái)酁?28。在一個(gè)高并發(fā)的環(huán)境下,128是遠(yuǎn)遠(yuǎn)不夠的,所以我們要改大一些
辦法:將net.core.somaxconn = 1024添加到/etc/sysctl.conf中,然后執(zhí)行sysctl -p?生效配置,如下圖
警告2: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
解釋:overcommit_memory?表內(nèi)存分配策略,可選值:0、1、2
0, 表示內(nèi)核將檢查是否有足夠的可用內(nèi)存供應(yīng)用進(jìn)程使用;如果有足夠的可用內(nèi)存,內(nèi)存申請(qǐng)?jiān)试S;否則,內(nèi)存申請(qǐng)失敗,并把錯(cuò)誤返回給應(yīng)用進(jìn)程。
1, 表示內(nèi)核允許分配所有的物理內(nèi)存,而不管當(dāng)前的內(nèi)存狀態(tài)如何。
2, 表示內(nèi)核允許分配超過(guò)所有物理內(nèi)存和交換空間總和的內(nèi)存
辦法:將vm.overcommit_memory = 1添加到/etc/sysctl.conf中,然后執(zhí)行sysctl -p生效配置,如下圖(由于剛執(zhí)行了第一個(gè)警告的修復(fù),所以兩條命令都有)
警告3: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
解釋:THP(透明大頁(yè))的知識(shí)請(qǐng)參考這篇博客?https://www.cnblogs.com/kerrycode/p/4670931.html
redis建議我們關(guān)掉THP,還給出的具體的操作辦法,注意必須使用root來(lái)操作,否則會(huì)失敗的
辦法:執(zhí)行命令?echo never > /sys/kernel/mm/transparent_hugepage/enabled
?? ? ? ? ? ?并把命令?echo never > /sys/kernel/mm/transparent_hugepage/enabled 寫入到?/etc/rc.local 中
? ? ? ? ? ? 執(zhí)行命令?source /etc/rc.local
全部修復(fù)后,啟動(dòng)redis,已經(jīng)不報(bào)任何警告了,如下圖
總結(jié)
以上是生活随笔為你收集整理的解决redis启动时的警告的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: linux 使用 cp 命令强制覆盖功能
- 下一篇: go 打印 %v %+v %#v 的区别