redis 2
yml
version: "3.9"
services:
redis:
image: redis:7.2
container_name: redis-prod
command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
volumes:
- ./redis.conf:/usr/local/etc/redis/redis.conf
- redis-data:/data
ports:
- "127.0.0.1:6379:6379"
restart: unless-stopped
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 3s
retries: 3
volumes:
redis-data:等实践
打开持久化
conf
save 900 1
save 300 10
save 60 10000
appendonly yes
appendfsync everysec显式限制内存(非常重要)
conf
maxmemory 2gb
maxmemory-policy allkeys-lru设置密码
conf
requirepass strong_passwordredis 6 设置密码方式不一样
备份
方式很多
- 定期拷贝 dump.rdb
- 备份 appendonly.aof(恢复时间稍长,但更安全)
- 定时任务 + redis-cli save
- 使用 主从复制 + 备份从库