Redis master-from deployment practices
0. Preface
This article provides a brief introduction to Redis's master-slave deployment, which implements a primary two-from, using two Sentinel monitors to achieve simple ha, which is used from the library as a standby machine.
1. Deployment
There are three servers, with Redis as the main library on 239 hosts and the remaining two as slave libraries. Authentication is involved here, so when Requirepass and Masterauth are used both in the main library and from the library, because when the main library goes down, the Sentinel will require authentication when one of them is promoted from the library to the primary library, and for simplicity, the configuration file uses the same configuration and password.
239 configuration involved in the main library:
Requirepass Messagequeuemasterauth MessageQueue
Related configurations are involved from the library:
Slaveof 172.16.17.239 6379masterauth Messagequeuerequirepass MessageQueue
Configuration of two Sentinels:
Sentinel Monitor Gateway 172.16.17.239 6379 2sentinel Auth-pass Gateway MessageQueue
As the final deployment diagram.
After the final deployment can be viewed through the REDIS-CLI connection sentry.
As shown: You can see the IP and port of the main library, the number of slave machines and the number of Sentinels
2. Detailed configuration instructions for Sentinel:
#端口号port 26379# dir <working-directory>dir/tmp# monitoring master database Sentinel Monitor Gateway 172.16.17.239 6379 * Certified Password Sentinel a Uth-pass Gateway messagequeue# Send ping interval, greater than 1 seconds at 1 second intervals, less than 1 seconds at configured intervals Sentinel Down-after-milliseconds Gateway 30000# Simultaneous reconfiguration of slave during disaster recovery # when the slave is used for querying, it is used to ensure that a certain amount of slave can continue to service at the time of the disaster preparation. Sentinel Parallel-syncs Gateway # 1. The time to re-make the recovery after the last attempt to recover # 2. From the machine, depending on the Sentinel, the time required to replicate a correct host from a wrong host, that is, the recovery time-out. # 3. The time to cancel the disaster, that is, slaveof no one is sent to the slave, and the slave is not answered and timed out. # 4. Maximum time for all slave configuration points to the host (Total disaster recovery time) # 3 min Sentinel failover-timeout Gateway 180000# script has a maximum run time of 60 seconds, and when the script termination code is 1 it means that the failure is re-executed (up to 10 times by default), For the 2 O'Clock Table Success # notification script to notify the administrator (via Sms,email, etc.) # The script passes in two parameters, the first one is the event type, the second is the event description # Sentinel Notification-script mymaster/var/redis/ notify.sh# Client reconfiguration scripts (scripts should be reentrant) # perform some specific tasks when using the main library change, such as notifying client master library changes. # Sentinel Client-reconfig-script <master-name> <script-path># The following parameters are passed to script # <master-name> <role > <state> <from-ip> <from-port> <to-ip> <to-port>## <state> always "failover" # < Role> is "leader" or "Observer" # FROM-IP/FROm-port for old database address # To-ip/to-port to change the original library address # Sentinel Client-reconfig-script mymaster/var/redis/reconfig.sh
3. Sentinel Applications
Sentinel provides methods for querying the main library after a disaster is switched to the main library.
1. As on the configuration file, you can use scripting to notify.
2. You can use Sentinel Master <master_name> to query by connecting Sentinel (where Master_name is the gateway behind Sentinel Monitor for the above Sentinel profile).
The following local code (using the Hiredis library, after the connection to use the AUTH command authentication to operate):
1 const char *pcommand = "SENTINEL master%s"; 2 redisreply *preply = (redisreply*) Rediscommand (prediscontext-& Gt;pcontext, Pcommand, pmastername); 3 4 if (NULL! = preply) 5 {6 if (Redis_reply_array = = Preply->type && preply->elements ; = 5) 7 {8 Nmasteriplen = Redis_min (Preply->element[3]->len); 9 memcpy (Pmasterip, preply-> Element[3]->str, Nmasteriplen); Pmasterip[nmasteriplen] = ' atoi '; *pmasterport ELEMENT[5]->STR); nret = redis_success;13 }14 freereplyobject (preply);
4. Summary
As shown in the deployment is mainly used for a company project, implemented in a simple message queue, where there are no other open source message queues (such as ACTIVEMQ,ZEROMQ,RABBITMQ, etc.) there are some other factors in.
Category: Redis
Deploy Redis Master-from