centos上yum安装memcache+xcache
1、eAccelerator
eAccelerator是一个自由开放源码PHP加速器,优化和动态内容缓存,提高了PHP脚本的缓存性能,使得PHP脚本在编译的状态下,对服务器的开销几乎完全消除。 它还有对脚本起优化作用,以加快其执行效率。使PHP程序代码执效率能提高1-10倍。从文字上可以理解为:eAccelerator是PHP加速器扩展。
2、memcached
Memcached 是一个高性能的分布式内存对象缓存系统,用于在动态应用中减少数据库负载,提升访问速度。它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提供动态、数据库驱动网站的速度。从文字上可以理解为:内存缓存扩展,并且针对于集群服务器使用较多,主要用于分布式缓存,算是数据库缓存。
3、Alternative PHP Cache(APC缓存)
Alternative PHP Cache (APC缓存)是一种对PHP有效的开放源高速缓冲储存器工具,他能够缓存Opcode(目标文件)的PHP中间码。 APC的缓存分两部分:系统缓存和用户数据缓存. 系统缓存 是自动使用的,是指APC把PHP文件源码的编译结果缓存起来,然后在再次调用时先对比时间标记。如果未过期,则使用缓存代码运行。默认缓存 3600s(一小时).但是这样仍会浪费大量CPU时间.因此可以在php.ini中设置system缓存为永不过期(apc.ttl=0).不过如果这样设置,改运PHP代码后需要restart一下您的web服务器(比如apache…).目前对APC的性能测试一般指的是这一层cache;从文字上理到:Alternative PHP Cache(APC缓存)也算是一种内存缓存扩展,算是数据库缓存扩展。
4、Xcache
是一个开源的opcode缓存器/优化器, 他能够提高服务器上的PHP性能,他通过把编译PHP后的数据缓冲到共享内存从而避免重复的编译过程, 能够直接使用缓冲区已编译的代码从而提高速度. 通常能够提高您的页面生成速率2到5倍, 降低服务器负载。 其实它与eAccelerator一样是PHP加速器扩展。
以上就是他们的作用与区别,简单一点就是:eAccelerator,xcache是PHP缓存扩展,memcached、APC缓存是数据库缓存扩展,一般两者只有要安装其中一个即可,不要贪多。另外,实际测试中发现当Cache数量超过一定阀值的时候,APC的性能不如Memcache。所以在扩展的选择上,本人一般会选择xcache+memcached这个组合。
准备安装环境:
# /bin/rpm -ivh http://ftp.uninett.no/linux/epel/6/i386/epel-release-6-8.noarch.rpm
# /bin/rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
(1)安装memcache、memcached
1: 安装 memcache及其组件
# yum --enablerepo=remi install php-devel memcached php-pecl-memcache libmemcached php-memcached
2:查看是否安装成功,启动服务
#memcached -h
#php -m|grep memcache
#chkconfig memcached on
#service memcached start
#service httpd restart
3: memcache 优化参数设置
# service memcached restart
# ps -ef |grep memcached
# killall memcached
# /usr/bin/memcached -d -m 1024 -u root -l 42.51.159.207 -p 1024 -P /tmp/memcached.pid
#vi /etc/rc.local
添加/usr/bin/memcached -d -m 1024 -u root -l 42.51.159.207 -p 1024 -P /tmp/memcached.pid 开机自动加载配置
(2) 安装 xcache
1:准备源码编译安装
# wget http://xcache.lighttpd.net/pub/Releases/3.1.0/xcache-3.1.0.tar.gz
# tar -zxvf xcache-3.1.0.tar.gz
# cd xcache-3.1.0
# phpize
1 | # ./configure --enable-xcache --enable-xcache-coverager --enable-xcache-optimizer --with-php-config=/usr/bin/php-config |
# make&&make install
安装后提示"Installing shared extensions: /usr/lib64/php/modules/"
# make test
输入 Yns 回车
# touch /tmp/xcache #创建缓存文件
# chmod 777 /tmp/xcache #设置权限
2:写入php配置文件
# vi /etc/php.ini 末尾加入
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | [xcache-common] ; change me - 64 bit php => /usr/lib64/php/modules/xcache.so extension = /usr/lib64/php/modules/xcache.so ; 32 bit php => /usr/lib/php/modules/xcache.so ;zend_extension = /usr/lib64/php/modules/xcache.so [xcache.admin] xcache.admin.auth = On xcache.admin.user = "xcache" xcache.admin.pass = "e10adc3949ba59abbe56e057f20f883e" [xcache] xcache.shm_scheme = "mmap" xcache.size = 1024M xcache.count = 1 xcache.slots = 2048K xcache.ttl = 3600 xcache.gc_interval = 300 xcache.var_size = 1024M xcache.var_count = 1 xcache.var_slots = 2048K xcache.var_ttl = 0 xcache.var_maxttl = 0 xcache.var_gc_interval = 300 ;N/A for /dev/zero xcache.readonly_protection = Off xcache.mmap_path = "/tmp/xcache" xcache.cacher = On xcache.stat = On xcache.coredump_directory = "" xcache.experimental = On xcache.optimizer = On [xcache.coverager] ; enabling this feature will impact performance ; enable only if xcache.coverager == On && xcache.coveragedump_directory == "non-empty-value" ; enable coverage data collecting and xcache_coverager_start/stop/get/clean() functions xcache.coverager = On xcache.coveragedump_directory = "/var/www/html/xcache/coverager" ;xcache end |
3: 查看效果
# service httpd restart
# php -v
会看到"with XCache v3.1.0, Copyright" 字样,说明xcache安装成功
4: 安装xcache监控面板
# cp -a ./htdocs /var/www/html/
# mv /var/www/html/htdocs /var/www/html/xcache
5: xcache面板的ie访问
http://ip/xcache 登录用户名是xcache密码123456 这个登录的账号 ,php.ini的[xcache.admin]标识有设置。
ps:
1,xcache 可以用yum安装 , 安装命令#yum install php-xcache xcache-admin
2, xcache官方