1. 程式人生 > 其它 >docker 搭建 redis 叢集(Redis-Cluster叢集)

docker 搭建 redis 叢集(Redis-Cluster叢集)

1、安裝依賴項
yum install -y epel-release
yum install -y python-pip python-devel gcc
pip install --upgrade pip
2、安裝 docker-compose
pin install docker-compose
容器初始化

使用docker-compose方式,先建立一個docker-compose.yml檔案,內容如下:

version: '3'

services:
 redis1:
  image: publicisworldwide/redis-cluster
  network_mode: host
  restart: always
  volumes:
   - /data/redis/8001/data:/data
  environment:
   - REDIS_PORT=8001

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

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

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

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

 redis6:
  image: publicisworldwide/redis-cluster
  network_mode: host
  restart: always
  volumes:
   - /data/redis/8006/data:/data
  environment:
   - REDIS_PORT=8006
3、啟動redis叢集
docker-compose up -d
4、檢視已經啟動的程序
docker-compose ps
5、初始化叢集

如果在這裡要重新初始化,可以 docker-compose up stop 後,刪除 volumes 配置的對應資料目錄,然後 docker-compose up -d 重新啟動,然後初始化

docker run --rm -it inem0o/redis-trib create --replicas 1 172.19.165.222:8001 172.19.165.222:8002 172.19.165.222:8003 172.19.165.222:8004 172.19.165.222:8005 172.19.165.222:8006

接下來就可以使用 Redis Desktop Manager 等工具連線了,記得要取消勾選 change host on cluster redirects:

作者: DaleyZou
出處:https://www.cnblogs.com/daleyzou/p/docker-redis-cluster.html

參考連結(
https://www.runoob.com/docker/docker-redis-cluster.html
https://www.jianshu.com/p/b7dea62bcd8b)