docker搭建三主三从redis集群使用Docker Compose

  • Post author:
  • Post category:其他


提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录







一、准备与执行

cd /

mkdir data

cd data

mkdir redis

cd redis/

mkdir 7001到7006

vi docker-compose.yml

yml内容

version: '3'
services:
 redis1:
  image: publicisworldwide/redis-cluster
  network_mode: host
  restart: always
  volumes:
   - /data/redis/7001/data:/data
  environment:
   - REDIS_PORT=7001

 redis2:
  image: publicisworldwide/redis-cluster
  network_mode: host
  restart: always
  volumes:
   - /data/redis/7002/data:/data
  environment:
   - REDIS_PORT=7002

 redis3:
  image: publicisworldwide/redis-cluster
  network_mode: host
  restart: always
  volumes:
   - /data/redis/7003/data:/data
  environment:
   - REDIS_PORT=7003

 redis4:
  image: publicisworldwide/redis-cluster
  network_mode: host
  restart: always
  volumes:
   - /data/redis/7004/data:/data
  environment:
   - REDIS_PORT=7004

 redis5:
  image: publicisworldwide/redis-cluster
  network_mode: host
  restart: always
  volumes:
   - /data/redis/7005/data:/data
  environment:
   - REDIS_PORT=7005

 redis6:
  image: publicisworldwide/redis-cluster
  network_mode: host
  restart: always
  volumes:
   - /data/redis/7006/data:/data
  environment:
   - REDIS_PORT=7006

执行

docker-compose up -d

查看

docker-compose ps

docker ps -a

随便进一个redis容器内部

docker exec -it d909a719e924 /bin/bash

然后执行下面命令 ip改成自己的主机地址 过程中输入yes

 redis-cli --cluster create 192.168.91.133:7001 192.168.91.133:7002 192.168.91.133:7003 192.168.91.133:7004 192.168.91.133:7005 192.168.91.133:7006 --cluster-replicas 1



​​​








总结



版权声明:本文为qq_55648724原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。