当前位置:网站首页>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 .
边栏推荐
- Xshell connecting VMware virtual machines
- Sword finger offer II 014 A sliding window of anagrams in strings
- Win10开启热点共享后断网怎么解决?
- 项目经理在项目中起到的作用
- [efficiency] another note artifact is open source!
- How does LSF see whether the job reserved slot is reasonable?
- [matlab] data statistical analysis
- 剑指 Offer II 035. 最小时间差
- How Jerry used to output a clock source to the outside world [chapter]
- WARNING: Unsupported upgrade request.
猜你喜欢

A development of student management system based on PHP
![[compilation principle] overview](/img/af/246750beb72842e83a19e42270c09e.png)
[compilation principle] overview

Assembly language (5) register (memory access)

How does social e-commerce operate and promote?

匯編語言(5)寄存器(內存訪問)

杰理之增加加密文件播放功能【篇】

Old mobile phones turn waste into treasure and serve as servers

杰理之系统时钟设置出现复位或无效问题【篇】

【编译原理】词法分析

杰理之如何给外界输出一个时钟源使用【篇】
随机推荐
SnakeYAML配置文件解析器
Precautions for using Jerry's timer [chapter]
软考中级和高级选哪个比较好?
How do components communicate
杰理之adc_get_voltage 函数获取电压值不准【篇】
【编译原理】词法分析
Xshell connecting VMware virtual machines
How high does UART baud rate require for clock accuracy?
golang sort slice int
IDEA全局搜索汉字[通俗易懂]
[matlab] curve fitting
Under the same WiFi, the notebook is connected to the virtual machine on the desktop
DDD concept is complex and difficult to understand. How to design code implementation model in practice?
WPF development essays Collection - ECG curve drawing
ES6 knowledge points
golang sort slice int
华为云GaussDB(for Redis)揭秘第19期:GaussDB(for Redis)全面对比Codis
Precautions for use of Jerry's SPI slave [chapter]
How smart PLC constructs ALT instruction
js禁止浏览器默认事件