Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example of the method of building redis-sentinel cluster based on docker

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. Overview

Redis clusters can achieve high availability and sharding across a set of redis nodes. There will be 1 master and multiple slave nodes in the cluster. When the master node fails, a slave node should be elected as the new master. However, Redis itself (including many of its clients) does not have the ability of automatic fault detection and active / standby switching, so it needs an external monitoring scheme to achieve automatic fault recovery.

Redis Sentinel is the officially recommended high availability solution. It is a monitoring and management tool for Redis cluster, which can provide node monitoring, notification, automatic fault recovery and client configuration discovery services.

2. Problems encountered

1. Docker host network

When docker uses host network, it does not work for windows and mac (no solution is found), and finally abandons windows to deploy clusters using centos.

2. Sentinel connection problem without using host network

You can specify the port of the master node to connect to the sentinel cluster without using the host network, so it can be connected normally. However, when the master node fails, the IP obtained by sentinel from the master node is the virtual IP in the container, which makes the cluster unable to connect properly.

3. Construction process

1. Directory structure

2. Sentinel configuration file

1 、 sentinel1.conf

# Port number port 26379dir / tmp# mymaster: custom cluster name. 2: the number of votes must be 2 sentinel to determine whether the master node has failed. "sentinel monitor mymaster" means that if the master node fails for more than 5000 seconds and there is no reply, it is determined that the master node cannot reach sentinel down-after-milliseconds mymaster 500 seconds, which means that at most numslaves is synchronously updating the new mastersentinel parallel-syncs mymaster nodes at the time of failover. The failover timeout sentinel failover-timeout mymaster 5000.

2 、 sentinel2.conf

# Port number port 26380dir / tmp# mymaster: custom cluster name. 2: the number of votes must be 2 sentinel to determine whether the master node has failed. "sentinel monitor mymaster" means that if the master node fails for more than 5000 seconds and there is no reply, it is determined that the master node cannot reach sentinel down-after-milliseconds mymaster 500 seconds, which means that at most numslaves is synchronously updating the new mastersentinel parallel-syncs mymaster nodes at the time of failover. The failover timeout sentinel failover-timeout mymaster 5000.

3 、 sentinel3.conf

# Port number port 26381dir / tmp# mymaster: custom cluster name. 2: the number of votes must be 2 sentinel to determine whether the master node has failed. "sentinel monitor mymaster" means that if the master node fails for more than 5000 seconds and there is no reply, it is determined that the master node cannot reach sentinel down-after-milliseconds mymaster 500 seconds, which means that at most numslaves is synchronously updating the new mastersentinel parallel-syncs mymaster nodes at the time of failover. The failover timeout sentinel failover-timeout mymaster 5000.

3 、 docker-compose.yml

Version: '2'services: master: image: redis:4.0 restart: always container_name: redis-master # use host network network_mode: "host" command: redis-server-- port 16379 slave1: image: redis:4.0 restart: always container_name: redis-slave-1 network_mode: "host" # specify the port and specify master ip port command: redis-server-- port 16380-- slaveof 16379 slave2: image: redis:4.0 restart: always Container_name: redis-slave-2 network_mode: "host" command: redis-server-- port 16381-- slaveof 16379 sentinel1: image: redis:4.0 restart: always container_name: redis-sentinel-1 network_mode: "host" # specify sentinel file location command: redis-sentinel / usr/local/etc/redis/sentinel.conf # use volume mapping files to the specified sentinel location volumes: -. / sentinel/sentinel1.conf:/usr/ Local/etc/redis/sentinel.conf sentinel2: image: redis:4.0 restart: always container_name: redis-sentinel-2 network_mode: "host" command: redis-sentinel / usr/local/etc/redis/sentinel.conf volumes: -. / sentinel/sentinel2.conf:/usr/local/etc/redis/sentinel.conf sentinel3: image: redis:4.0 restart: always container_name: redis-sentinel-3 network_mode: "host" command: redis-sentinel / usr/local / etc/redis/sentinel.conf volumes: -. / sentinel/sentinel3.conf:/usr/local/etc/redis/sentinel.conf

4. Use centos to deploy the cluster test effect.

1. Test the connection to the cluster through sentinel1

2. Test the data synchronization of master node and child node.

3. Close master to view the switch between master and slave

Sentinel normal Unicom

The primary node is switched from 16379 to 16381

End

After a week of laziness after the Dragon Boat Festival, a sentinel cluster was built before. Due to the problem of docker network model, the cluster could not be connected after the master / slave nodes were switched. Yesterday, when I saw that host could not be implemented on window, I tested it on centos.

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report