Get the App
SLTechnology News&Howtos  ›  Servers  › 

Nginx+memcached directly connected memcached nginx third-party module ngx_http_upstream_consistent_hash

Shulou Source: shulou.com Published: 2022-06-03 00:36:47 09月22日 Update

1. First download ngx_http_upstream_consistent_hash from https://www.nginx.com/resources/wiki/modules/consistent_hash/ 's official website.

2. Decompress unzip master.zip to get ngx_http_consistent_hash-master folder

3. Recompile nginx

First use / Data/apps/nginx/sbin/nginx-V to take a look at the original compilation options and install with the original compilation options first stop the nginx service

. / configure-prefix=/Data/apps/nginx-with-pcre=/usr/local/src/pcre-8.00-with-zlib=/usr/local/src/zlib-1.2.11-add-module=/usr/local/src/ngx_http_consistent_hash-master

After adding the option of ngx_http_consistent_hash, make & & make install

4. Nginx configure a set of memcached upstream servers

Specify a server group through the memcached_pass directive

And the callback page that is not loaded into the cache is specified by error_page 404 = / callback.php to read and set the cache in a consistent hash manner in the callback page. If the memcache extension is installed

Upstream memcacheserver {

Consistent_hash $request_uri

Server 127.0.0.1:11211

Server 127.0.0.1:11212

Server 127.0.0.1:11213

}

Server {

Listen 7000

Server_name 47.93.5.10

Root / Data/sijunjie/web

Index index.html

Location / {

Default_type text/html

Set $memcached_key "$uri?$args"

Memcached_pass memcacheserver

Error_page 404 = / callback.php

}

Location ~\ .php$ {

Root / Data/sijunjie/web

Fastcgi_pass 127.0.0.1:9000

Fastcgi_index index.php

Fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name

Include fastcgi_params

}

}

5. Configure php

Extension=/Data/apps/php/lib/php/extensions/no-debug-non-zts-20131226/memcache.so

Memcache.hash_strategy=consistent (this instruction distributes the key using a consistent hash) so that it can be consistent with nginx

6. Processing access in callback.php due to the consistent hash distribution configured in step 5, the three servers added here are consistent with the nginx.

$memcache = new Memcache ()

$memcache- > addServer ('127.0.0.1 dollars, 11211)

$memcache- > addServer ('127.0.0.1 dollars, 11212)

$memcache- > addServer ('127.0.0.1 dollars, 11213)

Tags: Consistency service consistency server hash compilation configuration instruction method cache page file folder time three first use processing access module third party Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi vpn MySQL Microsoft Shulou Information