废柴阿尤6个月前更新关注私信 一、问题描述 在Docker部署Redis时提示 root@chaopower-master:~# docker logs redis-server 1:C 07 Apr 2024 01:23:49.191 # WARNING Your kernel has a bug that could lead to data corruption during background save. Please upgrade to the latest stable kernel. 1:C 07 Apr 2024 01:23:49.191 # Redis will now exit to prevent data corruption. Note that it is possible to suppress this warning by setting the following config: ignore-warnings ARM64-COW-BUG 我本想将内核版本升级或者降级试试,但是由于是生产环境,上面跑着好多公司业务所以不能盲目动内核,但是这个docker部署的redis只是用来做测试用,所以这个问题也就很好解决! 二、解决方式 解决方式很简单,日志已经提醒需要在redis.config中添加配置 ignore-warnings ARM64-COW-BUG 但是,容器都没启动成功,根本没法获取容器中的redis.conf文件。 因此,需要先在宿主机上配置好redis.conf,再映射进容器中 1、下载对应版本redis.conf文件 我们需要在redis官网找到对应redis版本的配置文件 redis官网:https://redis.io/docs/management/config/ 如果在拉取镜像时用的是latest版本可以用以下命令查看Redis版本 root@chaopower-master:~# docker image inspect redis:latest | grep -i "version" "DockerVersion": "", "GOSU_VERSION=1.17", "REDIS_VERSION=7.2.3", root@chaopower-master:~# 2、更改redis.conf文件 root@chaopower-master:~# sed -i '$a\ignore-warnings ARM64-COW-BUG' /data/redis_7.2/conf/redis.conf root@chaopower-master:~# egrep "^ignore-warnings" /data/redis_7.2/conf/redis.conf ignore-warnings ARM64-COW-BUG 如果需要开启redis持久化请用以下命令修改redis配置文件 root@chaopower-master:~# sed -i 's/^appendonly no$/appendonly yes/' /data/redis_7.2/conf/redis.conf root@chaopower-master:~# grep "appendonly yes" /data/redis_7.2/conf/redis.conf 3、启动redis容器 root@chaopower-master:~# docker run -itd --restart=always --name test-redis1 -v /data/redis_7.2/conf/redis.conf:/usr/local/etc/redis/redis.conf -v /data/redis_7.2/data/:/data -p 16379:6379 redis:latest redis-server /usr/local/etc/redis/redis.conf root@chaopower-master:~# docker logs test-redis1 1:C 07 Apr 2024 02:32:04.502 # WARNING Your kernel has a bug that could lead to data corruption during background save. Pleaseernel. 1:C 07 Apr 2024 02:32:04.502 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 1:C 07 Apr 2024 02:32:04.502 * Redis version=7.2.3, bits=64, commit=00000000, modified=0, pid=1, just started 1:C 07 Apr 2024 02:32:04.502 * Configuration loaded 1:M 07 Apr 2024 02:32:04.503 * monotonic clock: POSIX clock_gettime 1:M 07 Apr 2024 02:32:04.503 # Failed to write PID file: Permission denied _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 7.2.3 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 1 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | https://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 1:M 07 Apr 2024 02:32:04.503 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn28. 1:M 07 Apr 2024 02:32:04.504 # Warning: Could not create server TCP listening socket ::1:6379: bind: Cannot assign requested a 1:M 07 Apr 2024 02:32:04.504 * Server initialized 1:M 07 Apr 2024 02:32:04.507 * Creating AOF base file appendonly.aof.1.base.rdb on server start 1:M 07 Apr 2024 02:32:04.511 * Creating AOF incr file appendonly.aof.1.incr.aof on server start 1:M 07 Apr 2024 02:32:04.511 * Ready to accept connections tcp root@chaopower-master:~# cat >docker-compose-redis.yml<EOF version: '3.8' services: redis: image: redis:latest container_name: test-redis1 restart: always volumes: - /data/redis_7.2/conf/redis.conf:/usr/local/etc/redis/redis.conf - /data/redis_7.2/data/:/data ports: - "16379:6379" command: redis-server /usr/local/etc/redis/redis.conf # 使用该参数,container内的root拥有真正的root权限。 privileged: true EOF # 映射配置文件所在地址: -v /data/redis_7.2/conf/redis.conf:/usr/local/etc/redis/redis.conf# 映射redis数据保存地址:-v /data/redis_7.2/data/:/data# 使用配置文件:redis-server /usr/local/etc/redis/redis.conf # 映射6379端口:-p 16379:6379 如果在生成环境中建议和有关人员商议后将内核升级或者降级最为稳妥。 © 版权声明文章版权归作者所有,未经允许请勿转载。THE ENDRedis 喜欢就支持一下吧点赞5赞赏 分享QQ空间微博QQ好友海报分享复制链接收藏