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

评论关闭
IT源码网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!