Prepare three virtual machines CentOS 7 environment, and then download the redis-5.0.8 installation package, I put it in the /opt directory
wget https://github.com/redis/redis/archive/5.0.8.tar.gz
Unzip
tar -xzvf redis-5.0.8.tar.gz
For the redis installation process of each virtual machine, please refer to my previous article
1. Three virtual machines
192.168.171.210( master) | port 6379 |
---|---|
192.168.171.211( slave) | port 6379 |
192.168.171.212( slave) | port 6379 |
192.168.171.210 ( sentinel) | port 26379 |
---|---|
192.168.171.211 ( sentinel) | port 26379 |
192.168.171.212 ( sentinel) | port 26379 |
2. Edit redis configuration file
# bind 127.0.0.1//Comment out this line protected-mode no //Turn off protection mode
requirepass 10010//Set redis password,If you set a password,Three redis instances must set the same password
3. Edit sentinel.conf configuration file
daemonize yes //Start the daemon
sentinel monitor mymaster 192.168.171.21263792
sentinel auth-pass mymaster 10010
4. Start in order
Start the master redis instance --> start the replicaof redis instance --> start three sentinel instances
systemctl start redisd
. /src/redis-sentinel sentinel.conf
5. Test failover
. /src/redis-cli -a 10010-p 6379 DEBUG sleep 40
Execute the above command on the master, and after 40 seconds, observe whether the master is changed to another instance
Recommended Posts