redis learning (D) from the main structure and mechanism Sentinel

What is a master-slave structure

As shown, there may be a plurality of master server from the server, the server may also have the following from the server, which is redis the cascade structure. The primary server when the data is changed, to synchronize data from the server, maintaining data consistency weak.

 

Why redis to build a master-slave structure

From the point of view of personal understanding

1, the main server to reduce the pressure , due to the periodically synchronize data from the server to the main server, so when we read data during operation, can be accessed from the server, only need to access the main server at the time of writing operation, greatly reducing the primary server pressure

2, to prevent the primary server goes down and crash the service , once the primary server goes down, if not from the server, all requests will be playing in the relational database, is likely to cause an avalanche cache, has from the server, through the mechanism Sentinel, We can re-elect a master server, the previous master server after the restart as you can run from the server. Greatly enhanced the robustness of the service

 

Sentinel mechanism

As the name suggests, that is used to sentry sentry, sentries through periodic ping to determine whether the server is running well, just said all levels of server, Sentinel mechanism can come out from the server in the election of a new primary server after the primary server goes down, If there is a problem from the server, and then only need to restart the primary server to re-establish the association.

We usually use more common sentry monitor a set of servers, in order to prevent the main server may not be because of some minor problems caused by Sentinel to ping replace the main server. In the case of multi-Sentinel, the Sentinel found that when a problem, it will make a similar poll of the work, after other guards will try to ping a server failure, and then draw their own conclusions, when considered sentinels reaches a certain server downtime standard, will take action.

 

Sentinel from the main building +

We understand the principle almost, after you try to build a master-slave + Sentinel service

Here a selection of built from two main

The main server configuration file using the default, do not show, attention Sentinel master-slave synchronization mode can not bind 127.0.0.1 and 0.0.0.0, the primary server goes down or can not get to vote the new master

Follows from the configuration server, create a new file, note the suffix .conf

# 使得Redis服务器可以跨网络访问
bind 0.0.0.0
# 设置密码
requirepass "123456"
# 指定主服务器,注意:有关slaveof的配置只是配置从服务器,主服务器不需要配置
slaveof 192.168.43.38 6379
# 主服务器密码,注意:有关slaveof的配置只是配置从服务器,主服务器不需要配置
masterauth 123456

#启动端口
port 6079

Next we try to start it: Start command redis-server.exe + configuration file , as shown below, to start the server from the same command, replacing the configuration files

Print out the information from the main server can see both 6079 and 6179 associated with the success of the port from the server to the main server, and then we test

redis-cli.exe command to enter the primary server, if there are additional parameters to remember a password -a, as for example: redis-cli.exe -a 123456

Setting a aaa key, a value of 111

Entering a view from any server, pay attention to enter from the server need to add -p parameter from the server port number

 Can be found to get this value, indicating that my Lord from the completed structures

 

Next we set up sentries, the new document, called the suffix .conf

sentinel myid 859fe0cf486ce0872bc03a3ab74d342e153d87b6
#监听主服务器
sentinel monitor mymaster 192.168.43.38 6079 1
sentinel down-after-milliseconds mymaster 500
#超时设置
sentinel failover-timeout mymaster 1500
sentinel auth-pass mymaster 123456
protected-mode no
# Generated by CONFIG REWRITE
port 26379
#文件位置
dir "D:\\redis"
sentinel config-epoch mymaster 4051
sentinel leader-epoch mymaster 4051
#监听的从服务器
sentinel known-slave mymaster 192.168.43.38 6379
sentinel known-slave mymaster 192.168.43.38 6179
sentinel current-epoch 4051

 

Start clicking Sentinel

And then try to turn off the main server

You can see, was chosen as the new master server in the server port 6079 

carry out

Published 41 original articles · won praise 75 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_44407699/article/details/104788764