docker搭建redis集群

[root@warship ~]# cat /etc/docker/daemon.json 
{
  "registry-mirrors": ["https://aj9exr6t.mirror.aliyuncs.com"]
}
[root@warship ~]# tree /home/redis/
/home/redis/
├── docker-compose.yml
├── redis_7001
│   ├── redis_7001.conf
│   └── redis_data
│       ├── appendonly.aof
│       ├── dump.rdb
│       └── nodes.conf
├── redis_7002
│   ├── redis_7002.conf
│   └── redis_data
│       ├── appendonly.aof
│       ├── dump.rdb
│       └── nodes.conf
├── redis_7003
│   ├── redis_7003.conf
│   └── redis_data
│       ├── appendonly.aof
│       ├── dump.rdb
│       └── nodes.conf
├── redis_7004
│   ├── redis_7004.conf
│   └── redis_data
│       ├── appendonly.aof
│       ├── dump.rdb
│       └── nodes.conf
├── redis_7005
│   ├── redis_7005.conf
│   └── redis_data
│       ├── appendonly.aof
│       ├── dump.rdb
│       └── nodes.conf
└── redis_7006
    ├── redis_7006.conf
    └── redis_data
        ├── appendonly.aof
        ├── dump.rdb
        └── nodes.conf

12 directories, 25 files
[root@warship ~]# cat /home/redis/redis_7001/redis_7001.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
[root@warship ~]# cat /home/redis/docker-compose.yml 
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

部署集群docker run --rm -it gavinmroy/redis-trib create --replicas 1 本机ip:7001 本机ip:7002 本机ip:7003 本机ip:7004 本机ip:7005 本机ip:7006 
Unable to find image 'gavinmroy/redis-trib:latest' locally
latest: Pulling from gavinmroy/redis-trib
7b3159310e21: Pull complete 
b942d2c4d8d6: Pull complete 
a7021af2bc4b: Pull complete 
Digest: sha256:41a80d27a886487a11a63d84f3e21f9fd16883af95858640097f46a799cb3ec9
Status: Downloaded newer image for gavinmroy/redis-trib:latest
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.18.144:7001
192.168.18.144:7002
192.168.18.144:7003
Adding replica 192.168.18.144:7004 to 192.168.18.144:7001
Adding replica 192.168.18.144:7005 to 192.168.18.144:7002
Adding replica 192.168.18.144:7006 to 192.168.18.144:7003
M: de2bfa78f13df5f52fb76ab8fbb77cfc072b4e14 192.168.18.144:7001
   slots:0-5460 (5461 slots) master
M: c6cde029e65c27e935cdb3193bb7beee9d218904 192.168.18.144:7002
   slots:5461-10922 (5462 slots) master
M: b548028b2125c785adf62bc56c569b8d12840327 192.168.18.144:7003
   slots:10923-16383 (5461 slots) master
S: af46eb2fce331f9565b831e4de9479532fe9d7df 192.168.18.144:7004
   replicates de2bfa78f13df5f52fb76ab8fbb77cfc072b4e14
S: c0c67c7d38b93fcbd54b447b8efa7c6afd8a6d46 192.168.18.144:7005
   replicates c6cde029e65c27e935cdb3193bb7beee9d218904
S: eeb15c14999face8016b9051b935a03eddcccf2d 192.168.18.144:7006
   replicates b548028b2125c785adf62bc56c569b8d12840327
Can I set the above configuration? (type 'yes' to accept): >>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join..
>>> Performing Cluster Check (using node 192.168.18.144:7001)
M: de2bfa78f13df5f52fb76ab8fbb77cfc072b4e14 192.168.18.144:7001
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: c0c67c7d38b93fcbd54b447b8efa7c6afd8a6d46 172.19.0.1:7005@17005
   slots: (0 slots) slave
   replicates c6cde029e65c27e935cdb3193bb7beee9d218904
M: c6cde029e65c27e935cdb3193bb7beee9d218904 172.19.0.1:7002@17002
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: af46eb2fce331f9565b831e4de9479532fe9d7df 172.19.0.1:7004@17004
   slots: (0 slots) slave
   replicates de2bfa78f13df5f52fb76ab8fbb77cfc072b4e14
S: eeb15c14999face8016b9051b935a03eddcccf2d 172.19.0.1:7006@17006
   slots: (0 slots) slave
   replicates b548028b2125c785adf62bc56c569b8d12840327
M: b548028b2125c785adf62bc56c569b8d12840327 172.19.0.1:7003@17003
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
也可以用本地redis-retrib测试
[root@warship ~]# redis-trib check 192.168.18.144:7001
>>> Performing Cluster Check (using node 192.168.18.144:7001)
M: de2bfa78f13df5f52fb76ab8fbb77cfc072b4e14 192.168.18.144:7001
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: c0c67c7d38b93fcbd54b447b8efa7c6afd8a6d46 172.19.0.1:7005@17005
   slots: (0 slots) slave
   replicates c6cde029e65c27e935cdb3193bb7beee9d218904
M: c6cde029e65c27e935cdb3193bb7beee9d218904 172.19.0.1:7002@17002
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: af46eb2fce331f9565b831e4de9479532fe9d7df 172.19.0.1:7004@17004
   slots: (0 slots) slave
   replicates de2bfa78f13df5f52fb76ab8fbb77cfc072b4e14
S: eeb15c14999face8016b9051b935a03eddcccf2d 172.19.0.1:7006@17006
   slots: (0 slots) slave
   replicates b548028b2125c785adf62bc56c569b8d12840327
M: b548028b2125c785adf62bc56c569b8d12840327 172.19.0.1:7003@17003
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

参考 https://blog.csdn.net/bpqdwo/article/details/93537951

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值