- 用法:nginx响应请求时,直接请求memcached,如果没有相应的内容,再回调php页面去查询database,并写入memcached
- nginx请求memecached时, 一般用uri、arg做key, 比如/abc.php?id=3
- 安装第三方模块:ngx_http_php_memcache_standard_balancer-master
- 解压到path/ngx_module
- 配置:
./configure --prefix=/xxx/xxx-add_module=path/ngx_module
- 编译安装:
make && make install
3.配置memcache集群 - 全局中
upstream memserver { 把用到的memcached节点,声明在一个组里 hash_key $request_uri; // hash计算时的依据,以uri做依据来hash server localhost:11211; server localhost:11212; } ```
- location中
location / { # root html; set $memcached_key $uri; memcached_pass memserver; // memserver为上面的memcache节点的名称 error_page 404 /writemem.php; index index.php index.html index.htm; }
- 在nginx中做集群与负载均衡,步骤都是一样的
- Upstream {}模块 把多台服务器加入到一个组
- 然后 memcached_pass, fastcgi_pass, proxy_pass ==> upstream组