安装xcache,为php加速

前一篇博文,笔者写了关于LAMP的构建http://407711169.blog.51cto.com/6616996/1185226。最后提到了XCache加速的功能。这里来详细的来做一下加速及对比。
Xcahe 可以加快 php 的执行速度,加上安装设定都很直觉,就使用这个来试试
1 安装xcache-3.0.1
 
  1. [root@localhost ~]# tar xf xcache-3.0.1.tar.gz   
  2. [root@localhost ~]# cd xcache-3.0.1       //xcache是php的扩展,要使用php命令加载此扩展   
  3. [root@localhost xcache]# /usr/local/php/bin/phpize     //phpize命令作用是要准备一个php扩展准备编译,所以扩展要先执行编译   
  4. [root@localhost xcache]#./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config     
  5. //php-config表示能够获取php的配置信息以及编译时的选项信息;   
  6. //由于不在默认路径下,xcache要获取php安装时所启用的功能,否则xcache会找不到php的路径   
  7. [root@localhost xcache]#make   
  8. [root@localhost xcache]#make install        
  9. 安装结束时,会出现类似如下行:   
  10. Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20100525/   
  11. //安装共享扩展模块路径,先把这个路径复制下来,等一下复制到xcache的配置文件中  
2 编辑php.ini,整合php和xcache
  1. [root@localhost xcache]# mkdir /etc/php.d   
  2. [root@localhost xcache]# cp xcache.ini /etc/php.d    //将xcache提供的样例配置导入php.ini  
  3. 重启网络服务查看网页  
 

后续:为LAMP添加XCache加速。_lamp

  1. [root@localhost xcache]#vim /etc/php.d/xcache.ini //可以查看下他的配置信息  
 

后续:为LAMP添加XCache加速。_xcahe加速_02

3为源码编译httpd提供虚拟主机
 
  1. [root@localhost xcache]#vim /etc/httpd/httpd.conf   
  2. #DocumentRoot "/usr/local/apache/htdocs"       //一定要注释中心主机配置   
  3. Include /etc/httpd/extra/httpd-vhosts.conf     //开启虚拟主机配置文件,默认有样例   
  4. LoadModule log_config_module modules/mod_log_config.so    //开启mod_log功能,默认是启用的   
  5. 保存退出   
  6.  
  7. [root@localhost xcache]#vim /etc/httpd/extra/httpd-vhosts.conf       //在提供的样例上修改   
  8.  
  9. <VirtualHost *:80>   
  10. ServerName www.a.org   
  11. DocumentRoot "/www/a.org"   
  12. <Directory "/www/a.org">   
  13. Options none   
  14. AllowOverride none   
  15. Require all granted     //定义任何都有访问权限   
  16. </Directory>   
  17. ErrorLog "/var/log/httpd/a.org-error_log"   
  18. CustomLog "/var/log/httpd/a.org-access_log" combined   
  19. </VirtualHost>   
  20.  
  21. <VirtualHost *:80>   
  22. ServerName www.b.net   
  23. DocumentRoot "/www/b.net"   
  24. <Directory "/www/b.net">   
  25. Options none   
  26. AllowOverride none   
  27. Require all granted   
  28. </Directory>   
  29. ErrorLog "/var/log/httpd/b.net-error_log"   
  30. CustomLog "/var/log/httpd/b.net-access_log" common   
  31. </VirtualHost>   
  32. 保存退出   
4创建域名和日志的目录
 
  1. [root@localhost xcache-3.0.1]# mkdir /www/{a.org,b.net} -pv  
  2. mkdir: created directory `/www'  
  3. mkdir: created directory `/www/a.org'  
  4. mkdir: created directory `/www/b.net'  
  5. [root@localhost xcache-3.0.1]# mkdir /var/log/httpd/  
5创建域名的页面index.html
  1. [root@localhost xcache]#echo "<h1>www.a.org</h1>> /www/a.org/index.html   
  2. [root@localhost xcache]#echo "<h1>www.b.net</h1>> /www/b.net/index.html   
  3. [root@localhost xcache]#httpd –t   
6 在物理机上添加域名解析记录
  1. 过程:点击硬盘c盘---> Windows---> System32---> drivers---> etc--->hosts文件    
  2. 添加如下内容:   
  3. 172.16.111.1  www.a.org   
  4. 172.16.111.1  www.b.net   
  5.  //注意:不要忘记保存,点击保存按钮   
  6.  [root@localhost xcache]#service httpd restart   
7 测试域名
 

后续:为LAMP添加XCache加速。_xcahe加速_03

 
 
8 使用ab工具对静态页面进行压力测试
 
  1. [root@localhost xcache]#ab -c 10 -n 100 http://www.a.org/index.html   
 

后续:为LAMP添加XCache加速。_lamp_04

9 对动态页面进行压力测试
 
  1. 安装phpMyAdmin-3.5.1-all-languages.tar.bz2软件包到/www/b.net下   
  2. [root@localhost ~]#tar xf phpMyAdmin-3.5.1-all-languages.tar.bz2/ -C /www/b.net   
  3. [root@localhost ~]#cd /www/b.net   
  4. [root@localhost b.net]#mv phpMyAdmin-3.5.1-all-languages / pma   
  5. [root@localhost b.net]#cd pma   
  6. [root@localhost pma]#cp config.sample.inc.php config.inc.php    //软件包提供默认配置文件,重命名配置文件名称   
  7. [root@localhost pma]#openssl rand -base64 10      //生成10位的随机数,把生成的随机数复制到配置文件中   
  8. [root@localhost pma]#vim config.inc.php   //编辑配置文件,把生成的随机数写在下面的位置   
  9. $cfg['blowfish_secret'] = 'QkMTw3ZlpJlBKA'     
  10. [root@localhost pma]#mysqladmin -uroot password 'redhat'      //生成root用户的密码,登录站点www.b.net/pma不允许使用空密码   
  11. [root@localhost pma]#ab -c 100 -n 1000 http://www.b.net/pma/index.html     //动态页面压力测试   

后续:为LAMP添加XCache加速。_xcahe加速_05

后续:为LAMP添加XCache加速。_xcahe加速_06