redis啟動失敗


 

redis.conf 設置的daemonize yes后台運行,使用redis-server redis.conf之后沒有任何反應,以為啟動成功

使用 ps -ef|grep redis 查看redis進程發現沒有,修改redis.conf配置中的logfile的值,打印日志例如: logfile  "/usr/local/redis/log/redis.log"

再次使用redis-server redis.conf命令啟動redis,之后再從/usr/local/redis/log/redis.log   redis的日志文件中查看日志信息:

24120:M 29 Mar 09:59:05.556 * Increased maximum number of open files to 10032 (it was originally set to 1024).
  ...

24120:M 29 Mar 09:59:22.368 # Server started, Redis version 3.2.9
24120:M 29 Mar 09:59:22.368 # 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.
24120:M 29 Mar 09:59:22.388 # 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.
24120:M 29 Mar 09:59:22.388 # Bad file format reading the append only file: make a backup of your AOF file, then use ./redis-check-aof --fix <filename>

根據上面warning提示信息進行處理:

echo 1 > /proc/sys/vm/overcommit_memory

echo "vm.overcommit_memory=1" >> /etc/sysctl.conf

echo never > /sys/kernel/mm/transparent_hugepage/enabled

./redis-check-aof --fix <filename>

之后重新啟動  redis-server redis.conf成功

解釋:

overcommit_memory參數說明: 設置內存分配策略(可選,根據服務器的實際情況進行設置) /proc/sys/vm/overcommit_memory 可選值:0、1、2。 0, 表示內核將檢查是否有足夠的可用內存供應用進程使用;如果有足夠的可用內存,內存申請允許;否則,內存申請失敗,並把錯誤返回給應用進程。 1, 表示內核允許分配所有的物理內存,而不管當前的內存狀態如何。 2, 表示內核允許分配超過所有物理內存和交換空間總和的內存

redis在dump數據的時候,會fork出一個子進程,理論上child進程所占用的內存和parent是一樣的,比如parent占用的內存為8G,這個時候也要同樣分配8G的內存給child,如果內存無法負擔,往往會造成redis服務器的down機或者IO負載過高,效率下降。所以這里比較優化的內存分配策略應該設置為 1(表示內核允許分配所有的物理內存,而不管當前的內存狀態如何)。

echo是一種最常用的與廣泛使用的內置於Linux的bash和C shell的命令,通常用在腳本語言和批處理文件中來在標准輸出或者文件中顯示一行文本或者字符串。

echo可以使用重定向符來輸出到一個文件而不是標准輸

   $  echo  "Test" > test

參考:http://www.jbxue.com/LINUXjishu/5303.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM