JohnsonChung

 前言

  前面介绍了

################################# REPLICATION #################################  # Master-Slave replication. Use slaveof to make a Redis instance a copy of # another Redis server. A few things to understand ASAP about Redis replication. # # 1) Redis replication is asynchronous, but you can configure a master to #    stop accepting writes if it appears to be not connected with at least #    a given number of slaves. # 2) Redis slaves are able to perform a partial resynchronization with the #    master if the replication link is lost for a relatively small amount of #    time. You may want to configure the replication backlog size (see the next #    sections of this file) with a sensible value depending on your needs. # 3) Replication is automatic and does not need user intervention. After a #    network partition slaves automatically try to reconnect to masters #    and resynchronize with them. # slaveof redis 6379   # redis是master的容器名  # If the master is password protected (using the "requirepass" configuration # directive below) it is possible to tell the slave to authenticate before # starting the replication synchronization process, otherwise the master will # refuse the slave request. # masterauth 123455  slave-read-only yes  # slave只读
复制代码

三个配置文件配置好后,就可以配置docker-composer.yml文件了

复制代码
version: "3.7"  networks:   backend:     driver: bridge  services:  ### Redis ################################################   # master   redis:     image: johnson19900110/redis:latest     restart: always     volumes:       - ${DATA_PATH_HOST}/redis/master:/data       - ./redis/config/redis-master.conf:/usr/local/etc/redis/redis.conf     ports:       - 6379:6379     networks:       - backend    # slave 1   redis-slave1:     image: johnson19900110/redis:latest     restart: always     volumes:       - ${DATA_PATH_HOST}/redis/slave1:/data       - ./redis/config/redis-slave1.conf:/usr/local/etc/redis/redis.conf     ports:       - 6380:6379     networks:       - backend     depends_on:       - redis    # slave 2   redis-slave2:     image: johnson19900110/redis:latest     restart: always     volumes:       - ${DATA_PATH_HOST}/redis/slave2:/data       - ./redis/config/redis-slave2.conf:/usr/local/etc/redis/redis.conf     ports:       - 6381:6379     networks:       - backend     depends_on:       - redis       - redis-slave1
复制代码

然后就可以启动redis容器了

docker-composer up -d redis-slave2

  这时候3个redis就已经启动起来了

这是我们进入master容器。在redis-cli命令下执行 

关键字:
50000+
5万行代码练就真实本领
17年
创办于2008年老牌培训机构
1000+
合作企业
98%
就业率

联系我们

电话咨询

0532-85025005

扫码添加微信