Linux:Memcached--(PHP网页访问的加速)

Memcached

Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态、数据库驱动网站的速度。Memcached基于一个存储键/值对的hashmap。其守护进程(daemon )是用C写的,但是客户端可以用任何语言来编写,并通过memcached协议与守护进程通信

一·php模块扩展

安装包:memcache-2.2.5.tgz

[root@server1 ~]# tar zxf memcache-2.2.5.tgz    ##解压
[root@server1 ~]# cd memcache-2.2.5
[root@server1 memcache-2.2.5]# cd /usr/local/lnmp/php/bin/
[root@server1 bin]# pwd
/usr/local/lnmp/php/bin
[root@server1 bin]# cd
[root@server1 ~]# vim .bash_profile    ##增加路径
[root@server1 ~]# source .bash_profile
[root@server1 ~]# cd memcache-2.2.5
[root@server1 memcache-2.2.5]# phpize 

增加路径:
这里写图片描述
这里写图片描述

编译三部曲

[root@server1 memcache-2.2.5]# ./configure 
[root@server1 memcache-2.2.5]# make
[root@server1 memcache-2.2.5]# make install 

配置文件

[root@server1 memcache-2.2.5]# cd /usr/local/
[root@server1 local]# cd lnmp/php/etc/
[root@server1 etc]# vim php.ini 
[root@server1 etc]# vim php.ini 
[root@server1 etc]# /etc/init.d/php-fpm reload
Reload service php-fpm  done
[root@server1 etc]# php -m |grep memcache
memcache
[root@server1 etc]# cd
[root@server1 ~]# cd memcache-2.2.5
[root@server1 memcache-2.2.5]# cp memcache.php example.php /usr/local/lnmp/nginx/html/
[root@server1 memcache-2.2.5]# yum install memcached -y
[root@server1 memcache-2.2.5]# /etc/init.d/memcached start
[root@server1 memcache-2.2.5]# netstat -antlp |grep :11211
[root@server1 html]# vim memcache.php 

在 memcache.php 文件
这里写图片描述
网页访问:
这里写图片描述
这里写图片描述
这里写图片描述

物理机测试:

这里写图片描述
这里写图片描述

二·缓存前移

安装包: openresty-1.13.6.1.tar.gz

[root@server1 ~]# tar zxf openresty-1.13.6.1.tar.gz 
[root@server1 ~]# cd openresty-1.13.6.1

编译三部曲

[root@server1 openresty-1.13.6.1]# ./configure --prefix=/usr/local/lnmp/openresty --with-http_ssl_module --with-http_stub_status_module --user=nginx --group=nginx --with-threads --with-file-aio
[root@server1 openresty-1.13.6.1]# gmake
[root@server1 openresty-1.13.6.1]# gmake   install

配置文件

[root@server1 conf]# vim nginx.conf
[root@server1 conf]# /usr/local/lnmp/openresty/nginx/sbin/nginx -t   ##检测
[root@server1 conf]# /usr/local/lnmp/openresty/nginx/sbin/nginx   ##打开

这里写图片描述
这里写图片描述
这里写图片描述

网页访问:

这里写图片描述

物理机测试:
这里写图片描述
这里写图片描述

猜你喜欢

转载自blog.csdn.net/Le_Anny/article/details/81450268