当前位置:网站首页>18_ Redis_ Redis master-slave replication & cluster building
18_ Redis_ Redis master-slave replication & cluster building
2022-07-02 15:20:00 【Listen to the rain】
Master slave replication concept
Master slave copy , It means to put one Redis Server data , Copy to other Redis The server . The former is called the main node (master/leader), The latter is called the slave node (slave/follower); Data replication is one-way , From master to slave only .Master Write first ,Slave Mainly reading .
By default , Each station Redis Servers are all primary nodes ; And a master node can have multiple slave nodes ( Or no slave ), But a slave node can only have one master node .( A father can have many sons , But a son has only one father )
The main functions of master-slave replication include :
- 1、 data redundancy ︰ Master-slave replication realizes hot backup of data , It's a way of data redundancy beyond persistence .
- 2、 Fault recovery ∶ When there is a problem with the master node , Can be served by a slave node , Fast fault recovery ; It's actually a redundancy of services .
- 3、 Load balancing ∶ On the basis of master-slave replication , Cooperate with the separation of reading and writing , Write service can be provided by the master node , Read service provided by slave node ( The write Redis Connect master node when data is applied , read Redis Apply connection from node when data ), Share server load ; Especially in the situation of less writing and more reading , Sharing read load through multiple slave nodes , Can be greatly improved Redis Concurrency of servers .
- 4、 High availability ( colony ) footstone ∶ In addition to the above functions , Master slave replication is also the foundation for sentinels and clusters to implement , So master-slave replication is Redis High availability Foundation .
Generally speaking , To put Redis Used in engineering projects , Use only one Redis Absolutely not , Here's why ︰
- 1、 Structurally , Single Redis The server will have a single point of failure , And a server needs to handle all the request loads , pressure ;
- 2、 In terms of capacity , Single Redis Server memory capacity is limited , Even if it's a Redis The memory capacity of the server is 256G, You can't use all the memory Redis Storage memory , Generally speaking , A single Redis The maximum memory used should not exceed 20G.
Products on e-commerce websites , It's usually a upload , Countless times , To say professional is to say " Read more and write less ".
For this scenario , We can make the following Architecture ︰
Master slave copy , Read / write separation ! 80% In this case, they are all reading operations ! Master Write first ,Slave Mainly reading , Slow down the pressure on the server ! Architecture often uses
Cluster environment configuration
Only configure slave Libraries , No need to configure the main library !
127.0.0.1:6379> info replication // View the current library information
//# Replication
role:master // Information about the current library : Default master
connected_slaves:0 // No slave
master_failover_state:no-failover
master_replid:ab08b135b40fc3d1b0a710e52776d1aa485ce1de
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
Copy 3 Configuration files , Then modify the corresponding information
- 1、 port
- 2、pid name
- 3、log File name
- 4、dump.rdb name
Modify the host configuration file : vim redis79.conf
Modify the slave configuration file :vim redis80.conf
Modify the slave configuration file :vim redis81.conf
The application scenario at this time is Single machine multi cluster : Deploy multiple servers on one server redis service
After modifying the configuration file , Start our 3 individual redis The server , You can view through the process information !
Cluster building : One master and two subordinates
By default , Each station Redis Servers are all primary nodes ; In general, we only need to configure the slave machine !
Command build
Configure slave : Recognize the boss ! A master (6379) Two from (6380,6381)
Configuration command : Execute the command in the slave :SLAVEOF 127.0.0.1 6379
The real slave master configuration should be configured in the configuration file , It's permanent , We're using commands here , Temporary
Configuration file setup
details
The host can write , The slave can't write , Only read ! All the information and data in the host , Will be automatically saved by the slave machine !
Host write :
The slave can only read the content :
Test questions :
- The host is disconnected , The slave is still connected to the host , But because only the host can write , There is no write operation after the host goes down , This is the time , If the mainframe comes back , The slave can still get the information written by the host directly !
- If you use the command line , To configure the master-slave , If the slave is restarted at this time , The slave will change back to the host ! As long as you use the command again, it becomes a slave , Immediately you get the value from the host !
Master slave replication principle :
Slave( Slave ) Start successfully connected to master( host ) A... Will be sent later sync( Sync ) command
Master Received orders , Start the background storage process , At the same time, collect all received commands for modifying the dataset , After the background process is finished ,master Will transfer Whole Data file to slave, And complete a full synchronization .
Copy in full : and slave The service receives the database file data , Save it and load it into memory .
Incremental replication :Master Continue to pass all new collected modification commands to slave, Complete synchronization
But just reconnect master, One full synchronization ( Copy in full ) Will be executed automatically . We can see it in the data machine !
边栏推荐
- MFC timer usage
- JVM architecture, classloader, parental delegation mechanism
- Application of CDN in game field
- [c voice] explain the advanced pointer and points for attention (2)
- TiDB 软件和硬件环境建议配置
- FPGA - clock-03-clock management module (CMT) of internal structure of 7 Series FPGA
- MFC 控制台打印,弹出对话框
- 实用调试技巧
- Tidb hybrid deployment topology
- 记一次面试
猜你喜欢
[C language] explain the initial and advanced levels of the pointer and points for attention (1)
GeoServer offline map service construction and layer Publishing
c语言入门--数组
07_哈希
.NET Core 日志系统
vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)
kibana 基础操作
List集合&UML图
16_Redis_Redis持久化
The past and present lives of visual page building tools
随机推荐
基于RZ/G2L | OK-G2LD-C开发板存储读写速度与网络实测
vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)
C # delay, start the timer in the thread, and obtain the system time
LeetCode_ Sliding window_ Medium_ 395. Longest substring with at least k repeated characters
Record an interview
C language exercises - (array)
Dragonfly low code security tool platform development path
记一次面试
About text selection in web pages and counting the length of selected text
Application and practice of Jenkins pipeline
20_Redis_哨兵模式
哈夫曼树:(1)输入各字符及其权值(2)构造哈夫曼树(3)进行哈夫曼编码(4)查找HC[i],得到各字符的哈夫曼编码
Tidb hybrid deployment topology
How does CTO help the business?
MFC console printing, pop-up dialog box
实用调试技巧
传感器数据怎么写入电脑数据库
Table responsive layout tips
02_ Linear table_ Sequence table
4. Data splitting of Flink real-time project