如果我使用命令运行redis:alpine Docker镜像
docker run redis:alpine
Run Code Online (Sandbox Code Playgroud)
我看到几个警告:
1:C 08 May 08:29:32.308 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.2.8 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 1
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
1:M 08 May 08:29:32.311 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 08 May 08:29:32.311 # Server started, Redis version 3.2.8
1:M 08 May 08:29:32.311 # 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.
1:M 08 May 08:29:32.311 # 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.
1:M 08 May 08:29:32.311 * The server is now ready to accept connections on port 6379
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下方法修复前两个警告Dockerfile:
FROM redis:alpine
COPY somaxconn /proc/sys/net/core/somaxconn
COPY sysctl.conf /etc/sysctl.conf
CMD ["redis-server", "--appendonly", "yes"]
Run Code Online (Sandbox Code Playgroud)
我的本地文件somaxconn包含单个条目511并sysctl.conf包含该行vm.overcommit_memory = 1.但是,当我构建和运行容器时,我仍然会收到相同的警告.
我怎样才能摆脱这些警告?(在https://www.techandme.se/performance-tips-for-redis-cache-server/中提到了这些问题,但其中描述的解决方案涉及修改rc.local,似乎与Rasperry Pi有关).
ova*_*nes 11
处理事情的方法不好:/proc是只读文件系统来修改它你可以在特权模式下运行Docker,而不是在容器启动后修改它.
如果以特权模式运行容器,则可以使用以下命令禁用THP:
# echo never > /sys/kernel/mm/transparent_hugepage/enabled
# echo never > /sys/kernel/mm/transparent_hugepage/defrag
Run Code Online (Sandbox Code Playgroud)
正确的方法:确保您运行较新版本的Docker(如果需要,可以升级).run子命令具有--sysctl选项:
$ docker run -ti --sysctl net.core.somaxconn=4096 --rm redis:alpine /bin/sh
root@9e850908ddb7:/# sysctl net.core.somaxconn
net.core.somaxconn = 4096
...
Run Code Online (Sandbox Code Playgroud)
不幸的是:vm.overcommit_memory目前不允许通过--sysctl参数设置同样适用于THP(transparent_hugepage),这是因为它们不是命名空间.因此,要在Linux主机上运行的容器中修复这些警告,您可以直接在主机上更改它们.这里有相关问题:
如果这样做,您不需要特权模式.
| 归档时间: |
|
| 查看次数: |
7475 次 |
| 最近记录: |