当前位置:网站首页>[introduction series of redis] redis builds master-slave servers
[introduction series of redis] redis builds master-slave servers
2022-07-23 17:24:00 【Hall owner a Niu】
Personal profile
- Author's brief introduction : Hello everyone , I'm Daniel , New star creator of the whole stack .
- Stand by me : give the thumbs-up + Collection ️+ Leaving a message.
- Series column : Punching and kicking database
- Maxim : To be light , Because there are people who are afraid of the dark !

Catalog
Preface
In reality , Server downtime is very common , Server downtime , our redis The service stopped naturally , It has great security risks , therefore redis It is necessary to build master-slave servers , It can not only realize the separation of reading and writing , It can also form a powerful multi-level server cluster architecture !
The concept of master-slave
- One master You can have multiple slave, One slave You can have more than one slave, Go on like this , A powerful multi-level server cluster architecture can be formed .
- master To write data ,slave To read data , Statistics : The reading and writing ratio of the website is 10:1, Therefore, it is necessary to build master-slave .
- Read and write separation can be realized through master-slave configuration .

notes :master and slave It's all one redis example (redis service ), The slave server can synchronize the data of the master server through the logging mechanism .
Build master slave (windows System )
Here I set up a slave server , Multiple operation methods are the same !
Pictured , Put your redis Make a copy of the directory and put it in the same folder , Let one be the main service for , The other is when the slave server .
For the master server , Don't make any changes , What needs to be changed is Redis-Slave From the configuration file in the server .
open Redis-Slave Inside redis.windows.conf
You can see bind The binding of ip as well as port Port number , Because it is built on the same computer , therefore ip Don't modify , In the future, I will encounter multiple computers , Just on this basis ip It can also be changed to the corresponding computer .
Because both servers are under the same system of the same computer ,bind It's all local. IP Address 127.0.0.1, Two independent Redis example , We can make the ports different , Then you can start it independently .
Pictured , We set the port number of the slave server to 6378
It's set up from the server , Next is master-slave Redis Service binding , Start the master-slave service .
open Redis-slave Profile in folder , stay port Add a line below the line , Used to bind the primary server IP Address and port port :
slaveof 127.0.0.1 6379

Master slave after saving Redis Service binding is complete !
At the same time, in order to prevent the conflict between the master server and the slave server , Here we will configure rename from the server ( because redis-server The default is redis.windows.conf).
At this time, the command to start from the server is :
redis-server redis.windows-slave.conf

test
Start the master-slave server


You can see that the startup is successful and the master-slave binding is also ok Of ·, Next, start their respective clients .
In order to prevent conflict , Add the port number when starting :
Lord :redis-cli -p 6379
from :redis-cli -p 6378


Client started successfully !
Next, we test the read-write synchronization and separation of master-slave Services :

Pictured , We added a field in the main server , Let's see if we can read from the server :

Sure , There is no problem with master-slave synchronization !
We know that the slave server is read-only , Let's verify :

You can see that the test was successful , Cannot write from server !
Conclusion
If you think the blogger's writing is good , You can pay attention to the current column , Bloggers will finish this series ! You are also welcome to subscribe to other good columns of bloggers .
Series column
Soft grinding css
Hard bubble javascript
flask Framework quick start
边栏推荐
猜你喜欢
随机推荐
Fundamentals of C language -- 2-6 pointers, arrays and sizeof operators
SQL报错盲注详解
排序-介绍,代码思路,使用建议,代码实现-1
Lake Shore - empx-h2 low temperature probe station
Vscode - code and file changes cannot be saved
Function secondary development / plug-in development of JMeter (detailed version)
虚拟机网络连接方式
Wechat applet class binding, how to bind two variables
常见模拟电路设计 一(含仿真):方波、三角波、正弦波的互相发生「建议收藏」
Could not load dynamic library ‘cudnn64_ 8.dll‘; dlerror: cudnn64_ 8.dll not found
[mysql] I. MySQL starts
动态库*.dll文件的Debug/Release版本是否可以混用(交叉用)?
keil错误和解决办法(1):FCARM - Output Name not specified, please check ‘Options for Target - Utilities‘
Eureka notes
Agile testing practice in large-scale teams
Detailed explanation of SQL bool blind note and time blind note
Shrimp noodles: what do you know about the JVM memory layout?
IDEA中给项目添加依赖的jar包
【Flutter -- 布局】弹性布局(Flex 和 Expanded)
Solution for iPhone unable to open openv** file







![[30. N-queen problem]](/img/ed/7e2832695613c16da034f05bd4040b.png)