Tokyo
tyrant ( ttserver ) series - high availability and high reliability + nginx
[ author: Sun Li
link: http://www.cnblogs.com/sunli/ Update Time: ]
previous article Tokyo
tyrant ( ttserver ) series -memcache protocol
1. Based on Memcache High Availability of protocols 1.1 Build Ttserver.
As shown in the figureIPIs177And178The two machines are mutually active and standbyTtserver.
1.2 In PHP High Availability
Very lucky,PHPOfMemcacheThe client can directly implement the Failover function. TheAddserverVery good functions or methods.
BoolMemcache: addserver(String $ Host [, Int $ Port [, Bool $ Persistent [, Int $ Weight [, Int $ Timeout [, Int $ Retry_interval [, Bool $ Status [, Callback $ Failure_callback[, Int$ Timeoutms]
)
$ memcache = New memcache; $ memcache-> addserver ( '2017. 192. 168.0.177 ' , 11211 ); $ memcache-> addserver ( '2017. 168.0.178 ' , 11211 ); $ Memcache->Get("Key"); ?>
|
Addserver Will add IP Put it in a pool, and then use the key pair Hash (The default is CRC32 (key)
%
Current_server_num ) Select a server for access , When one of the servers is down, Current_server_num It will be reduced by one and re-executed Hash Connect to a new server to achieve automatic failover.For more information, see PHPAbout Memcache .
1.3 Other languages
Http://code.google.com/p/memcached/wiki/ClientsThis isMemcachedOfClient
APIList of implementations of various languages, almost allAPIAre providedPHPSimilarAddserverImplement the Failover function.
2. Exploitation Nginx Implementation HTTP High Availability of protocols 2.1 Why Nginx Come in?
-
TtserverProvidedHTTPInterface
TtserverNo security guarantee provided
NginxProcessingHTTPThe performance of the request and reverse proxy is very good.
NginxThe reverse proxy has the load balancing and health check functions.
2.2 How to combine Nginx High Availability 2.2.1 Configuration
InNginxAdd the following to the configuration file:
Upstream backend { Server 192.168.0.177: 11211 Weight = 5 max_fails = 3 fail_timeout = 30 s; Server 192.168.2.178: 11211 Weight = 1 max_fails = 3 fail_timeout = 30 s; } |
ExploitationUpstreamPoint to the two backend machines.
location ~ * /count (. *) { if ($ request_method = put) { return 403; } if ($ request_method = delete) { return 403; } if ($ request_method = post) { return 403; } proxy_method get; proxy_pass http: // backend; } |
When the path contains/CountThe proxyTtserverRequest data from the backend. Please note that this is blockedPut, delete, postMethod.Get,The main purpose is to ensure security, becauseDelete, post, putYes, you can modify the data.
2.2.2 Use
Use the preceding configuration file to startNginxYou can accessTtserver. For exampleHttp: // host/count_key1Will displayTtserverMediumKeyIs"Count_key1". When we stop at the same time177And178When the frontend passesNginx
Http: // host/count_key1They are also available.