docker-compose 部署redis-cluster

1.下载官方 redis.conf

http://download.redis.io/redis-stable/redis.conf

2.修改redis.conf

# bind 127.0.0.1 //加上注释#
protected-mode no //关闭保护模式
port 6061  //绑定自定义端口
#daemonize yes //禁止redis后台运行
pidfile /var/run/redis_6061.pid 
cluster-enabled yes //开启集群 把注释#去掉
cluster-config-file nodes_6061.conf //集群的配置 配置文件首次启动自动生成 

2.docker-compose.yaml

version: '3.4'
services:
  node1:
    image: redis:5.0.5
    container_name: redis-node1
    restart: always
    ports:
      - 6061:6061
      - 16061:16061
    volumes:
      - /home/smb/data/redis-cluster/node1:/data
      - /home/smb/config/redis-cluster/node1:/usr/local/etc/redis
    command:
      redis-server /usr/local/etc/redis/redis.conf
       
  node2:
    image: redis:5.0.5
    container_name: redis-node2
    restart: always
    ports:
      - 6062:6062
      - 16062:16062
    volumes:
      - /home/smb/data/redis-cluster/node2:/data
      - /home/smb/config/redis-cluster/node2:/usr/local/etc/redis
    command:
      redis-server /usr/local/etc/redis/redis.conf
       
       
  node3:
    image: redis:5.0.5
    container_name: redis-node3
    restart: always
    ports:
      - 6063:6063
      - 16063:16063
    volumes:
      - /home/smb/data/redis-cluster/node3:/data
      - /home/smb/config/redis-cluster/node3:/usr/local/etc/redis
    command:
      redis-server /usr/local/etc/redis/redis.conf
       
  node4:
    image: redis:5.0.5
    container_name: redis-node4
    restart: always
    ports:
      - 6064:6064
      - 16064:16064
    volumes:
      - /home/smb/data/redis-cluster/node4:/data
      - /home/smb/config/redis-cluster/node4:/usr/local/etc/redis
    command:
      redis-server /usr/local/etc/redis/redis.conf
       
  node5:
    image: redis:5.0.5
    container_name: redis-node5
    restart: always
    ports:
      - 6065:6065
      - 16065:16065
    volumes:
      - /home/smb/data/redis-cluster/node5:/data
      - /home/smb/config/redis-cluster/node5:/usr/local/etc/redis
    command:
      redis-server /usr/local/etc/redis/redis.conf
       
  node6:
    image: redis:5.0.5
    container_name: redis-node6
    restart: always
    ports:
      - 6066:6066
      - 16066:16066
    volumes:
      - /home/smb/data/redis-cluster/node6:/data
      - /home/smb/config/redis-cluster/node6:/usr/local/etc/redis
    command:
      redis-server /usr/local/etc/redis/redis.conf

4. docker-compose up -d 启动redis-cluster

5. 链接集群

docker run --rm -it zvelo/redis-trib create --replicas 1 ip:6061 ip:6062 ip:6063 ip:6064 ip:6065 ip:6066

6.测试 redis Desktop Manager 链接 6061 node1  ,node已经切换成功

docker-compose 部署redis-cluster_第1张图片

你可能感兴趣的:(docker-compose,杂记,微服务)