当前位置:网站首页>Sentinel sentinel mechanism
Sentinel sentinel mechanism
2022-06-25 17:32:00 【Hua Weiyun】
Sentinel Sentinel mechanism
The sentinel mechanism is Redis Enable highly available solutions : By one or more Sentinel Examples of Sentinel The system can monitor any number of master and slave servers , If the primary server goes offline ,Sentinel Automatically upgrade the slave server under the offline master server to a new master server , The master server of the alternative principle continues to process command requests , After the offline master server is restored, it is set as the slave server of the new master server
Start and initialize Sentinel
When one Sentinel Startup time , The following steps are required
1. Initialize server
Sentinel The essence is a system that operates in a special mode Redis The server , start-up Sentinel The first step is to initialize a normal Redis The server , Normal servers are initialized by loading RDB Documents or AOF File to restore database state , But because Sentinel Do not use databases , So initialization Sentinel It doesn't load RDB Documents or AOF file
2. Will be ordinary Redis Replace the code used by the server with Sentinel Special code
Ordinary Redis The common port is 6379,Sentinel The common port is 26379
Sentinel Server command table :sentinel.c Of sentinelcmds
struct redisCommand sentinelcmds[] = { {"ping",pingCommand,1,"",0,NULL,0,0,0,0,0}, {"sentinel",sentinelCommand,-2,"",0,NULL,0,0,0,0,0}, {"subscribe",subscribeCommand,-2,"",0,NULL,0,0,0,0,0}, {"unsubscribe",unsubscribeCommand,-1,"",0,NULL,0,0,0,0,0}, {"psubscribe",psubscribeCommand,-2,"",0,NULL,0,0,0,0,0}, {"punsubscribe",punsubscribeCommand,-1,"",0,NULL,0,0,0,0,0}, {"info",sentinelInfoCommand,-1,"",0,NULL,0,0,0,0,0}};Command table only 7 An order , Better than average redis The command list of the server is much less
3. initialization Sentinel state
Server initialization sentinelState structure , This structure holds all and Sentinel Function related states
/* Main state. */struct sentinelState { dict *masters; /* Dictionary of master sentinelRedisInstances. Key is the instance name, value is the sentinelRedisInstance structure pointer. */ int tilt; /* Are we in TILT mode? */ int running_scripts; /* Number of scripts in execution right now. */ mstime_t tilt_start_time; /* When TITL started. */ mstime_t previous_time; /* Time last time we ran the time handler. */ list *scripts_queue; /* Queue of user scripts to execute. */} sentinel;4. According to the given profile , initialization Sentinel The list of monitoring primary servers .
Sentinel Of masters The dictionary records all the Sentinel Information about the monitored master server , Where the key of the dictionary is the name of the monitored master server , The value of the dictionary corresponds to the monitored master server sentinelRedisInstance structure . Every sentinelRedisInstance The structure represents a quilt Sentinel Monitored Redis Server instance
Sentinel Initialization of raises a pair of masters Initialization of a dictionary ,masters The beginning of the dictionary is based on what is loaded Sentinel Configuration file to do .
5. Create a network connection to the primary server
Sentinel Two... Connected to the primary server will be created Asynchronous network connection : One is command connection , Dedicated to sending commands to the primary server , And receive command reply , One is subscription connection , For subscribing to the master server _sentinel_:hello channel
Sentinel You need to create multiple network connections with multiple instances , therefore Sentinel Asynchronous connection is used .
️ Thank you for your
If you think this is helpful for you :
- Welcome to follow me ️, give the thumbs-up , Comment on , forward
- Focus on
Panpan small class, Push good articles for you regularly , There are also group chat and irregular lottery activities , You can say what you want , Communicate with the great gods , Learning together . - If there is anything inappropriate, you are welcome to criticize and correct .
边栏推荐
- 学习太极创客 — MQTT(一)MQTT 是什么
- Precautions for use of Jerry's SPI slave [chapter]
- The role of the project manager in the project
- 旧手机变废为宝,充当服务器使用
- TCP chat + transfer file server server socket v2.8 - fix 4 known problems
- 单例模式应用
- How does social e-commerce operate and promote?
- Sword finger offer II 025 Adding two numbers in a linked list
- UART波特率对时钟精度的要求有多高?
- 剑指 Offer II 035. 最小时间差
猜你喜欢

Singleton mode application

Mathematical modeling - linear programming

记一次基于PHP学生管理系统的开发

Create a new ar fashion experience with cheese and sugar beans

Redis distributed lock collation

STM32 hardware error hardfault_ Handler processing method

CVPR small target detection: context and attention mechanisms improve small target detection (attached with paper Download)

杰理之唤醒口使用注意事项【篇】

Learn Tai Chi Maker - mqtt (III) connect to mqtt server

超全金属PBR多通道贴图素材网站整理
随机推荐
学习太极创客 — MQTT(一)MQTT 是什么
golang sort slice int
杰理之SPI 从机使用注意事项【篇】
Old mobile phones turn waste into treasure and serve as servers
Super Full Metal PBR Multi - channel Mapping Materials website collation
学习太极创客 — MQTT(二)MQTT 基本原理
What are the steps for launching the mobile ERP system? It's important to keep it tight
WARNING: Unsupported upgrade request.
Singleton mode application
On Web 3.0
Good fat man takes you to learn Flink series -flink source code analysis episode I standalone startup script analysis
[compilation principle] overview
超全金屬PBR多通道貼圖素材網站整理
汇编语言(5)寄存器(内存访问)
华为云GaussDB(for Redis)揭秘第19期:GaussDB(for Redis)全面对比Codis
上线移动ERP系统有哪些步骤?环环紧扣很重要
数学建模——非线性规划
Distinguishing seven kinds of facial expressions by deep separable convolution neural network
Precautions for using timer_cap.c of Jerry [chapter]
Kotlin