Tokyo tyrant (ttserver) series-high availability and high reliability + nginx

Source: Internet
Author: User
Tags failover

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?
    1.  

      • 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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.