Docker部署Redis6.2一主两从三哨兵集群
Redis集群部署
节点
|
IP
|
master
|
10.3.192.57
|
slave1
|
10.3.192.58
|
slave2
|
10.3.192.59
|
官方文档
集群特性
- Monitoring. Sentinel constantly checks if your master and replica instances are working as expected.
- Notification. Sentinel can notify the system administrator, or other computer programs, via an API, that something is wrong with one of the monitored Redis instances.
- Automatic failover. If a master is not working as expected, Sentinel can start a failover process where a replica is promoted to master, the other additional replicas are reconfigured to use the new master, and the applications using the Redis server are informed about the new address to use when connecting.
- Configuration provider. Sentinel acts as a source of authority for clients service discovery: clients connect to Sentinels in order to ask for the address of the current Redis master responsible for a given service. If a failover occurs, Sentinels will report the new address.
集群架构
- Masters are called M1, M2, M3, ..., Mn.
- replicas are called R1, R2, R3, ..., Rn (R stands for replica).
- Sentinels are called S1, S2, S3, ..., Sn.
1.master节点
echo "export MY_MASTER=10.3.192.57" >> /etc/profile source /etc/profile vim redis-master.yml version: "3.7" services: redis-master: image: 1573927589/redis:6.2.5 network_mode: "host" restart: always environment: PASSWORD: 123456 volumes: - "./redis_data:/var/lib/redis" redis-sentinel: image: 1573927589/redis:6.2.5 network_mode: "host" restart: always depends_on: - redis-master environment: ROLER: sentinel MY_MASTER: $MY_MASTER PASSWORD: 123456
2.slave1节点
echo "export MY_MASTER=10.3.192.57" >> /etc/profile source /etc/profile vim redis-slave1.yml version: "3.7" services: redis-slave: image: 1573927589/redis:6.2.5 network_mode: "host" restart: always volumes: - "./redis_data:/var/lib/redis" environment: ROLER: slave MY_MASTER: $MY_MASTER PASSWORD: 123456 redis-sentinel: image: 1573927589/redis:6.2.5 network_mode: "host" restart: always environment: ROLER: sentinel MY_MASTER: $MY_MASTER PASSWORD: 123456
3.slave2节点
echo "export MY_MASTER=10.3.192.57" >> /etc/profile source /etc/profile vim redis-slave2.yml version: "3.7" services: redis-slave: image: 1573927589/redis:6.2.5 network_mode: "host" restart: always volumes: - "./redis_data:/var/lib/redis" environment: ROLER: slave MY_MASTER: $MY_MASTER PASSWORD: 123456 redis-sentinel: image: 1573927589/redis:6.2.5 network_mode: "host" restart: always environment: ROLER: sentinel MY_MASTER: $MY_MASTER PASSWORD: 123456
4.集群状态验证
root@localhost:/# redis-cli 127.0.0.1:6379> auth 123456 OK 127.0.0.1:6379> info replication
5.集群哨兵验证
root@localhost:/# redis-cli -p 26379 127.0.0.1:26379> info sentinel