首页 > 其他 > 详细

docker-compose搭建redis集群--Cluster模式

时间:2020-06-24 14:11:12      阅读:90      评论:0      收藏:0      [点我收藏+]

Redis有三种集群模式

* 主从模式

* Sentinel模式

* Cluster模式

参考:Redis集群详解

首先需要docker 、docker-compose 环境

技术分享图片

 

 Gitee地址: https://gitee.com/lifeToSpring/redis-cluster

 

节点192.168.255.225:

docker-compose.yml

services:
  redis-master1:
    image: redis:5.0 # 基础镜像
    container_name: node1 # 容器名称
    working_dir: /config # 切换工作目录
    environment: # 环境变量
      - PORT=6391 # 会使用config/nodes-${PORT}.conf这个配置文件
    ports: # 映射端口,对外提供服务
      - 6391:6391 # redis的服务端口
      - 16391:16391 # redis集群监控端口
    stdin_open: true # 标准输入打开
    tty: true # 后台运行不退出
    network_mode: host # 使用host模式
    privileged: true # 拥有容器内命令执行的权限
    volumes:
      - /mydata/redis-cluster/config:/config #配置文件目录映射到宿主机
    entrypoint: # 设置服务默认的启动程序
      - /bin/bash
      - redis.sh
  redis-master2:
    image: redis:5.0
    working_dir: /config
    container_name: node2
    environment:
      - PORT=6392
    ports:
      - 6392:6392
      - 16392:16392
    stdin_open: true
    network_mode: host
    tty: true
    privileged: true
    volumes:
      - /mydata/redis-cluster/config:/config
    entrypoint:
      - /bin/bash
      - redis.sh
  redis-master3:
    image: redis:5.0
    container_name: node3
    working_dir: /config
    environment:
      - PORT=6393
    ports:
      - 6393:6393
      - 16393:16393
    stdin_open: true
    network_mode: host
    tty: true
    privileged: true
    volumes:
      - /mydata/redis-cluster/config:/config
    entrypoint:
      - /bin/bash
      - redis.sh

 

 

 

节点192.168.255.226:

docker-compose.yml

version: "3"
services:
  redis-slave1:
    image: redis:5.0
    container_name: node4
    working_dir: /config
    environment:
      - PORT=6394
    ports:
      - 6394:6394
      - 16394:16394
    stdin_open: true
    network_mode: host
    tty: true
    privileged: true
    volumes:
      - /mydata/redis-cluster/config:/config
    entrypoint:
      - /bin/bash
      - redis.sh
  redis-slave2:
    image: redis:5.0
    working_dir: /config
    container_name: node5
    environment:
      - PORT=6395
    ports:
      - 6395:6395
      - 16395:16395
    stdin_open: true
    network_mode: host
    tty: true
    privileged: true
    volumes:
      - /mydata/redis-cluster/config:/config
    entrypoint:
      - /bin/bash
      - redis.sh
  redis-slave3:
    image: redis:5.0
    container_name: node6
    working_dir: /config
    environment:
      - PORT=6396
    ports:
      - 6396:6396
      - 16396:16396
    stdin_open: true
    network_mode: host
    tty: true
    privileged: true
    volumes:
      - /mydata/redis-cluster/config:/config
    entrypoint:
      - /bin/bash
      - redis.sh

 

公共部分:

技术分享图片

 

 redis.sh

redis-server  /config/nodes-${PORT}.conf

修改对应的配置文件(参考):

# bind 127.0.0.1 //加上注释#
protected-mode no //关闭保护模式
port 6391  //绑定自定义端口
# daemonize yes //禁止redis后台运行
pidfile /var/run/redis_6391.pid
cluster-enabled yes //开启集群 把注释#去掉
cluster-config-file nodes_6391.conf //集群的配置 配置文件首次启动自动生成
appendonly yes //开启aof
cluster-announce-ip 10.xx.xx.xx   //要宣布的IP地址。nat模式要指定宿主机IP
cluster-announce-port 6391  //要宣布的数据端口。
cluster-announce-bus-port 16391  //要宣布的集群总线端口

 

docker-compose搭建redis集群--Cluster模式

原文:https://www.cnblogs.com/brithToSpring/p/13187206.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!