您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
马哥linux运维学习笔记-编译安装LAMP之php-5.4.13、xcache-2.0及使用ab命令实现压力测试
发布时间:2019-02-08 09:11:56编辑:雪饮阅读()
整合php5.4.13+apache2.4.4:
[root@localhost ~]# cp /usr/local/src/php-5.4.13/php.ini-production /etc/php.ini
在httpd主机中心配置文件的mime_module模块中新增配置项
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
同配置文件中dir_module模块中添加php默认页索引
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
编译xcache2.0.0
[root@localhost xcache-2.0.0]# /usr/local/php/bin/phpize
[root@localhost xcache-2.0.0]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
[root@localhost xcache-2.0.0]# cp xcache.ini /etc/php.d/
[root@localhost xcache-2.0.0]# head /etc/php.d/xcache.ini
[xcache-common]
;; install as zend extension (recommended), normally "$extension_dir/xcache.so"
zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
; zend_extension_ts = /usr/local/lib/php/extensions/non-debug-zts-xxx/xcache.so
;; For windows users, replace xcache.so with php_xcache.dll
;zend_extension_ts = c:/php/extensions/php_xcache.dll
;; or install as extension, make sure your extension_dir setting is correct
; extension = xcache.so
;; or win32:
; extension = php_xcache.dll
然后重启apache
虚拟主机
在中心主机配置文件中去除Include /etc/httpd/extra/httpd-vhosts.conf的注释
并注释DocumentRoot "/usr/local/apache/htdocs"
虚拟主机配置文件配置如:
<VirtualHost *:80>
ServerName www.a.org
DocumentRoot "/www/a.org"
<Directory "/www/a.org">
Options none
AllowOverride none
Require all granted
</Directory>
ErrorLog "/var/log/httpd/a.org-error_log"
CustomLog "/var/log/httpd/a.org-access_log" combined
</VirtualHost>
<VirtualHost *:80>
ServerName www.b.net
DocumentRoot "/www/b.net"
<Directory "/www/b.net">
Options none
AllowOverride none
Require all granted
</Directory>
ErrorLog "/var/log/httpd/b.net-error_log"
CustomLog "/var/log/httpd/b.net-access_log" combined
</VirtualHost>
创建相关目录
[root@localhost xcache-2.0.0]# mkdir -p /www/a.org
[root@localhost xcache-2.0.0]# mkdir -p /www/b.net
[root@localhost xcache-2.0.0]# mkdir -p /var/log/httpd
创建对应html
[root@localhost xcache-2.0.0]# cat /www/a.org/index.html
this is www.a.org
[root@localhost xcache-2.0.0]# cat /www/b.net/index.html
this is www.b.net
增加hosts解析
[root@localhost xcache-2.0.0]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.1.9 www.a.org www.b.net
重启apache
[root@localhost xcache-2.0.0]# /usr/local/apache/bin/apachectl restart
ab测试
解决ab测试“Too many open files”问题
问题:
[root@localhost xcache-2.0.0]# /usr/local/apache/bin/ab -c 2000 -n 10000 http:// www.a.org/index.html
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.a.org (be patient)
socket: Too many open files (24)
解决:
ab测试是一个客户端应用,出现该错误是因为打开的页面数超过了客户端所在系统所限制的最大页面数,提示该限制即可
[root@localhost xcache-2.0.0]# ulimit -n 10000
忽略错误
问题:
[root@localhost src]# /usr/local/apache/bin/ab -c 2000 -n 10000 http://www.a.org/pma/index.php
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.a.org (be patient)
Completed 1000 requests
Completed 2000 requests
apr_socket_recv: Connection reset by peer (104)
Total of 2039 requests completed
解决:
-r参数可以忽略错误
[root@localhost src]# /usr/local/apache/bin/ab -r -c 2000 -n 10000 http://www.a.org/pma/index.php
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.a.org (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Apache/2.4.4
Server Hostname: www.a.org
Server Port: 80
Document Path: /pma/index.php
Document Length: 6784 bytes
Concurrency Level: 2000
Time taken for tests: 113.031 seconds
Complete requests: 10000
Failed requests: 1847
(Connect: 0, Receive: 483, Length: 881, Exceptions: 483)
Write errors: 0
Total transferred: 68324822 bytes
HTML transferred: 61863296 bytes
Requests per second: 88.47 [#/sec] (mean)
Time per request: 22606.171 [ms] (mean)
Time per request: 11.303 [ms] (mean, across all concurrent requests)
Transfer rate: 590.31 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2365 6933.2 0 45003
Processing: 10 8437 22230.7 1484 113012
Waiting: 0 4733 15316.1 1230 89400
Total: 10 10802 25587.7 1676 113012
Percentage of the requests served within a certain time (ms)
50% 1676
66% 2430
75% 4462
80% 5583
90% 25699
95% 86888
98% 113003
99% 113009
100% 113012 (longest request)
关键字词:linux,php5.4.13,xcache2.0,ab