码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2020-05-02 22:56:35      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:python   cts   public   工具   creat   配置   接下来   dock   数据   

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:

参考链接(

https://www.runoob.com/docker/docker-redis-cluster.html

https://www.jianshu.com/p/b7dea62bcd8b

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

标签:python   cts   public   工具   creat   配置   接下来   dock   数据   

原文地址:https://www.cnblogs.com/daleyzou/p/docker-redis-cluster.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!