1.Master-slave replication (master/slave)
2.High available Sentinel Sentinel
3.High availability cluster pattern
【 Master-slave replication (master/slave)]
[RedisOne master multi slave architecture]
Through persistence, Redis ensures that even if the server is restarted, it will not lose (or a small amount of lost) data, but because the data is stored on a server, if the server fails, such as the hard disk, it can also cause data loss.
In order to avoid data single point loss, we need to deploy multiple copies of data on a number of different servers, even if one server fails, other servers can continue to provide services.
【How to achieve it]
It is requested that when the data on the main server is updated, the updated data will be automatically synchronized to other servers.
RedisA copy (replication) function is provided to automatically realize data synchronization of multiple Redis servers.
By configuring multiple Redis and specifying the master and slave relationship between these Redis in the configuration file, the master is responsible for writing the data and synchronizing the written data to the slave machine in real time, which is called the “master slave copy”, that is, the master/slave mode, and RediS default master is used for writing, slave is used for reading, and writing data to salve can cause errors.
[ Implementation mode 1]
When modifying the configuration file, the server reads the configuration file and automatically becomes the slave server of the specified server when it starts, thus forming the master-slave replication relationship.
The following configuration is based on the single server, starting the configuration of multiple Redis instances, simulating a number of redis services.
#masterThe main server conf file configuration adds a new redis_6380 configuration file. include /usr/local/redis-3.2.9/redis.conf #Import the contents of the Redis original configuration file
daemomize yes port 6380 pidfile /var/rum/redis_6380.pid logfile 6380.log dbfilename dump6380.rdb #slaveConfiguration from the server conf file include /usr/local/redis-3.2.9/redis.conf #Master server
daemonize yes port 6382 pidfile /var/run/redis_6382.log dbfilename dump6382.rdb slaveof 127.0.0.1 6380 #This sentence is the key
[ Implementation mode 2]
./redis-server –slaveof <master-ip> <master-port>，When starting redis, specify the current server as the slave slave of a main Redis service.
[Disaster tolerance treatment (manual treatment)]
When the master service fails, you need to manually upgrade one of the slave to master, and the rest of the slave hang to the new master (cold processing). The steps are as follows (if three machines are: Master, slave1, slave2)
1.To connect to slave1, first upgrade the slave1 server to master:slaveof no one
2.Connect to salve2 and hang slave2 on the new master:slaveof 127.0.0.1 6381
[Summary of the master-slave model]
【High availability of the Sentinel sentinel]
SentineSentinel is a highly available solution provided by Redis official, which can be used to monitor the running of multiple Redis instances.
[Configuration (using a single server to start three instances)]
【High availability cluster pattern]
RedisCluster is a distributed server group consisting of multiple node groups. It has the characteristics of replication, high availability and fragmentation. Redis does not need the Sentinel sentinel to complete the function of node removal and failure transfer. Each node is set to cluster mode, and this cluster model has no central node.It can be extended horizontally, the official document says it can be extended linearly to 1000 nodes, and the performance and high availability of the Redis cluster is superior to the previous version of the Sentinel sentinel pattern, and the cluster configuration is relatively simple.