Sentinel mode of redis in docker environment

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,
Insert picture description here

View the data in the server The
Insert picture description here
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.
Insert picture description here
Enter the container of the master device and check the status
Insert picture description here
of the master device. Do the same operation on another slave device. The final result is shown in the figure below.
Insert picture description here

Test master-slave replication mode

Insert picture description here
View the data in the slave device
Insert picture description here

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

Insert picture description here
View the status of the sentry.
The address information of the main device is displayed here.
Insert picture description here
The sentinels information here is different from the docker address I actually created, I don’t know why
Insert picture description here

Disconnect

Turn off the master device (192.168.1.10) to see if it can be switched normally.
Insert picture description here
View the information of any sentry.
Insert picture description here
View the information of the redis container (on 1.11).
Insert picture description here
View the changes of another slave device.
Insert picture description here
1.11 As a new master device, you can also add data normally
Insert picture description here
, 1.7 is still a slave device, so it still cannot be created
Insert picture description here

Master device before restart

Insert picture description here

Insert picture description here

Insert picture description here
Automatically sync books
Insert picture description here

Shoulders of giants

https://www.jianshu.com/p/ce1d78cd368a

Guess you like

Origin blog.csdn.net/qq_41948178/article/details/106585244