Redis sentry mode principle
Redis Sentry Mode Principle
Sentinel mode is a special mode. First of all, Redis provides the sentinel command. The sentinel is an independent As a process, it will run independently. The principle is that the sentinel monitors multiple running Redis instances by sending commands and waiting for the Redis server to respond.
Linux - redis sentinel cluster instance
Command arrangement
Official website address: http://redisdoc.com/
redis-cli info #查看redis数据库信息 redis-cli info replication #查看redis的复制授权信息 redis-cli info sentinel #查看redis的哨兵信息
Configuration process
Ideas:
redis master-slave
一Master and two slaves plan
1. Environment preparation, prepare the redis architecture of one master and two slaves
redis-6379.conf
port 6379 daemonize yes logfile "6379.log" dbfilename "dump-6379.rdb" dir "/opt/redis/6379/" redis-6380.conf port 6380 daemonize yes logfile "6380.log" dbfilename "dump-6380.rdb" dir "/opt/redis/6380/" slaveof 127.0.0.1 6379 redis-6381.conf port 6381 daemonize yes logfile "6381.log" dbfilename "dump-6381.rdb" dir "/opt/redis/6381/" slaveof 127.0.0.1 6379
2. Prepare three data folders
mkdir -p /opt/redis/{6379,6380,6381}
3. Start three databases respectively
[root@master sbredis]# redis-server redis-6379.conf [root@master sbredis]# redis-server redis-6380.conf [root@master sbredis]# redis-server redis-6381.conf
4. Detect the master-slave status
redis-cli -p 6379 info replication redis-cli -p 6380 info replication redis-cli -p 6381 info replication
5. Prepare three redis sentinels to detect the master-slave status
Prepare the configuration of the three sentinels File
redis-26379.conf
// Sentinel节点的端口 port 26379 dir /var/redis/data/ logfile "26379.log" // 当前Sentinel节点监控 192.168.119.10:6379 这个主节点 // 2代表判断主节点失败至少需要2个Sentinel节点节点同意 // mymaster是主节点的别名 sentinel monitor mymaster 192.168.119.10 6379 2 //每个Sentinel节点都要定期PING命令来判断Redis数据节点和其余Sentinel节点是否可达,如果超过30000毫秒30s且没有回复,则判定不可达 sentinel down-after-milliseconds mymaster 30000 //当Sentinel节点集合对主节点故障判定达成一致时,Sentinel领导者节点会做故障转移操作,选出新的主节点, 原来的从节点会向新的主节点发起复制操作,限制每次向新的主节点发起复制操作的从节点个数为1 sentinel parallel-syncs mymaster 1 //故障转移超时时间为180000毫秒 sentinel failover-timeout mymaster 180000 redis-26380.conf port 7000 daemonize yes dir "/opt/data" logfile "7000.log" dbfilename "dump-7000.rdb" cluster-enabled yes cluster-config-file nodes-7000.conf cluster-require-full-coverage no redis-26381.conf
Three configuration files, only the port is different, quickly generate the configuration file through the command
[root@master sbredis]# sed "s/26379/26380/g" redis-26379.conf > redis-26380.conf [root@master sbredis]# sed "s/26379/26381/g" redis-26379.conf > redis-26381.conf
6. Start three sentinels respectively
[root@master sbredis]# redis-sentinel redis-26379.conf [root@master sbredis]# redis-sentinel redis-26380.conf [root@master sbredis]# redis-sentinel redis-26381.conf
7. Detect the sentinel, master-slave status
redis-cli -p 26379 info sentinel
When you see the following information, you are like me
[root@master sbredis]# redis-cli -p 26379 info sentinel Sentinel sentinel_masters:1 sentinel_tilt:0 sentinel_running_scripts:0 sentinel_scripts_queue_length:0 sentinel_simulate_failure_flags:0 master0:name=s17ms,status=ok,address=127.0.0.1:6379,slaves=2,sentinels=3
8. Test, kill the master redis, and see if it switches automatically
ps -ef|grep redis kill 进程 ..
9. Start redis 6379 again to see if it has joined the master-slave cluster
redis-server redis-6379.conf
Recommended tutorial: "Redis Tutorial"
The above is the detailed content of Redis sentry mode principle. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Redis cluster mode deploys Redis instances to multiple servers through sharding, improving scalability and availability. The construction steps are as follows: Create odd Redis instances with different ports; Create 3 sentinel instances, monitor Redis instances and failover; configure sentinel configuration files, add monitoring Redis instance information and failover settings; configure Redis instance configuration files, enable cluster mode and specify the cluster information file path; create nodes.conf file, containing information of each Redis instance; start the cluster, execute the create command to create a cluster and specify the number of replicas; log in to the cluster to execute the CLUSTER INFO command to verify the cluster status; make

How to clear Redis data: Use the FLUSHALL command to clear all key values. Use the FLUSHDB command to clear the key value of the currently selected database. Use SELECT to switch databases, and then use FLUSHDB to clear multiple databases. Use the DEL command to delete a specific key. Use the redis-cli tool to clear the data.

To read a queue from Redis, you need to get the queue name, read the elements using the LPOP command, and process the empty queue. The specific steps are as follows: Get the queue name: name it with the prefix of "queue:" such as "queue:my-queue". Use the LPOP command: Eject the element from the head of the queue and return its value, such as LPOP queue:my-queue. Processing empty queues: If the queue is empty, LPOP returns nil, and you can check whether the queue exists before reading the element.

Using the Redis directive requires the following steps: Open the Redis client. Enter the command (verb key value). Provides the required parameters (varies from instruction to instruction). Press Enter to execute the command. Redis returns a response indicating the result of the operation (usually OK or -ERR).

Using Redis to lock operations requires obtaining the lock through the SETNX command, and then using the EXPIRE command to set the expiration time. The specific steps are: (1) Use the SETNX command to try to set a key-value pair; (2) Use the EXPIRE command to set the expiration time for the lock; (3) Use the DEL command to delete the lock when the lock is no longer needed.

The best way to understand Redis source code is to go step by step: get familiar with the basics of Redis. Select a specific module or function as the starting point. Start with the entry point of the module or function and view the code line by line. View the code through the function call chain. Be familiar with the underlying data structures used by Redis. Identify the algorithm used by Redis.

Redis, as a message middleware, supports production-consumption models, can persist messages and ensure reliable delivery. Using Redis as the message middleware enables low latency, reliable and scalable messaging.

The steps to start a Redis server include: Install Redis according to the operating system. Start the Redis service via redis-server (Linux/macOS) or redis-server.exe (Windows). Use the redis-cli ping (Linux/macOS) or redis-cli.exe ping (Windows) command to check the service status. Use a Redis client, such as redis-cli, Python, or Node.js, to access the server.
