A master-slave replication

role

The master-slave replication architecture is only used for redundant backup of data, and the slave node is only used for synchronization, but it cannot write data

The problem

Automatic failover that cannot resolve a master node failure

Architecture diagram

Set up process

1. Prepare three machines and modify the configuration file. (You can use different configuration files for the same machine.) Master port 6379 bind 0.0.0.0 slave1 port 6380 bind 0.0.0.0 slaveof masterip Masterport slave2 port 6381 Bind 0.0.0.0 slaveof masterip masterportCopy the code

2. Start three machines to test./redis-server /root/master/ redis.conf. /redis-server /root/slave1/redis.conf. /redis-server /root/slave2/redis.confCopy the code

The guard mechanism

introduce

Sentinel is a highly available solution for Redis: A Sentinel system consisting of one or more Sentinel instances can monitor any number of primary servers and the secondary servers under these primary servers, and automatically upgrade a secondary server under the offline primary server to a new primary server when the monitored primary server goes offline (using the heartbeat mechanism). Sentinel is simply a master-slave architecture with automatic failover. A set of sentinel services can monitor N master/slave architectures.

Question:

1. The concurrent load of a node 2. The memory and disks of a node go offline

Sentry architecture schematic diagram

Build sentinel architecture

1. Create sentinel configuration on the primary node. Create sentinel.conf file in the redis. Enter the following content in the sentinel.conf file: Name of the monitored database (choose your own name) IP port 1 indicates the number of sentinels 3. Startup guard mode test redis - sentinel/root/sentinel/sentinel conf added: redis - sentinel the script file can be obtained from the source directory of redis, start the sentinel must first start master-slave, The number 2 indicates that two or more sentinel services detect a master outage before performing a master/slave switchover.Copy the code

Use SpringBoot to connect to sentinel mode

# # redis sentinel configuration master name of writing is the use of sentinel surveillance of the spring. The redis. Sentinel. Master = # mymaster connection is no longer a specific redis host, writing is more than one sentinel node Spring. Redis. Sentinel nodes = 192.168.202.206:26379Copy the code

Note: if the connection in the following error: RedisConnectionException: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command ‘CONFIG SET protected-mode no’ from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2)

Solution: Add bind 0.0.0.0 to sentry’s configuration file to enable remote connection privileges