凡品【FanPin】文档
首页文档中心关于我们
首页文档中心关于我们
  1. Redis
  • 概述
  • 笔记
    • ProxmoxVE
      • ProxmoxVE 8.4 常见问题
      • ProxmoxVE 9.0 常见问题
      • Ceph 相关
    • MySQL
      • MySQL
      • Git存储方式实现
    • Debian
      • Debian 12 常见问题
      • Debian 13 常见问题
    • Nginx
      • Nginx 调优
      • Nginx 安装
    • APISIX
      • APISIX部署
      • APISIX常见问题
    • Haproxy
      • Haproxy 3.2 本地
      • Haproxy 3.0.10-r1
      • Haproxy 3.2 公网
    • SD-WAN
      • Tinc
        • TINC常见问题
        • 虚拟局域网
      • Frrouting
        • Frrouting安装
      • Netmaker
        • Netmaker部署
    • iStoreOS
      • 安装部署
    • Redis
      • Redis集群
  • 文档
    • 接口规则
      • 基本规则
      • HTTP状态码
      • 签名
    • 网关相关
      • 路由与注册
      • 自动删除弃用接口
      • 分页数据
    • 平台相关
      • 文章相关
        • 分类列表
        • 分类详情
        • 文章列表
        • 文章详情
      • 基础信息
    • 其他接口
    • 工具类【Free】
      • 网络相关
        • 获取IP信息
        • Home入口
      • 图片相关
      • 文本相关
      • 游戏相关
  1. Redis

Redis集群


Redis Cluster Docker方式部署#

目录结构#

docker-compose.yml文件#

services:
  redis-cluster:
    image: redis:8
    container_name: redis-cluster
    networks:
      - baota_net
    volumes:
      - ./redis-data:/data
      - ./init.sh:/data/init.sh
    ports:
      - "7000-7005:7000-7005"       # 客户端端口
      - "17000-17005:17000-17005"   # Cluster bus端口
    command: bash /data/init.sh

  redisinsight:
    image: redis/redisinsight:latest
    container_name: redisinsight
    networks:
      - baota_net
    ports:
      - "8001:5540"   # 浏览器访问 http://宿主机IP:8001
    restart: unless-stopped

volumes:
  redis-data:
  redisinsight-data:

networks:
  baota_net:
    external: true

init.sh文件#

#!/bin/bash
REDIS_PASSWORD="ProdStrongPass123!"

# 创建 Redis 节点配置并启动
for p in 7000 7001 7002 7003 7004 7005; do
  mkdir -p /data/$p
  cat > /data/$p/redis.conf <<EOF
port $p
cluster-enabled yes
cluster-config-file nodes-$p.conf
cluster-node-timeout 5000
appendonly yes
protected-mode no
bind 0.0.0.0
requirepass $REDIS_PASSWORD
masterauth $REDIS_PASSWORD
# 广播容器名,保证 RedisInsight 容器内部可访问
cluster-announce-ip redis-cluster
cluster-announce-port $p
cluster-announce-bus-port 1$p
EOF
  redis-server /data/$p/redis.conf &
done

# 等待 Redis 节点启动
sleep 5

# 创建集群
yes yes | redis-cli -a $REDIS_PASSWORD --cluster create \
  redis-cluster:7000 redis-cluster:7001 redis-cluster:7002 \
  redis-cluster:7003 redis-cluster:7004 redis-cluster:7005 \
  --cluster-replicas 1

# 保持容器运行
tail -f /dev/null

创建 Docker 网络(如果尚未创建):#

启动容器#

验证 Redis Cluster 状态:#

🌐 RedisInsight 免费版使用(自动发现集群)#

1、打开浏览器访问:http://宿主机IP:8001
2、点击 Add Redis Database → Redis Software Cluster
3、填写 入口节点信息(Cluster 中任意一个主节点):
字段填写示例
Host192.168.10.155(宿主机IP)或 redis-cluster(容器内部UI)
Port7000
Usernamedefault
PasswordProdStrongPass123!
Use TLSfalse
4、点击 Test Connection → 成功后 Add
5、RedisInsight 会自动发现其余集群节点并显示在 UI 中
注意:免费版不会显示 cluster bus 细节,但可以浏览和操作各节点数据。
修改于 2025-09-09 15:34:46
上一页
安装部署
下一页
基本规则
Built with