The content of the invention
In view of the deficiencies of the prior art, the present invention provides a kind of Redis high-availability systems and method based on QConf, base
Application program and Redis databases can be thoroughly decoupled in QConf, no matter Redis databases do any change, and application program is equal
Database relevant configuration need not be changed.Meanwhile based on sentry's cluster, it is possible to achieve Redis database failures automatically switch, from
And realize the High Availabitity of Redis database services.
The purpose of the present invention is achieved through the following technical solutions:A kind of Redis High Availabitities system based on QConf
System, the system include QConf management ends, QConf clients, QConf service ends, sentry's clustered node and Redis replica nodes.
QConf clients:The server of QConf agent service and QConf extensions is run, meanwhile, application program also portion
Administration is in QConf clients;Major function is interacted with QConf service ends, obtains newest QConf service nodes and parsing institute
State QConf service nodes.
QConf service ends:The zookeeper clusters of QConf service nodes are stored, the zookeeper clusters typically wrap
Include odd number member, and number of members at least three.By QConf management ends, registered to QConf service ends or update QConf clothes
Business node.
QConf management ends:QConf monitoring services and QConf administration extensions are disposed, are monitored by QConf monitoring services
The survival of all QConf service nodes of QConf service ends;By QConf administration extensions, QConf service ends it is newly-increased or
Update QConf service nodes;Ordinary circumstance, keeper are responsible for safeguarding QConf management ends.
Sentry's clustered node:The server of sentry's cluster is run, sentry's cluster generally comprises odd number member, and into
Member's number at least three;Sentry's cluster is responsible for monitoring master library and the survival from storehouse in Redis duplication clusters, if Redis master libraries
Break down, sentry's cluster triggers the switching of Redis master libraries automatically, produces new Redis master libraries;One sentry's cluster can monitor
One or more Redis replicates cluster.
Redis replica nodes:The server that Redis replicates cluster is run, the Redis replicates cluster, generally comprises one
Individual Redis master libraries, one or more Redis is from storehouse;Each Redis replicates cluster, different using port numbers unique mark
Redis replicates cluster, and port numbers are different.
Further, sentry's clustered node includes sentry's cluster management module, and sentry's cluster management module needs
The parameter to be passed to:Redis master libraries ip, sentry's cluster ports and redis master library identifiers.
Further, the QConf management ends include QConf service nodes management module and QConf service nodes monitor
Module;
The QConf service nodes management module needs incoming parameter:Zookeeper clusters connection string, QConf
The ip and port of service node and all members of sentry's cluster;
The QConf service nodes monitoring module needs incoming parameter:Zookeeper cluster connection strings.
Further, the QConf clients include QConf service nodes parsing module, sentry's parsing module and application
Routine access module;
The QConf service nodes parsing module needs incoming parameter:QConf service nodes;
Sentry's parsing module needs incoming parameter:Sentinel node ip, sentry's cluster ports and Redis master libraries mark
Symbol;
The application program access modules need incoming parameter:The ip of Redis master libraries, Redis replicate the port of cluster
And password.
A kind of Redis high availability methods based on QConf, this method include:
(1) sentry's cluster management module is called, replicates cluster in Redis replica nodes deployment Redis, while collect in sentry
Group node disposes sentry's cluster, replicates cluster for monitoring Redis, if Redis master libraries break down, sentry's cluster can be certainly
Row switching Redis master libraries, realize Redis master library High Availabitities.
(2) QConf service node management modules are called, zookeeper clusters and QConf administration extensions is disposed, passes through PHP
Application call QConf administration extensions interfaces, sentry's cluster QConf service nodes corresponding to are registered in QConf service ends.
By QConf administration extensions interfaces, it can be increased, updated and be checked newly operation to the QConf service nodes.
(3) QConf service node monitoring modules are called, starts QConf monitoring services in QConf management ends, monitors QConf
The viability of sentinel node corresponding to all QConf service nodes in service end, ensure the whistle that application program is got every time
Soldier's node is available.
(4) QConf service node parsing modules, after QConf service node management module end of runs, sentry's cluster are called
QConf service nodes corresponding to being registered to.Then, application program is called corresponding to QConf according to the QConf service nodes
Expansion interface, the ip of one sentinel node of return and port.
If in QConf service ends, the QConf service nodes are updated, zookeeper clusters can be automatically by
QConf agent are serviced, and ensure that the sentinel node that application program is got every time is newest.
(5) call sentry's parsing module, according to QConf service nodes parsing module return the sentinel node ip and
Port, Redis expansion interfaces corresponding to application call, the ip of return Redis master libraries and port.
(6) call application program access modules, according to call sentry's parsing module return the Redis master libraries ip and
Port, Redis expansion interfaces corresponding to application call, Redis connections are established, so as to Redis read-write requests.
The beneficial effects of the invention are as follows:
(1) framework simple and stable:Redis High Availabitities framework proposed by the present invention is both simple and stable, greatly improves
The availability of Redis databases..
(2) maintenance cost is low:Because High Availabitity framework proposed by the present invention is simple, it is highly convenient for safeguarding, and cost is very
It is low.
(3) technology maturation, reliability are high:Realize that Redis principals and subordinates are automatically switched using sentry's pattern, technology maturation, use
QConf is reliable and stable as intermediate layer.
Embodiment
The present invention is described in further detail with specific embodiment below in conjunction with the accompanying drawings.
As shown in figure 1, a kind of Redis high-availability systems based on QConf provided by the invention, the system include QConf
Five management end, QConf clients, QConf service ends, sentry's clustered node and Redis replica nodes units.
(1) Redis replica nodes
Redis is disposed on multiple servers and replicates cluster, in order to ensure Redis service availabilities, Redis master libraries and
Redis is run on different server respectively from storehouse.The port numbers that each Redis replicates all members of cluster are consistent, different
Redis replicates cluster, and port numbers are different.After Redis replicates clustered deploy(ment), next interacted with sentry's clustered node, it is real
The High Availabitity of existing Redis database services.
(2) sentry's clustered node
Sentry's cluster is run on multiple servers, sentry's cluster member is odd number, at least 3 members, in order to protect
Sentry's cluster service availability is demonstrate,proved, same all members of sentry's cluster dispose on a different server, each sentry's cluster
All member ports number are consistent, and in order to replicate cluster difference with Redis and keep associating, sentry's cluster ports number=Redis is multiple
Cluster ports number+20000 processed, different sentry's clusters, port numbers are different.Each sentry's cluster, can monitor a Redis and answer
Cluster processed, multiple Redis can also be monitored and replicate cluster, sentry's cluster distinguishes different Redis by Redis master libraries identifier
Replicate cluster.Each member is referred to as sentinel node in sentry's cluster.
(3) QConf service ends
QConf service ends are primarily referred to as storing the zookeeper clusters of QConf service nodes, the zookeeper clusters
Run on different servers, also, all member ports number of zookeeper clusters are consistent, and each member is distributed in not
On same server, zookeeper cluster members require odd number, at least three.The each member of Zookeeper clusters is referred to as
Zookeeper nodes.
(4) QConf management ends
Start QConf monitoring services, it is necessary to which incoming parameter is in QConf management ends:The QConf service ends
Zookeeper cluster connection strings
Major function is to manage the survival of sentry corresponding to QConf service nodes and monitoring QConf service nodes, QConf
QConf service nodes, monitoring are registered and updated to management end and the interaction of QConf service ends, QConf management ends to QConf service ends
The viability of all QConf service nodes of the QConf service ends, so as to ensure that sentry that application program is got every time
Service is available, and then ensures Redis database High Availabitities.
(5) QConf clients
Application deployment is in QConf clients, in QConf clients, operation QConf agent services, and, need simultaneously
Want Redis extensions corresponding to QConf extensions corresponding to disposing application program and application program.QConf clients and QConf services
End interaction, the last look of the QConf service nodes is obtained in real time, ensure that the sentry that application program obtains every time is newest.
According to the QConf service nodes, parsing obtains sentinel node, and then, Redis extends according to corresponding to application program, parsing
Sentinel node obtains Redis master libraries, and then, application program can be established with Redis master libraries and connected.
As shown in Fig. 2 the module that each unit specifically includes is as follows:
(1) sentry's cluster management module
It is the ip of Redis master libraries, sentry's cluster ports, Redis master library identifiers to need incoming parameter;
Firstly the need of disposing mono- master library of Redis in Redis replica nodes and N number of be more than or equal to 1, Redis masters from storehouse, N
Storehouse is different with the ip from storehouse, and port is identical.Then sentry's cluster is disposed on sentry's clustered node, respectively on three servers
Sentinel node is disposed, according to incoming parameter, the sentinel node is respectively started.All sentinel nodes in one sentry's cluster
Ip is different, and port numbers are identical, also, the relation of the port of sentry's cluster and the port of reids duplication clusters is:
Sentry's cluster ports=Redis replicates cluster ports+20000
If necessary to increase a sentinel node newly, it is only necessary to start one according to incoming parameter on a new server
Individual sentinel node.But require that the number of sentinel node must be odd number.
If necessary to migrate a sentinel node, it is necessary on new server start a sentinel node, then again under
Line node to be migrated, offline mode are as follows:
A node serve to be migrated) is stopped
Kill node_pid
Node_pid treats sentinel node process pid, and acquisition can be checked by ps-ef.
B) performed in remaining all sentinel node:
SENTINEL sentinels Redis master library identifiers
If necessary to increase a Redis newly from storehouse, it is only necessary to start a Redis node on a new server,
Port numbers are consistent with Redis duplications cluster ports, then log in the Redis nodes, perform:
SLAVEOFF Redis master library ip Redis replicate cluster ports
So, sentry's cluster h can be added to new Redis in corresponding sentry's cluster from storehouse automatically.
It is as follows from storehouse, mode if necessary to migrate a Redis:
A Redis to be migrated) is stopped from storehouse
The Redis to be migrated is logged in from storehouse, is performed:
SHUTDOWN
B) performed in all sentinel nodes:
SENTINEL sentinels Redis master library identifiers
Switch if necessary to Redis master libraries, mode is as follows:
Any one sentinel node is logged in, execution is such as issued orders:
SENTINEL failover Redis master library identifiers
So, sentry's cluster is automatically performed Redis master libraries in several seconds and switched online.
(2) QConf service nodes management module
Need incoming parameter:Zookeeper clusters connection string, QConf service nodes and sentry's cluster it is all into
The ip of member and port.
A set of zookeeper clusters are disposed in Qconf service ends first, the zookeeper clusters include five
Zookeeper nodes, all zookeeper node ports are consistent, are distributed on five servers.Then replicate and save in Redis
Point deployment Redis replicates cluster and disposes sentry's cluster in sentry's clustered node, next, disposing QConf in QConf management ends
Administration extensions and installation PHP software kits.
Using PHP application program management QConf service nodes, it can increase newly and update QConf service nodes.
A it is as follows that QConf service node modes) are increased newly:
$ qzk=new QConfZK (" zookeeper clusters connection string ");
$ service_path=" QConf service nodes ";
$ services_input=array (" sentinel node 1 "=>QCONF_STATUS_UP, " sentinel node 2 "=>
QCONF_STATUS_UP, " sentinel node 3 "=>QCONF_STATUS_UP);
$qzk->servicesSet($service_path,$services_input);
Explanation:Zookeeper cluster connection strings are as follows:
192.168.1.100:2181,192.168.1.101:2181:192.168.1.102:2181:
192.168.1.103:2181,192.168.1.104:2181
QConf service nodes are as follows:/ db/Redis/sn26379, wherein 26379 be the port of sentry's cluster;
B) QConf service nodes are updated, it is necessary to delete and add two operations, it is as follows respectively:
Addition operation:
$ qzk=new QConfZK (" zookeeper clusters connection string ");
$ service_path=" QConf service nodes ";
$qzk->ServiceAdd ($ service_path, " sentinel node 4 ", QCONF_STATUS_UP);
Deletion action:
$ qzk=new QConfZK (" zookeeper clusters connection string ");
$ service_path=" QConf service nodes ";
$qzk->ServiceDelete ($ service_path, " sentinel node 3 ");
C all QConf service nodes information) are checked, the letter of specified QConf service nodes can be checked in the following way
Breath:
$ qzk=new QConfZK (" zookeeper clusters connection string ");
$ service_path=" QConf service nodes ";
$ services_output=$ qzk->servicesGet($service_path);
var_dump($services_output);
(3) QConf service nodes monitoring module
Need incoming parameter:Zookeeper cluster connection strings
In QConf management ends, according to incoming parameter, start QConf monitoring services as follows:
bin/monitor-cmd.sh start
Then perform such as to issue orders and check current all QConf service nodes, including reach the standard grade and offline node:
bin/monitor-cmd.sh list
After starting QConf monitoring services, the machine if some service of some QConf service node is delayed, QConf monitoring clothes
After business starts, sentinel node viability corresponding to all QConf service nodes of automatic detection, if the sentinel node is delayed
Machine, can be automatically offline from QConf service nodes;If sentinel node recovers service, can be reached the standard grade automatically in QConf service nodes;
QConf monitoring services ensure that the availability of QConf service nodes.
(4) QConf service nodes parsing module
Need incoming parameter:QConf service nodes
In QConf clients, zookeeper cluster connection strings are passed to, start QConf agent services, while portion
QConf extensions corresponding to application program are affixed one's name to, may then pass through following manner parsing QConf service nodes:
$ snserver=QConf::GetHost (" QConf service nodes ");
QConf agent return to the sentinel node of a survival using polling algorithm every time, both ensure that Redis services
High Availabitity, load balancing is realized again.
(5) sentry's parsing module
Need incoming parameter:Sentinel node ip, sentry's cluster ports and Redis master library identifiers
In QConf clients, it is necessary to which Redis corresponding to disposing application program extends, in the application, by calling the whistle
Soldier's interface, ip, port and the Redis master library identifiers of sentinel node are passed to, if run succeeded, return to the ip of Redis master libraries
And port, otherwise, return to the conditional code that reports an error.
(6) application program access modules
Need incoming parameter:Redis master libraries ip, Redis replicate cluster ports and password
After the execution of sentry's parsing module terminates, if return value is the conditional code that reports an error, application program will return to error information,
Represent currently without available Redis master libraries;After if sentry's parsing module execution terminates, return value is Redis master libraries
Ip and port, then, according to the ip of Redis master libraries and port and encrypted message, the connection of application call Redis extensions
Pond API, if there is available Redis connections, then Redis connections are returned to, otherwise, according to the Redis master libraries ip, port
And password, the establishment connection relevant interface in Redis extensions is called, creates Redis connections, then, the Redis is returned and connects
Connect, if creating Redis connection failures, return to error information, explanation can not create Redis connections.
A kind of Redis high availability methods based on QConf, this method include:
(1) sentry's cluster management module is called, replicates cluster in Redis replica nodes deployment Redis, while collect in sentry
Group node disposes sentry's cluster, replicates cluster for monitoring Redis, if Redis master libraries break down, sentry's cluster can be certainly
Row switching Redis master libraries, realize Redis master library High Availabitities.
(2) QConf service node management modules are called, zookeeper clusters and QConf administration extensions is disposed, passes through PHP
Application call QConf administration extensions interfaces, sentry's cluster QConf service nodes corresponding to are registered in QConf service ends.
By QConf administration extensions interfaces, it can be increased, updated and be checked newly operation to the QConf service nodes.
(3) QConf service node monitoring modules are called, starts QConf monitoring services in QConf management ends, monitors QConf
The viability of sentinel node corresponding to all QConf service nodes in service end, ensure the whistle that application program is got every time
Soldier's node is available.
(4) QConf service node parsing modules, after QConf service node management module end of runs, sentry's cluster are called
QConf service nodes corresponding to being registered to.Then, application program is called corresponding to QConf according to the QConf service nodes
Extend API, the ip of one sentinel node of return and port.
If in QConf service ends, the QConf service nodes are updated, zookeeper clusters can be automatically by
QConf agent are serviced, and ensure that the sentinel node that application program is got every time is newest.
(5) call sentry's parsing module, according to QConf service nodes parsing module return the sentinel node ip and
Port, Redis expansion interfaces corresponding to application call, the ip of return Redis master libraries and port.
(6) call application program access modules, according to call sentry's parsing module return the Redis master libraries ip and
Port, Redis expansion interfaces corresponding to application call, Redis connections are established, so as to Redis read-write requests.