Due to the limitations of Redis' single-point performance and our inherent need for data backup, Redis provides master-slave replication services. This article records the construction of a master-dual slave Redis service through docker compose. Configuration parsing#################################### REPLICATION #################################### # [Slave] Configuration of connecting to Master # slaveof 172.25.0.101 6379 # 【Slave】Read-only mode# slave-read-only yes # 【Slave】Password# masterauth <master-password> # [Slave] Is it allowed to respond to queries during replication? Dirty data may be returned. # slave-serve-stale-data yes # [Slave] The priority of a slave to be promoted to a master. This is only effective in sentinel mode. # slave-priority 100 # 【Slave】Slave's own IP reported to the Master # slave-announce-ip 5.5.5.5 # 【Slave】Slave's own port reported to the Master# slave-announce-port 1234 # 【Slave】The interval between Slave pinging Master# repl-ping-slave-period 10 # 【Master/Slave】Timeout# repl-timeout 60 # [Master] Diskless means directly writing the RDB file to be copied to the Socket without storing it on the disk first repl-diskless-sync no # [Master] If Diskless is enabled, it will wait for the specified number of seconds before replicating, so that more clients can connect within the window period and transmit in parallel. # repl-diskless-sync-delay 5 # [Master] Whether to enable the Nagle algorithm, which can reduce traffic usage but will make synchronization slower repl-disable-tcp-nodelay no # [Master] The size of the ring buffer log, which is used to reconnect after the Slave is disconnected to avoid full replication. The default value is 1mb # repl-backlog-size 1mb # 【Master】When the Master disconnects all Slaves for a specified period of time, the Master will clear the backlog # repl-backlog-ttl 3600 # [Master] When the number of slave connections is less than the specified number, the Master rejects all write operations # min-slaves-to-write 3 # [Master] When the delay is higher than the specified number of seconds, the Master rejects all write operations # min-slaves-max-lag 10 Service Construction Directory Structurereplication/ ├── docker-compose.yml ├── master │ ├── data │ └── redis.conf ├── slave1 │ ├── data │ └── redis.conf └── slave2 ├── data └── redis.conf Compose FileA subnet is defined for easy operation, and ports 6371 (Master), 6372, and 6373 are exposed. version: "3" networks: redis-replication: driver: bridge ipam: config: - subnet: 172.25.0.0/24 services: master: image: redis container_name: redis-master ports: - "6371:6379" volumes: - "./master/redis.conf:/etc/redis.conf" - "./master/data:/data" command: ["redis-server", "/etc/redis.conf"] restart: always networks: redis-replication: ipv4_address: 172.25.0.101 slave1: image: redis container_name: redis-slave-1 ports: - "6372:6379" volumes: - "./slave1/redis.conf:/etc/redis.conf" - "./slave1/data:/data" command: ["redis-server", "/etc/redis.conf"] restart: always networks: redis-replication: ipv4_address: 172.25.0.102 slave2: image: redis container_name: redis-slave-2 ports: - "6373:6379" volumes: - "./slave2/redis.conf:/etc/redis.conf" - "./slave2/data:/data" command: ["redis-server", "/etc/redis.conf"] restart: always networks: redis-replication: ipv4_address: 172.25.0.103 Instance ConfigurationMaster: Basically no configuration is required, the simplest thing is to specify a port. port 6379 protected-mode no repl-diskless-sync no repl-disable-tcp-nodelay no Slave: The instance configurations just need to remain consistent, because the subnets are defined and there are no port conflicts. port 6379 protected-mode no slaveof 172.25.0.101 6379 slave-read-only yes slave-serve-stale-data yes Start the serviceocker-compose up -d Creating network "replication_redis-replication" with driver "bridge" Creating redis-slave-1 ... done Creating redis-master ... done Creating redis-slave-2 ... done Checking the Master log, you can see that the replication requests from two Slaves were accepted:
Check the Slave log to see the entire process of connection establishment:
testLog in to the Master and try to write a new key. 127.0.0.1:6371> set hello world OK Log in to the slave and check whether it can read: 127.0.0.1:6372> get hello "world" The slave attempts a write operation: 127.0.0.1:6372> set hello redis (error) READONLY You can't write against a read only replica. This is the end of this article about the implementation of master-slave replication in docker compose deployment. For more relevant docker compose master-slave replication content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: A brief discussion on how to use slots in Vue
>>: Mysql auto-increment primary key id is not processed in this way
The first step is to check the version number and...
Added anti-crawler policy file: vim /usr/www/serv...
Table of contents 1.setInterval() 2.setTimeout() ...
A database index is a data structure whose purpos...
The effect shows that two browsers simulate each ...
This article example shares the specific code of ...
After installing a centos8 service under vmware a...
A joint index is also called a composite index. F...
Problem: The partition where MySQL stores data fi...
As shown below: XML/HTML CodeCopy content to clip...
Preface Today I will share with you a holy grail ...
Preface MySQL supports many types of tables (i.e....
This article shares the specific code of JavaScri...
1. iframe definition and usage The iframe element...
Table of contents 1. WordPress deployment 1. Prep...