LAMPX-AMPX测试篇:

环境:
Linux:    rhel5.8 (192.168.88.131虚拟机) ,物理机:192.168.88.1(Win7)
Apache: httpd-2.4.3.tar.bz2
MySQL:       mysql-5.5.28.tar.gz
Php:  php-5.4.8.tar.bz2
XCache: XCache-2.0.1.tar.bz2(php加速器)

写在测试之前:

1、请确认之前的安装已成功完成.
2、关闭selinux和清空iptables,命令:setenforce 0;iptables -F
3、开启php.ini的short_open_tag = On,此项提供对php等语言的简写方式,如果不开,安装某些web配置时,可能会出现错误:操作命令如下:

  1. sed -i 's/\(^short_open_tag = O\)ff$/\1n/g' /etc/php.ini 

拟主机配置篇:


1、修改主配置文件

  1. sed -i "s/^#\(.*\<vhosts.conf\>$\)/\1/g" /etc/httpd/httpd.conf  
  2. sed -i 's/\(^Doc.*cs\"$\)/\#\1/g' /etc/httpd/httpd.conf 

2、配置两个基于域名的虚拟主机(物理机测试时,记得修改hosts文件.)

  1. sed -i '/^[^#]/d' /etc/httpd/extra/httpd-vhosts.conf  
  2. echo -e '<VirtualHost *:80>\n\tDocumentRoot "/web/mosweb"\n\tServerName mos.example.com\n\tErrorLog "/web/logs/mos-error_log"\n\tCustomLog "/web/logs/mos-access_log" common\n\t<Directory "/web/mosweb">\n\t\tOptions none\n\t\tAllowOverride none\n\t\tRequire all granted\n\t</Directory>\n</VirtualHost>\n\n<VirtualHost *:80>\n\tDocumentRoot "/web/wwwweb"\n\tServerName www.example.com\n\tErrorLog "/web/logs/www-error_log"\n\tCustomLog "/web/logs/www-access_log" common\n\t<Directory "/web/wwwweb">\n\t\tOptions none\n\t\tAllowOverride none\n\t\tRequire all granted\n\t</Directory>\n</VirtualHost>' >> /etc/httpd/extra/httpd-vhosts.conf 

Ps: 淡定,亲,这就是删除系统默认的俩虚拟主机,再追加俩.需要注意的是高版本不在支持Order Allow,Deny的访问控制格式了,而且,如果虚拟主机不设置访问控制的话,则无法被访问,新版本的访问格式如下:
Require all granted   允许所有请求访问资源
Require all denied   拒绝所有请求访问资源
Require env env-var [env-var] ... 当指定环境变量设置时允许访问
Require method http-method [http-method] ...  允许指定的http请求方法访问资源
Require expr expression  当expression返回true时允许访问资源
Require user userid [userid] ...  允许指定的用户id访问资源
Require group group-name [group-name] ... 允许指定的组内的用户访问资源
Require valid-user  所有有效的用户可访问资源
Require ip 10 172.20 192.168.2  允许指定IP的客户端可访问资源
Require not group select  select组内的用户不可访问资源


3、为两个虚拟主机创建对应的目录和文件

  1. mkdir -pv /web/{logs,{mos,www}web}  
  2. echo -e '<h1>mos.example.com</h1>\n\t...OK!' > /web/mosweb/index.html  
  3. echo -e '<h2>www.example.com</h2>\n\t...OK.\n<?php\nphpinfo();\n?>' >/web/wwwweb/index.php 

4、修改windows的hosts,打开浏览器做测试即可

打开C:\Windows\System32\drivers\etc\hosts   添加如下行:

  1. 192.168.88.131  mos.example.com  
  2. 192.168.88.131  www.example.com 

 

 

MySQL简单测试篇:

