Blog Entry
记一次Redis错误
记一次Redis错误
- Created
- 2024/04/10
- Updated
- 2024/04/10
报错
在客户端连接时,出现:
Client On Error: Error: write ECONNABORTED Config right?docker
docker compose
redis: image: redis:6.2.7 restart: always hostname: redis container_name: mlcache-redis privileged: true ports: - "6399:6379" environment: - TZ=Asia/Shanghai volumes: - ./data/redis/data:/data - ./data/redis/logs:/logs# - ./data/redis/redis.conf:/etc/redis/redis.conf - ../redis/redis.conf:/etc/redis/redis.conf command: ["redis-server","/etc/redis/redis.conf"]# command: ["redis-server"]redis.conf
默认配置, 去redis/redis根目录下找redis.conf,最好是找对应版本的tag
尝试
尝试一
不使用配置启动,连接正常,即:
redis: image: redis:6.2.7 restart: always hostname: redis container_name: mlcache-redis privileged: true ports: - "6399:6379" environment: - TZ=Asia/Shanghai volumes: - ./data/redis/data:/data - ./data/redis/logs:/logs# - ./data/redis/redis.conf:/etc/redis/redis.conf# - ../redis/redis.conf:/etc/redis/redis.conf# command: ["redis-server","/etc/redis/redis.conf"] command: ["redis-server"]所以大致认为配置有问题
尝试二
重新启用配置
redis: image: redis:6.2.7 restart: always hostname: redis container_name: mlcache-redis privileged: true ports: - "6399:6379" environment: - TZ=Asia/Shanghai volumes: - ./data/redis/data:/data - ./data/redis/logs:/logs - ../redis/redis.conf:/etc/redis/redis.conf command: ["redis-server","/etc/redis/redis.conf"]看下日志: (docker logs $container_id)
2024-04-10 16:57:55 1:C 10 Apr 2024 16:57:55.529 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo2024-04-10 16:57:55 1:C 10 Apr 2024 16:57:55.529 # Redis version=6.2.7, bits=64, commit=00000000, modified=0, pid=1, just started2024-04-10 16:57:55 1:C 10 Apr 2024 16:57:55.529 # Configuration loaded2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.530 * monotonic clock: POSIX clock_gettime2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.530 # Warning: Could not create server TCP listening socket ::1:6379: bind: Cannot assign requested address2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.530 # A key '__redis__compare_helper' was added to Lua globals which is not on the globals allow list nor listed on the deny list.2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.530 * Running mode=standalone, port=6379.2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.530 # Server initialized2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.530 # 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.2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.533 * Loading RDB produced by version 6.2.72024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.533 * RDB age 35 seconds2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.533 * RDB memory usage when created 0.87 Mb2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.533 # Done loading RDB, keys loaded: 0, keys expired: 0.2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.534 * DB loaded from disk: 0.003 seconds2024-04-10 16:57:55 1:M 10 Apr 2024 16:57:55.534 * Ready to accept connections其中有个警告: Warning: Could not create server TCP listening socket ::1:6379: bind: Cannot assign requested address, 绑定端口失败
到redis.conf中,找到bind相关的一段:
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the# internet, binding to all the interfaces is dangerous and will expose the# instance to everybody on the internet. So by default we uncomment the# following bind directive, that will force Redis to listen only on the# IPv4 and IPv6 (if available) loopback interface addresses (this means Redis# will only be able to accept client connections from the same host that it is# running on).## IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES# JUST COMMENT OUT THE FOLLOWING LINE.# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~bind 127.0.0.1 -::1把bind这行注释掉
尝试三
重新启动容器,看日志:
2024-04-10 17:02:40 1:C 10 Apr 2024 17:02:40.645 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo2024-04-10 17:02:40 1:C 10 Apr 2024 17:02:40.645 # Redis version=6.2.7, bits=64, commit=00000000, modified=0, pid=1, just started2024-04-10 17:02:40 1:C 10 Apr 2024 17:02:40.645 # Configuration loaded2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.645 * monotonic clock: POSIX clock_gettime2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.645 # A key '__redis__compare_helper' was added to Lua globals which is not on the globals allow list nor listed on the deny list.2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.645 * Running mode=standalone, port=6379.2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.646 # Server initialized2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.646 # 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.2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.647 * Loading RDB produced by version 6.2.72024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.647 * RDB age 89 seconds2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.647 * RDB memory usage when created 0.77 Mb2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.647 # Done loading RDB, keys loaded: 0, keys expired: 0.2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.647 * DB loaded from disk: 0.001 seconds2024-04-10 17:02:40 1:M 10 Apr 2024 17:02:40.647 * Ready to accept connections有个警告: overcommit_memory is set to 0!
把尝试二中的bind部分修改为
bind 0.0.0.0overcommit_memory is set to 0!这个问题就没有了