新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

nginc+memcache-创新互联

memcache 分为服务端和客户端。服务端用来存放缓存,客户端用来操作缓存。
因此,可以使用 Nginx 直接访问 Memcache,并用$uri 和$args 等 Nginx 内置变量设定缓存 key规则,这样,当缓存命中时,Nginx 可以跳过通过 fastcgi 和 PHP 通信的过程,直接从 memcache中获取数据并返回。
OpenResty是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。

1.下载openresty的压缩包,opwnresty中含有自身的nginx,因此不需要额外安装nginx
[root@server2 ~]# tar zxf openresty-1.11.2.3.tar.gz
[root@server2 ~]# cd openresty-1.11.2.3
[root@server2 openresty-1.11.2.3]# yum install gcc-c++ -y
[root@server2 openresty-1.11.2.3]# yum install pcre-devel -y
[root@server2 openresty-1.11.2.3]# yum install openssl-devel -y
[root@server2 openresty-1.11.2.3]# ./configure
[root@server2 openresty-1.11.2.3]# gmake
[root@server2 openresty-1.11.2.3]# gmake install
[root@server2 openresty-1.11.2.3]# cd /usr//local/openresty/nginx/conf/

2.更改配置文件
[root@server2 conf]# vim nginx.conf
###########################################
 18 http {
 19    upstream memcache {      ##nginx 模块中,uosteam 主要用于完成数据的接收,处理,转发
 20    server 127.0.0.1:11211;      ##设置默认端口号
 21    }
 52        location /memc {
 53                internal;      ##只接受内部访问,不接收外部 http 请求
 54                memc_connect_timeout 100ms;
 55                memc_send_timeout 100ms;
 56                memc_read_timeout 100ms;
 57                set $memc_key $query_string;   ##使用 Nginx 内置的$query_string 来作为 key
 58                set $memc_exptime 300;      ##缓存失效时间
 59                memc_pass memcache;
 60                }   ##将请求的 URL 和后端服务返回的有效结果组成 key-value 存入 memcache服务
 72        location ~ \.php$ {
 73                set $key $uri$args;
 74                srcache_fetch GET /memc $key;
         ##注册一个输入拦截器到 location,这个配置将在location 进入时被执行
 75                srcache_store PUT /memc $key;
         ##注册一个输出拦截器到 location,当 location执行完成并输出时会被执行
 76                root           html;
 77                fastcgi_pass   172.0.0.60:9000;
 78                fastcgi_index  index.php;
 79                include        fastcgi.conf;
 80        }##为“~ \.php$”配置缓存,表示所有以“.php”结尾的请求都会结果被缓存
   }
##当所请求的 uri 以“.php”结尾时,首先到 memcache 中查询有没有以$uri$args 为 key 的数据,如果有则直接返回;否则,执行 location 的逻辑,如果返回的 http 状态码为 200,则在输出前以$uri$args 为 key,将输入结果存入 memcache

###########################################
[root@server2 conf]# /usr/local/openresty/nginx/sbin/nginx -t
[root@server2 conf]# /usr/local/openresty/nginx/sbin/nginx -s reload

[root@server2 conf]# /etc/init.d/httpd start
##注意:http与nginx的端口号都为80,因此需要修改http的端口号
[root@server2 html]# /etc/init.d/iptables stop
[root@server2 html]# yum install memcached -y

测试:
1.开启memcached,在物理机中进行压力测试
[root@server2 conf]# /etc/init.d/memcached start
[root@foundation60 Desktop]# ab -c 10 -n 50000 http://172.25.60.3/index.php
nginc+memcache

成都创新互联是一家集网站建设,饶平企业网站建设,饶平品牌网站建设,网站定制,饶平网站建设报价,网络营销,网络优化,饶平网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

2.关闭memcached,在物理机中进行压力测试
[root@server2 conf]# /etc/init.d/memcached stop
[root@foundation60 Desktop]# ab -c 10 -n 50000 http://172.25.60.3/index.php
nginc+memcache

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前题目:nginc+memcache-创新互联
标题来源:http://www.wjwzjz.com/article/cejoeh.html
在线咨询
服务热线
服务热线:028-86922220
TOP