docker - 如何在Windows 10上修复 “Redis must be restarted after THP is disabled”警告?

标签 docker redis docker-compose windows-10 dockerfile

我有一个docker-compose.yml文件。运行此命令时,出现警告“禁用THP后必须重新启动Redis”。

以下是我的docker-compose.yml:

version: '3'
services:
  myapp:
    # container_name: myapp
    restart: always
    build: .
    ports:
      - '52000:52000'
      # - '8080:8080'
    #   - '4300:4300'
    #   - '4301:4301'
    command: ["./wait-for-it.sh", "redis:6379", "--", "npm", "start"]
    links:
      - redis
      - mongo
  mongo:
    # container_name: myapp-mongo
    image: 'mongo:latest'
    ports:
      - '28107:28107'
      # - '27017:27017'
  redis:
    # container_name: myapp-redis
    # restart: always
    image: 'redis:4.0.11'
    # command: ["redis-server", "--appendonly", "yes"]
    ports:
      - '6379:6379'

以下是我的日志:
redis_1  | 1:C 24 Sep 10:21:09.224 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1  | 1:C 24 Sep 10:21:09.236 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1  | 1:C 24 Sep 10:21:09.236 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1  | 1:M 24 Sep 10:21:09.239 * Running mode=standalone, port=6379.
redis_1  | 1:M 24 Sep 10:21:09.239 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1  | 1:M 24 Sep 10:21:09.239 # Server initialized
mongo_1  | 2019-09-24T10:21:10.304+0000 I  CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
redis_1  | 1:M 24 Sep 10:21:09.239 # 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.
redis_1  | 1:M 24 Sep 10:21:09.239 * Ready to accept connections

最佳答案

# 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.



从错误中,您可以在Docker主机上使用'echo never > /sys/kernel/mm/transparent_hugepage/enabled'修复您的问题。

但是,我知道您在Windows上并且无法访问hyper-v MobyLinuxVM,因此您应该在下一步中使用解决方法:

docker-compose.yaml:
version: '3'
services:
  redis:
    image: 'redis:4.0.11'
    ports:
      - '6379:6379'
    depends_on:
      - helper
    sysctls:
      - net.core.somaxconn=511
  helper:
    image: alpine
    command: sh -c "echo never > /sys/kernel/mm/transparent_hugepage/enabled"
    privileged: true

上面将首先启动一个辅助容器,该容器将never设置为/sys/kernel/mm/transparent_hugepage/enabled,因为所有容器将共享相同的主机内核,因此稍后启动的redis容器也将从中受益,请参见下一个执行日志:
PS E:\abc> docker-compose up
Starting abc_helper_1 ... done
Recreating 29ea8bfaeafc_abc_redis_1 ... done
Attaching to abc_helper_1, abc_redis_1
redis_1   | 1:C 25 Sep 15:38:17.822 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1   | 1:C 25 Sep 15:38:17.822 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1   | 1:C 25 Sep 15:38:17.822 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1   | 1:M 25 Sep 15:38:17.822 * Running mode=standalone, port=6379.
redis_1   | 1:M 25 Sep 15:38:17.823 # Server initialized
redis_1   | 1:M 25 Sep 15:38:17.823 * DB loaded from disk: 0.000 seconds
redis_1   | 1:M 25 Sep 15:38:17.823 * Ready to accept connections

关于docker - 如何在Windows 10上修复 “Redis must be restarted after THP is disabled”警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58078237/

相关文章:

postgresql - 重新创建容器后如何让 PostgresQL 使用 .env 文件中的环境变量(不删除卷)

php - Symfony 和 Docker - 缓存和日志目录权限

docker - 在 Docker 构建过程中从主机复制文件以最小化图像大小

macos - 如何在一台非常老的 Mac 上安装和运行 Docker Desktop 和 DDEV?

javascript - Node.js:Redis 安全说明

ruby-on-rails - 使用 Sidekiq 发送电子邮件时是否可以不使用 Redis?

windows -/var/run/docker.sock 如何适用于 Windows Docker?

docker - 找不到quay.io/etcd容器命令

docker 私有(private)注册表用户创建

Redis概念: In memory or DB?