To prepare

Assume that the IP address is 192.168.1.30-35

Change the 30-32 configuration (e.g. /etc/redis/redis.conf to the path you set)

All three of them

The bind 0.0.0.0Copy the code
Run the command in 31 to 32Copy the code

Redis -cli slaveof 192.168.1.30 6379 info(Verify primary/secondary Settings successfully)

## Modify the 33-35 configuration (using the sentinel configuration provided with source code)Copy the code

Bind 0.0.0.0 Sentinel monitor myMaster 192.168.1.30 6379 2

# # to start the sentinelCopy the code

redis-sentinel /path/to/sentinel.conf

## is executed in 30Copy the code

sudo kill -s SIGTERM $(pgrep redis)

## and sentinelCopy the code

827:X 18 Feb 08:20:28.205 # +switch-master mymaster 192.168.1.31 6379 192.168.1.32 6379

Enter 31 to executeCopy the code

Redis -cli info (check primary/secondary status and verify whether to switch to 31 because 31priority is lower, i.e. higher priority)

Copy the code