dcoekr 啟動 redis 三個警告的解決辦法


1,警告的內容和大概意思

1,關於 TCP 連接數

  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
  2. 意思:大概就是 tcp 連接數設置為 128 太小了

2,關於 overcommit_memory 的值設置

  1. 內容: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
  2. 意思:大概是 overcommit_memory 的值設置為0時 在低內存條件下,后台保存可能會失敗

3,關於 THP 支持

  1. 內容: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
  2. 意思:大概是內核中啟用了透明大頁面(THP)支持。 這將導致Redis的延遲和內存使用問題

2,解決的方法

1,修改配置文件 vim /etc/sysctl.conf, 寫入下面兩個內容(注意是宿主機)

net.core.somaxconn=551   # 這里的數據根據生產的需要和電腦的性能進行調整 必須 大於等於 551
vm.overcommit_memory=1   

2,保存之后執行 sysctl -p 使得修改生效

3,修改配置文件 vim /etc/rc.local,寫入下面的內容

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

4,保存之后,賦予文件執行權限,並使得配置生效

chmod +x /etc/rc.local
source /etc/rc.local

3,重新啟動一個 docker 容器

1,筆者這邊采用 docker-compose 的方式啟動,docker-compose.yml 配置文件如下

version: '3.1'
services:

  master:
    image: redis
    container_name: redis
    ports:
      - 6379:6379
    volumes:
      - ./redis.conf:/etc/redis.conf
      - ./data:/data
    command: redis-server /etc/redis.conf

2,查看日志文件發現 后面的兩個警告都沒了,但是第一個警告還存在,我們進入 docker 容器查看原因

docker exec -it redis bash
cat /proc/sys/net/core/somaxconn 

3,我們發現容器的這個值還是 128,也就是說修改宿主機並沒有同步改變容器的這個值

4,由於 /proc/sys/net/core/somaxconn 這個文件是只讀的,筆者這邊選擇使用特權容器強行修改該值,修改 docker-compose.yml 如下

version: '3.1'
services:

  master:
    image: redis
    container_name: redis
    privileged: true  # 啟動特權模式
    ports:
      - 6379:6379
    volumes:
      - ./redis.conf:/etc/redis.conf
      - ./data:/data
    command:          # 多個命令同時執行
      - /bin/bash 
      - -c 
      - |                 
        echo 551 > /proc/sys/net/core/somaxconn
        redis-server /etc/redis.conf

5,刪除日志文件,重啟 docker 容器

docker-compose down
docker-compose up -d

6,我們在去看啟動之后的日志文件,沒有 waring,沒有 error,有強迫症的我感覺世界都清凈了


免責聲明!

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



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