Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report