master-slave replication
Official documentation: https://redis.io/topics/replication
Master-slave replication in Redis, that is, the Master-Slave model, has the following characteristics
Master can have multiple slaves
Multiple slaves can not only connect to the same master, but also connect to other slaves
Master-slave replication will not block the master. When synchronizing data, the master can continue to process client requests
Provides system scalability
Master-slave replication process:
The slave establishes a connection with the master and sends a sync synchronization command
The master starts a background process to keep data snapshots in the file, and the master master process starts to collect new write commands and cache them
After saving in the background, send the file to the slave
slave saves the file to the hard disk
Master-slave replication configuration:
Configure 3 redis, 1master2slave
Use scp -r redis3.2_1/ sloveip:/ copy directory to copy the redis installed on the master to the slave
Modify the port number of the master slave in the configuration file
Modify the slaveof of the slave to the ip address port number of the host
Start these three redis services respectively
You can see that the master and slave have been started
Since it is simulated on the same machine, the port number must be specified to start the client
After startup, check the information in info, you can see that the master and slave have succeeded
View the slave and print the following information
When the master writes data, the slave can read it
sentinel
Sentinel can monitor the running status of the redis system. The main functions are:
Monitor whether the master database and slave database are running normally
When the primary database fails, the secondary database can be automatically replaced with the primary database to achieve automatic switching
Configuration (configured on slave1)
Copy the sentinel.conf file under the installed redis3.2_1 file to the folder where the configuration file is stored
Then enter the sentinel.conf file and configure the directory
Configuration name, master node ip, port, number of voting elections (1 means that there is a slave node that thinks the master node is down and the master node is down)
monitoring strategy
The default timeout of 30 seconds is downtime
Number of slave nodes
start redis service
start sentinel
View Sentinel Information
kill master node
info info
The master port has become 6381
Restart port 6380, console prints
info info