解決redis啟動的警告日志問題
redis啟動時,出現警告日志
原因是redis緩存的數據過多,沒有提前做好數據過期策略,導致超過物理機的實際內存。
需要修改計算機內存策略

(1)警告描述,不能設置tcp的堆積為511
因為/proc/sys/net/core/somaxconn的值為128太低。
報錯:
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為linux的內核參數,即linux每端扣可以監(jiān)聽的最大tcp數量。
解決方案:
修改linux系統參數,在里面增加net.core.somaxconn配置,注意:直接修改/proc/sys/net/core/somaxconn內,系統重啟后會還原。
永久解決:vim /etc/sysctl.conf
net.ipv4.conf.default.accept_source_route = 1
立即生效:sysctl -p
(2)一臺機器如果內存用完,在進行bgsave時,可能會報錯
錯誤信息大概如下:
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.
分析:
當執(zhí)行redis的bgsave命令時,redis會fork一個進程把redis中的內存數據寫入磁盤。
這樣的好處是,copy on write,有效的節(jié)省了內存占用。
但是,bgsave時,如果有數據變更,一樣需要申請內存。
當申請內存時,如果發(fā)現內存不夠,可能就會報上面的錯誤

vim /etc/sysctl.conf
net.core.somaxconn= 1024 sysctl vm.overcommit_memory=1 vm.overcommit_memory = 1
立即生效:sysctl -p
(3)使用的是透明大頁,可能導致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.
臨時解決方法:
echo never > /sys/kernel/mm/transparent_hugepage/enabled
永久解決方法:
將其寫入/etc/rc.local文件中
if test -f /sys/kernel/mm/redhat_transparent_hugepage/enabled; then echo never > /sys/kernel/mm/redhat_transparent_hugepage/enabled fi
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Redis+Caffeine實現分布式二級緩存組件實戰(zhàn)教程
這篇文章主要介紹了Redis+Caffeine實現分布式二級緩存組件實戰(zhàn)教程,介紹了分布式二級緩存的優(yōu)勢,使用組件的方法,通過示例代碼給大家介紹的非常詳細,需要的朋友可以參考下2022-08-08
銀河麒麟V10sp1服務器系統安裝redis不能使用的快速解決辦法
這篇文章主要介紹了銀河麒麟V10sp1服務器系統安裝redis不能使用的快速解決辦法,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-01-01

