本站支持搜索的镜像仓库:Docker Hub、gcr.io、ghcr.io、quay.io、k8s.gcr.io、registry.gcr.io、elastic.co、mcr.microsoft.com

Redis Sentinel 是 Redis 官方提供的高可用解决方案,用于监控 Redis 主从架构中的节点状态,实现自动故障检测、故障转移及配置管理。本镜像基于官方 Redis 镜像构建,封装了 Sentinel 组件,可快速部署至容器环境,为 Redis 集群提供高可用保障。
docker run -d \ --name redis-sentinel \ -p 26379:26379 \ -v /path/to/sentinel.conf:/etc/redis/sentinel.conf \ redis:alpine \ redis-sentinel /etc/redis/sentinel.conf
说明:需提前准备
sentinel.conf配置文件(见 4.4 配置参数),并通过-v挂载至容器内。
# 节点 1 docker run -d \ --name redis-sentinel-1 \ -p 26379:26379 \ -v /path/to/sentinel-1.conf:/etc/redis/sentinel.conf \ --network redis-net \ redis:alpine redis-sentinel /etc/redis/sentinel.conf # 节点 2(端口映射 26380,避免宿主机端口冲突) docker run -d \ --name redis-sentinel-2 \ -p 26380:26379 \ -v /path/to/sentinel-2.conf:/etc/redis/sentinel.conf \ --network redis-net \ redis:alpine redis-sentinel /etc/redis/sentinel.conf # 节点 3(端口映射 26381) docker run -d \ --name redis-sentinel-3 \ -p 26381:26379 \ -v /path/to/sentinel-3.conf:/etc/redis/sentinel.conf \ --network redis-net \ redis:alpine redis-sentinel /etc/redis/sentinel.conf
说明:需创建自定义网络
redis-net(docker network create redis-net),确保 Sentinel 与 Redis 节点在同一网络。
以下示例包含 1 主、2 从、3 Sentinel 节点的完整架构:
version: '3' networks: redis-net: driver: bridge services: # Redis 主节点 redis-master: image: redis:alpine container_name: redis-master ports: - "6379:6379" networks: - redis-net command: redis-server --appendonly yes # 开启 AOF 持久化 # Redis 从节点 1 redis-slave-1: image: redis:alpine container_name: redis-slave-1 ports: - "6380:6379" networks: - redis-net command: redis-server --slaveof redis-master 6379 # 指向主节点 # Redis 从节点 2 redis-slave-2: image: redis:alpine container_name: redis-slave-2 ports: - "6381:6379" networks: - redis-net command: redis-server --slaveof redis-master 6379 # 指向主节点 # Sentinel 节点 1 sentinel-1: image: redis:alpine container_name: sentinel-1 ports: - "26379:26379" networks: - redis-net volumes: - ./sentinel-1.conf:/etc/redis/sentinel.conf command: redis-sentinel /etc/redis/sentinel.conf # Sentinel 节点 2 sentinel-2: image: redis:alpine container_name: sentinel-2 ports: - "26380:26379" networks: - redis-net volumes: - ./sentinel-2.conf:/etc/redis/sentinel.conf command: redis-sentinel /etc/redis/sentinel.conf # Sentinel 节点 3 sentinel-3: image: redis:alpine container_name: sentinel-3 ports: - "26381:26379" networks: - redis-net volumes: - ./sentinel-3.conf:/etc/redis/sentinel.conf command: redis-sentinel /etc/redis/sentinel.conf
注:所有 Sentinel 配置文件(sentinel-1.conf、sentinel-2.conf、sentinel-3.conf)需包含相同的监控配置(见 4.4 配置参数)。
Sentinel 配置通过 sentinel.conf 文件定义,核心参数如下:
| 参数名 | 格式 | 说明 | 默认值 |
|---|---|---|---|
sentinel monitor <master-name> <ip> <port> <quorum> | 必选 | 监控的主节点名称、IP、端口及“仲裁数”(判断主节点不可用的最小 Sentinel 数量) | - |
sentinel down-after-milliseconds <master-name> <ms> | 可选 | 主节点无响应的超时时间(毫秒),超时则标记为“主观下线” | 30000(30秒) |
sentinel parallel-syncs <master-name> <num> | 可选 | 故障转移后,同时向新主节点同步数据的从节点数量(越小越慢,冲突越少) | 1 |
sentinel failover-timeout <master-name> <ms> | 可选 | 故障转移超时时间(毫秒),超时则重试 | 180000(3分钟) |
sentinel notification-script <master-name> <path> | 可选 | 节点状态变化时触发的通知脚本路径(如告警脚本) | - |
sentinel client-reconfig-script <master-name> <path> | 可选 | 故障转移后触发的客户端重配置脚本路径 | - |
示例配置文件(sentinel.conf):
# 监控名为 "mymaster" 的主节点(IP:redis-master,端口:6379,仲裁数:2) sentinel monitor mymaster redis-master 6379 2 # 主节点无响应 10 秒后标记为下线 sentinel down-after-milliseconds mymaster 10000 # 故障转移时允许 1 个从节点同时同步 sentinel parallel-syncs mymaster 1 # 故障转移超时时间 2 分钟 sentinel failover-timeout mymaster 120000
为简化配置,可通过环境变量动态注入 Sentinel 参数(无需手动编写 sentinel.conf),常用变量如下:
| 环境变量 | 对应配置参数 | 说明 |
|---|---|---|
SENTINEL_MONITOR_NAME | sentinel monitor <name> | 主节点名称(如 mymaster) |
REDIS_MASTER_HOST | sentinel monitor <ip> | 主节点 IP/主机名 |
REDIS_MASTER_PORT | sentinel monitor <port> | 主节点端口(默认 6379) |
SENTINEL_QUORUM | sentinel monitor <quorum> | 仲裁数(默认 2) |
SENTINEL_DOWN_AFTER | sentinel down-after-milliseconds | 超时时间(毫秒,默认 30000) |
SENTINEL_PARALLEL_SYNCS | sentinel parallel-syncs | 同步从节点数量(默认 1) |
SENTINEL_FAILOVER_TIMEOUT | sentinel failover-timeout | 故障转移超时(毫秒,默认 180000) |
使用环境变量的 Docker Run 示例:
docker run -d \ --name redis-sentinel \ -p 26379:26379 \ --network redis-net \ -e SENTINEL_MONITOR_NAME=mymaster \ -e REDIS_MASTER_HOST=redis-master \ -e REDIS_MASTER_PORT=6379 \ -e SENTINEL_QUORUM=2 \ -e SENTINEL_DOWN_AFTER=10000 \ redis:alpine \ redis-sentinel --sentinel
客户端需通过 Sentinel 获取当前主节点地址,而非直接连接主节点。以 Redis CLI 为例:
# 连接 Sentinel(端口 26379) redis-cli -h 127.0.0.1 -p 26379 # 获取主节点信息 sentinel get-master-addr-by-name mymaster # 输出示例:1) "redis-master" 2) "6379"(故障转移后将返回新主节点地址)
主流 Redis 客户端(如 Jedis、Lettuce)均内置 Sentinel 支持,配置示例(Java Jedis):
Set<String> sentinelSet = new HashSet<>(); sentinelSet.add("127.0.0.1:26379"); sentinelSet.add("127.0.0.1:26380"); sentinelSet.add("127.0.0.1:26381"); JedisSentinelPool pool = new JedisSentinelPool("mymaster", sentinelSet); Jedis jedis = pool.getResource();
免费版仅支持 Docker Hub 加速,不承诺可用性和速度;专业版支持更多镜像源,保证可用性和稳定速度,提供优先客服响应。
免费版仅支持 docker.io;专业版支持 docker.io、gcr.io、ghcr.io、registry.k8s.io、nvcr.io、quay.io、mcr.microsoft.com、docker.elastic.co 等。
当返回 402 Payment Required 错误时,表示流量已耗尽,需要充值流量包以恢复服务。
通常由 Docker 版本过低导致,需要升级到 20.x 或更高版本以支持 V2 协议。
先检查 Docker 版本,版本过低则升级;版本正常则验证镜像信息是否正确。
使用 docker tag 命令为镜像打上新标签,去掉域名前缀,使镜像名称更简洁。
探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录方式配置轩辕镜像加速服务,包含7个详细步骤
在 Linux 系统上配置轩辕镜像源,支持主流发行版
在 Docker Desktop 中配置轩辕镜像加速,适用于桌面系统
在 Docker Compose 中使用轩辕镜像加速,支持容器编排
在 k8s 中配置 containerd 使用轩辕镜像加速
在宝塔面板中配置轩辕镜像加速,提升服务器管理效率
在 Synology 群晖NAS系统中配置轩辕镜像加速
在飞牛fnOS系统中配置轩辕镜像加速
在极空间NAS中配置轩辕镜像加速
在爱快ikuai系统中配置轩辕镜像加速
在绿联NAS系统中配置轩辕镜像加速
在威联通NAS系统中配置轩辕镜像加速
在 Podman 中配置轩辕镜像加速,支持多系统
配置轩辕镜像加速9大主流镜像仓库,包含详细配置步骤
无需登录即可使用轩辕镜像加速服务,更加便捷高效
需要其他帮助?请查看我们的 常见问题 或 官方QQ群: 13763429