1、 修改管理员密码并给创建一个测试库授权用户

  1. mysql -uroot -p 键入回车,输入上篇设置的密码123  
  2. mysql>UPDATE mysql.user SET PASSWORD=PASSWORD('redhat'WHERE User='root';  
  3. mysql>use test;  
  4. mysql>GRANT ALL ON test.* TO 'testuser'@'%' IDENTIFIED BY '123';  
  5. mysql>FLUSH PRIVILEGES

2、 删除不用的空用户和IPv6的root用户等.

Ps:  此时还在mysql控制台中

  1. mysql>DELETE FROM user WHERE host='localhost.localdomain' AND user='';  
  2. mysql>DELETE FROM user WHERE host='localhost' AND user='';  
  3. mysql>DELETE FROM user WHERE host='::1';  
  4. mysql>FLUSH PRIVILEGES;  
  5. mysql>\q        此时才算结束 

3、 修改/web/wwwweb/index.php中内容如下:

  1. <?php    
  2. $link=mysql_connect('192.168.88.131','testuser','123');  //php连接mysql函数  
  3. if($link) echo ok;  //如果连接成功,输出ok  
  4. else echo no;   //如果连接失败,输出no 
  5. mysql_close();  //手动关闭本次连接,可不写,有默认超时时间.  
  6. ?> 

4、此时打开浏览器,输出若为OK,则表示正常.

 

 

Apache开启状态监控测试.

1、 查看是否启用此功能,此项功能由status_module模块提供

  1. httpd -M|grep status_module 

2、 在/etc/httpd/httpd.conf中加入如下行

  1. <Location /status>      #定义本地所有虚拟主机访问地址后面加/status即可使用  
  2.     SetHandler server-status    #貌似是调用server-status设置显示信息  
  3.     Require ip 192.168.88.0/24   #仅允许我自己定义的网段可看  
  4. </Location> 

3、 重启httpd,并在物理机器上查看相关内容

  1. service httpd restart  
  2. #打开浏览器:输入 mos.example.com 输出内容如下:  
  3. Apache Server Status for mos.example.com (via 192.168.88.131)  
  4.  
  5. Server Version: Apache/2.4.3 (Unix) PHP/5.4.8  #软件及版本  
  6. Server Built: Oct 27 2012 17:33:04  #软件编译安装的时间  
  7.  
  8. Current Time: Sunday, 28-Oct-2012 07:28:50 CST #服务器当前时间  
  9. Restart Time: Sunday, 28-Oct-2012 07:15:27 CST #上次www软件重启 时间  
  10. Parent Server Config. Generation: 1 #接收到重启命令的次数  
  11. Parent Server MPM Generation: 0  #貌似是告诉父进程是工作在MPM的模式下..  
  12. Server uptime: 13 minutes 22 seconds  #服务器运行时间  
  13. Total accesses: 3 - Total Traffic: 3 kB  # Apache收发的数据量  
  14.  
  15. CPU Usage: u0 s0 cu0 cs0  #CPU使用情况  
  16. .00374 requests/sec - 3 B/second - 1024 B/request  
  17. 1 requests currently being processed, 74 idle workers  
  18.  
  19. PID Connections     Threads Async connections  
  20. total   accepting   busy    idle    writing keep-alive  closing  
  21. 8965    0   yes 0   25  0   0   0  
  22. 8967    0   yes 0   25  0   0   0  
  23. 8995    1   yes 1   24  0   0   0  
  24. Sum 1       1   74  0   0   0  
  25.  
  26. ___________________________________________________W____________  
  27. ___________.....................................................  
  28. ................................................................  
  29. 说明:  
  30. * _:等待连结中。  
  31. * S:启动中。  
  32. * R: 正在读取要求。  
  33. * W:正在送出回应。  
  34. * K:处于保持联机的状态。  
  35. * D:正在查找 DNS。  
  36. * C:正在关闭连结。  
  37. * L:正在写入记录文件。  
  38. * G:进入正常结束程序中。  
  39. * I:处理闲置。  
  40. * .:尚无此程序。  
  41.  
  42. Scoreboard Key:  
  43. "_" Waiting for Connection"S" Starting up, "R" Reading Request,  
  44. "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,  
  45. "C" Closing connection"L" Logging, "G" Gracefully finishing,  
  46. "I" Idle cleanup of worker, "." Open slot with no current process  
  47.  
  48. Srv PID Acc M   CPU     SS  Req Conn    Child   Slot    Client  VHost   Request  
  49. 1-0 8967    0/1/1   _   0.00    796 0   0.0 0.00    0.00    192.168.88.1    mos.example.com:80  GET /status HTTP/1.1  
  50. 2-0 8995    0/1/1   _   0.00    3   2   0.0 0.00    0.00    192.168.88.1    mos.example.com:80  GET / HTTP/1.1  
  51. 2-0 8995    0/0/0   W   0.00    0   1534167436  0.0 0.00    0.00    192.168.88.1    mos.example.com:80  GET /status HTTP/1.1  
  52. 2-0 8995    0/1/1   _   0.00    3   1   0.0 0.00    0.00    192.168.88.1    mos.example.com:80  GET /favicon.ico HTTP/1.1  
  53. Srv Child Server number - generation #本程序与其父程序的编号  
  54. PID OS process ID  #本程序的PID(线程编号)  
  55. Acc Number of accesses this connection / this child / this slot #分别表示本次联机、本程序所处理的存取次数  
  56. M   Mode of operation    #该程序目前的状态。  
  57. CPU CPU usage, number of seconds     #该程序所耗用的 CPU 资源  
  58. SS  Seconds since beginning of most recent request    #距离上次处理要求的时间  
  59. Req Milliseconds required to process most recent request  #最后一次处理要求所耗费的时间,以千分之一秒为单位  
  60. Conn    Kilobytes transferred this connection    #本次联机所传送的数据量  
  61. Child   Megabytes transferred this child       #由该子程序所传送的数据量  
  62. Slot    Total megabytes transferred this slot      #由该 Slot 所传送的数据量  

 

简单搭建一个wordpress,使www.mos.com可以打开.

1、下载最新版wordpress并解压至网页根目录

  1. cd /root/work 
  2. wget http://cn.wordpress.org/wordpress-3.4.2-zh_CN.tar.gz  
  3. tar xf wordpress-3.4.2-zh_CN.tar.gz -C /web/mosweb/  
  4. cd /web/mosweb/  
  5. mv wordpress/* .    #将wordpress文件直接放在网站根目录. 

2、复制配置文件,并配置连接数据参数

  1. cp wp-config-sample.php wp-config.php #复制模板文件,切勿mv  
  2. sed -i 's@database_name_here@test@g' wp-config.php #指定连接数据库  
  3. sed -i 's@username_here@testuser@g' wp-config.php #连接数据库的用户名  
  4. sed -i 's@password_here@123@g' wp-config.php  #连接数据库的密码 

3、打开物理机(Win7),进入wordpress做配置收尾工作
打开浏览器,输入 mos.example.com
按提示,输入用户名,密码,邮箱然后提交即可.

 

使用ab命令做简单的压力测试.

1、修改虚拟机hosts文件,使其解析域名mos.example.com

  1. echo -e '192.168.88.131\tmos.example.com\n192.168.88.131\twww.example.com' >> /etc/hosts  
  2.  
  3.  
  4. #追加完成后,直接使用ping mos.example.com和www.example.com测试

2、简单的测试,譬如,200个用户,同时每个发10个请求到网页根目录的index.php文件

  1. ab -c 200 -n 2000   www.example.com/index.php 

 -c 有多少个用户同时发送请求, -n 总共发出的请求数
下面贴出笔者一个测试的结果作为范例注释:

 

  1. This is ApacheBench, Version 2.3 <$Revision: 1373084 $>  
  2. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/  
  3. Licensed to The Apache Software Foundation, http://www.apache.org/  
  4.         #一些版本相关信息等  
  5. Benchmarking mos.example.com (be patient)  
  6. Completed 200 requests  
  7. Completed 400 requests  
  8. Completed 600 requests  
  9. Completed 800 requests  
  10. Completed 1000 requests  
  11. Completed 1200 requests  
  12. Completed 1400 requests  
  13. Completed 1600 requests  
  14. Completed 1800 requests  
  15. Completed 2000 requests  
  16. Finished 2000 requests  
  17.  
  18.     #进度...  
  19. Server Software:        Apache/2.4.3 #软件版本  
  20. Server Hostname:        mos.example.com #测试主机  
  21. Server Port:            80 #通过80端口  
  22.  
  23. Document Path:          /wp-login.php  #测试页面wordpress登陆页面  
  24. Document Length:        242 bytes  #测试页面大小  
  25.  
  26. Concurrency Level:      200   #测试的并发请求数  
  27. Time taken for tests:   18.055 seconds  #测试总耗时  
  28. Complete requests:      2000    #全部请求书  
  29. Failed requests:        276 #失败的请求  
  30.    (Connect: 0, Receive: 0, Length: 276, Exceptions: 0)  
  31. Write errors:           0         
  32. Non-2xx responses:      1724      
  33. Total transferred:      1771164 bytes    #一共传输的字节  
  34. HTML transferred:       999844 bytes #生成的html的内容传输总量  
  35. Requests per second:    110.77 [#/sec] (mean) #大概每秒能完成几个  
  36. Time per request:       1805.550 [ms] (mean) #每个请求大概耗时  
  37. Time per request:       9.028 [ms] (mean, across all concurrent requests) #相对于所有的并发请求,平均每个用时多久  
  38. Transfer rate:          95.80 [Kbytes/sec] received  #传输速率...介个真心不高,估计是用的虚拟网卡缘故  
  39.  
  40. Connection Times (ms)    #连接时间  
  41.               min  mean[+/-sd] median   max 
  42. Connect:        0    7  22.6      0     140   #连接  
  43. Processing:    23 1667 2587.2    704   16935  #处理  
  44. Waiting:        0 1665 2587.3    704   16935  #等待  
  45. Total:         24 1674 2593.1    720   16968  
  46.  
  47. Percentage of the requests served within a certain time (ms)  
  48.   50%    720  
  49.   66%   1198  
  50.   75%   1562  
  51.   80%   2107  
  52.   90%   5423  
  53.   95%   7555  
  54.   98%   9908  
  55.   99%  12855  
  56.  100%  16968 (longest request)  
  57. #某个时间段的平均处理速率.  

 

 

 

 

 


Ps:
   测试时,尽量使用局域网测试,上面的结果,笔者的本地虚拟网卡,的传输速度太慢了,这估计是由于vmware虚拟网卡自身的问题,这已经严重影响了测试的有效性.
 
   测试时,可以开多个控制台,使用vmstat 1和top,以及网页的status进行观察系统满载时的各种详细参数.
 
   ab测试时,尽量使用多个页面,多次测试,去平均值为最好,若测试的精细,可对XCache开启和关闭的效果分别测试,以及apache的mpm的几个工作模型做详细修改测试,以及apache内各种配置的关闭和开启后的效果测,方式都是一样(笔者很多都正在测试).