installation of redis
Use Alibaba Cloud to install redis
Start redis
Create a configuration file
port 6379
logfile "redis-6381.log"
dir /data
appendonly yes
appendfilename appendonly.aof
# slaveof 127.1.0.1 6379
Start the redis image and cooperate with the container volume
# docker run -p 6379:6379 --name redis -v /home/docker/redis/redis.conf:/etc/redis/redis.conf -v /home/docker/redis/redis-data:/data -d redis redis-server /etc/redis/redis.conf
test
Test the connection. Use redis client to add data,
View the data in the server The
other two are similar, so far, the creation of the stand-alone version is complete.
Master-slave replication
Modify the configuration file of the slave device and add the ip of the master device.
port 6379
logfile "redis-6381.log"
dir /data
appendonly yes
appendfilename appendonly.aof
slaveof 192.168.1.10 6379
Enter the container of the slave device and check the status of the slave device.
Enter the container of the master device and check the status
of the master device. Do the same operation on another slave device. The final result is shown in the figure below.
Test master-slave replication mode
View the data in the slave device
Sentinel mode
Build a sentry container on each redis server
Sentinel's configuration file
port 26379
dir "/data"
logfile "sentinel-26379.log"
sentinel monitor mymaster 192.168.1.10 6379 2
sentinel down-after-milliseconds mymaster 10000
# sentinel failover-timeout mymaster 60000
# sentinel auth-pass mymaster 12345
Build
Start the sentry's container
# docker run -p 26379:26379 -v /home/docker/redis/redis-sentinel.conf:/etc/redis/redis-sentinel.conf -v /home/docker/redis/sentinel-data:/data -d redis redis-sentinel /etc/redis/redis-sentinel.conf
View the status of the sentry.
The address information of the main device is displayed here.
The sentinels information here is different from the docker address I actually created, I don’t know why
Disconnect
Turn off the master device (192.168.1.10) to see if it can be switched normally.
View the information of any sentry.
View the information of the redis container (on 1.11).
View the changes of another slave device.
1.11 As a new master device, you can also add data normally
, 1.7 is still a slave device, so it still cannot be created
Master device before restart
Automatically sync books
Shoulders of giants
https://www.jianshu.com/p/ce1d78cd368a