docker部署redis集群

首先创建几个文件夹

mkdir -r /home/redis/redis_7001/redis_data
mkdir -r /home/redis/redis_7002/redis_data
mkdir -r /home/redis/redis_7003/redis_data
mkdir -r /home/redis/redis_7004/redis_data
mkdir -r /home/redis/redis_7005/redis_data
mkdir -r /home/redis/redis_7006/redis_data

vi /home/redis/redis_7001/redis_7001.conf
vi /home/redis/redis_7002/redis_7002.conf
vi /home/redis/redis_7003/redis_7003.conf
vi /home/redis/redis_7004/redis_7004.conf
vi /home/redis/redis_7005/redis_7005.conf
vi /home/redis/redis_7006/redis_7006.conf

redis.conf内容,端口要依次修改

#bind ip 外网访问
port 7001 
protected-mode no
#requirepass admin
#masterauth admin
daemonize no
appendonly yes

cluster-enabled yes
cluster-node-timeout 15000
cluster-config-file nodes.conf

**注意: 在执行redis-trib create --replicas的时候,redis的密码要配置删掉,否则会连不上提示 can not connect ip **

version: '3.3'
services:
 redis-7001:
  image: redis:latest
  container_name: redis-7001
  restart: always
  command: redis-server /usr/local/etc/redis/redis.conf
  ports:
    - "7001:7001"
    - "17001:17001"
  volumes:
    - /home/redis/redis_7001/redis_data:/data
    - /home/redis/redis_7001/redis_7001.conf:/usr/local/etc/redis/redis.conf
    
 redis-7002:
  image: redis:latest
  container_name: redis-7002
  restart: always
  command: redis-server /usr/local/etc/redis/redis.conf
  ports:
    - "7002:7002"
    - "17002:17002"
  volumes:
    - /home/redis/redis_7002/redis_data:/data
    - /home/redis/redis_7002/redis_7002.conf:/usr/local/etc/redis/redis.conf
    
 redis-7003:
  image: redis:latest
  container_name: redis-7003
  restart: always
  command: redis-server /usr/local/etc/redis/redis.conf
  ports:
    - "7003:7003"
    - "17003:17003"
  volumes:
    - /home/redis/redis_7003/redis_data:/data
    - /home/redis/redis_7003/redis_7003.conf:/usr/local/etc/redis/redis.conf
    
 redis-7004:
  image: redis:latest
  container_name: redis-7004
  restart: always
  command: redis-server /usr/local/etc/redis/redis.conf
  ports:
    - "7004:7004"
    - "17004:17004"
  volumes:
    - /home/redis/redis_7004/redis_data:/data
    - /home/redis/redis_7004/redis_7004.conf:/usr/local/etc/redis/redis.conf
    
 redis-7005:
  image: redis:latest
  container_name: redis-7005
  restart: always
  command: redis-server /usr/local/etc/redis/redis.conf
  ports:
    - "7005:7005"
    - "17005:17005"
  volumes:
    - /home/redis/redis_7005/redis_data:/data
    - /home/redis/redis_7005/redis_7005.conf:/usr/local/etc/redis/redis.conf
    
 redis-7006:
  image: redis:latest
  container_name: redis-7006
  restart: always
  command: redis-server /usr/local/etc/redis/redis.conf
  ports:
    - "7006:7006"
    - "17006:17006"
  volumes:
    - /home/redis/redis_7006/redis_data:/data
    - /home/redis/redis_7006/redis_7006.conf:/usr/local/etc/redis/redis.conf

部署cluster

docker run --rm -it gavinmroy/redis-trib create --replicas 1 10.17.27.212:7001 10.17.27.212:7002 10.17.27.212:7003 10.17.27.212:7004 10.17.27.212:7005 10.17.27.212:7006 


--replicas 1   每个master有1个slave

6台机器,3个master,3个slave,尽量自己让master和slave不在一台机器上

docker run --rm -it gavinmroy/redis-trib check 10.17.27.212:7001

注意:如果再分配slot集群的时候,用的是内网分配,则java redis-cluster客户端用外网会连不上,报redis.clients.jedis.exceptions.JedisClusterMaxRedirectionsException: Too many Cluster redirections?的错,得用内网连接

你可能感兴趣的:(docker)