❶Apache接收客户的PHP程序请求,并根据规则过滤之。
❷Apache将PHP程序请求传递给PHP处理模块libphp5.so 。
❸PHP引擎定位磁盘上的PHP文件,并将其加载到内存中解析。
❹PHP处理模块libphp5.so将PHP源代码编译成为opcode。
❺PHP处理模块libpbp5.so执行opcode, 然后把opcode 缓存起来。
❻Apache接收客户端新的PHP程序请求,PHP 引擎直接读取缓存执行opcode文件,并将结果返回。在这一次任务中,就无第4步的编译解析了,从而提升了PHP 编译解析效率。
❶Nginx 接收客户端的PHP程序访问请求。
❷Nginx 根据扩展名等过滤规则将PHP程序请求传递给解析PHP的FCGI (phpfpm)进程。
❸PHP-FPM进程调用PHP解析器读取站点磁盘上的PHP文件,并加载到内存中。
❹PHP解析器将PHP程序编译成为opcode文件,然后把opcode缓存起来。
❺PHP-FPM引擎执行opcode 树后,返回数据给Nginx, 进而返回客户端。
❻Nginx 接收客户新的PHP程序请求, PHP-FPM 引擎就会直接读取缓存中的opcode并执行,将结果返回。该过程中无需第4 步操作,从而提升了PHP 编译解析效率。
❼如果访问数据库,程序首先检查客户端请求的数据在Memcached 服务的缓存中是否存在,如果存在,直接把请求的数据返回,不再请求后端数据库。
❽如果请求的数据在Memcached 缓存中不存在,则程序会去Memcahced 后端的数据库服务。把从数据库中取到的数据返回给客户端。
❾同时把新取到的数据库的数据缓存一份到Memcached 服务缓存中,下次同样的请求就直接从Memcacbed 服务缓存返回数据,从而减轻数据库的访问压力。
LNMP完整环境:LNMP架构部署WordPress论坛
[root@www ~]# cat /etc/redhat-release
CentOS release 6.6 (Final)
[root@www ~]# uname -r
2.6.32-504.30.3.el6.x86_64
[root@www ~]# uname -m
x86_64
[root@www ~]# /application/php/sbin/nginx -v
nginx version: nginx/1.6.3
[root@www ~]# /application/php/bin/php -v
PHP 5.3.27 (cli) (built: May 14 2021 10:24:11)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
[root@www ~]# mysqladmin -uroot -pxxxx version
mysqladmin Ver 8.42 Distrib 5.5.32, for linux2.6 on x86_64
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Server version 5.5.32
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /tmp/mysql.sock
Uptime: 42 min 54 sec
Threads: 1 Questions: 1 Slow queries: 0 Opens: 35 Flush tables: 1 Open tables: 4 Queries per second avg: 0.000
LC_ALL=C
:去除所有本地化的LC_*
设置perl: warning: Falling back to the standard locale ("C").
[root@www ~]# vim /etc/profile
略
export LANGUAGE="en_US.UTF-8:zh_CN.UTF-8"
export LANG=en_US:zh_CN.UTF-8
export LC_ALL=C
"/etc/profile" 81L, 1895C 已写入
[root@www ~]# source /etc/profile
[root@www ~]# yum install perl-devel -y
Installed:
perl-devel.x86_64 4:5.10.1-136.el6_6.1
Dependency Installed:
db4-cxx.x86_64 0:4.7.25-19.el6_6
db4-devel.x86_64 0:4.7.25-19.el6_6
gdbm-devel.x86_64 0:1.8.0-36.el6
perl-ExtUtils-MakeMaker.x86_64 0:6.55-136.el6_6.1
perl-ExtUtils-ParseXS.x86_64 1:2.2003.0-136.el6_6.1
perl-Test-Harness.x86_64 0:3.17-136.el6_6.1
[root@www ~]# yum install perl-CPAN -y
Installed:
perl-CPAN.x86_64 0:1.9402-136.el6_6.1
Dependency Installed:
perl-Digest-SHA.x86_64 1:5.47-136.el6_6.1
./configure --enable-memcache --with-php-config=/application/php/bin/php-config
[root@www ~]# cd /home/centos/tools
[root@www tools]# rz
[root@www tools]# tar zxf memcache-2.2.7.tgz
[root@www tools]# cd memcache-2.2.7
[root@www memcache-2.2.7]# /application/php/bin/phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
[root@www memcache-2.2.7]# ./configure --enable-memcache --with-php-config=/application/php/bin/php-config
[root@www memcache-2.2.7]# make
[root@www memcache-2.2.7]# make install
Installing shared extensions: /application/php/lib/php/extensions/no-debug-non-zts-20090626/
[root@www memcache-2.2.7]# cd ..
[root@www tools]# ls -l /application/php/lib/php/extensions/no-debug-non-zts-20090626/
total 244
-rwxr-xr-x. 1 root root 246472 May 17 06:41 memcache.so
./configure --with-php-config=/application/php/bin/php-config --with-pdo-mysql=/application/mysql
[root@www tools]# rz
[root@www tools]# tar xf PDO_MYSQL-1.0.2.tgz
[root@www tools]# cd PDO_MYSQL-1.0.2/
[root@www PDO_MYSQL-1.0.2]# /application/php/bin/phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
config.m4:104: warning: AC_CACHE_VAL(pdo_inc_path, ...): suspicious cache-id, must contain _cv_ to be cached
../../lib/autoconf/general.m4:1974: AC_CACHE_VAL is expanded from...
../../lib/autoconf/general.m4:1994: AC_CACHE_CHECK is expanded from...
aclocal.m4:2754: PHP_CHECK_PDO_INCLUDES is expanded from...
config.m4:104: the top level
config.m4:104: warning: AC_CACHE_VAL(pdo_inc_path, ...): suspicious cache-id, must contain _cv_ to be cached
../../lib/autoconf/general.m4:1974: AC_CACHE_VAL is expanded from...
../../lib/autoconf/general.m4:1994: AC_CACHE_CHECK is expanded from...
aclocal.m4:2754: PHP_CHECK_PDO_INCLUDES is expanded from...
config.m4:104: the top level
[root@www PDO_MYSQL-1.0.2]# ./configure --with-php-config=/application/php/bin/php-config --with-pdo-mysql=/application/mysql
[root@www PDO_MYSQL-1.0.2]# make
[root@www PDO_MYSQL-1.0.2]# make install
Installing shared extensions: /application/php/lib/php/extensions/no-debug-non-zts-20090626/
[root@www PDO_MYSQL-1.0.2]# ls -l /application/php/lib/php/extensions/no-debug-non-zts-20090626/
total 400
-rwxr-xr-x. 1 root root 246472 May 17 06:41 memcache.so
-rwxr-xr-x. 1 root root 155836 May 17 06:51 pdo_mysql.so
[root@www PDO_MYSQL-1.0.2]# cd ..
perl-devel库
./configure
[root@www tools]# rz
[root@www tools]# tar xf ImageMagick-6.7.9-10.tar.xz
[root@www tools]# cd ImageMagick-6.7.9-10/
[root@www ImageMagick-6.7.9-10]# ./configure
[root@www ImageMagick-6.7.9-10]# make
make all-am
make[1]: Entering directory `/root/PDO_MYSQL-1.0.2/ImageMagick-6.7.9-10'
略
make[1]: Leaving directory `/root/PDO_MYSQL-1.0.2/ImageMagick-6.7.9-10'
[root@www ImageMagick-6.7.9-10]# make install
make install-am
make[1]: Entering directory `/root/PDO_MYSQL-1.0.2/ImageMagick-6.7.9-10'
make[2]: Entering directory `/root/PDO_MYSQL-1.0.2/ImageMagick-6.7.9-10'
略
make[2]: Leaving directory `/root/PDO_MYSQL-1.0.2/ImageMagick-6.7.9-10'
make[1]: Leaving directory `/root/PDO_MYSQL-1.0.2/ImageMagick-6.7.9-10'
[root@www ImageMagick-6.7.9-10]# cd ..
ImageMagick
./configure --with-php-config=/application/php/bin/php-config
[root@www tools]# rz
[root@www tools]# tar zxf imagick-2.3.0.tgz
[root@www tools]# cd imagick-2.3.0
[root@www imagick-2.3.0]# /application/php/bin/phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
[root@www tools]# ./configure --with-php-config=/application/php/bin/php-config
[root@www tools]# make
[root@www imagick-2.3.0]# make install
Installing shared extensions: /application/php/lib/php/extensions/no-debug-non-zts-20090626/
[root@www imagick-2.3.0]# ls -l /application/php/lib/php/extensions/no-debug-non-zts-20090626/
total 1448
-rwxr-xr-x. 1 root root 1072953 May 17 07:29 imagick.so
-rwxr-xr-x. 1 root root 246472 May 17 06:41 memcache.so
-rwxr-xr-x. 1 root root 155836 May 17 06:51 pdo_mysql.so
[root@www imagick-2.3.0]# cd ..
cp php.ini php.ini.bak
extension_dir = "/application/php/lib/php/extensions/no-debug-non-zts-20090626/"
extension=memcache.so
[root@www xcache-3.2.0]# cd /application/php/lib
[root@www lib]# ls -l
[root@www lib]# cp php.ini php.ini.bak
[root@www lib]# ls -l
total 140
drwxr-xr-x. 15 root root 4096 May 17 06:41 php
-rw-r--r--. 1 root root 69627 May 14 10:40 php.ini
-rw-r--r--. 1 root root 69627 May 17 08:03 php.ini.bak
[root@www lib]# vim php.ini
819 extension_dir = "/application/php/lib/php/extensions/no-debug-non-zts-20090626/"
820 extension=memcache.so
821 extension=pdo_mysql.so
822 extension=imagick.so
pkill php-fpm
/application/php/sbin/php-fpm
ps -ef | grep php-fpm
[root@www lib]# pkill php-fpm
[root@www lib]# ps -ef | grep php-fpm | grep -v grep
[root@www lib]# /application/php/sbin/php-fpm
[root@www lib]# ps -ef | grep php-fpm
root 43759 1 0 08:47 ? 00:00:00 php-fpm: master process (/application/php/etc/php-fpm.conf)
nginx 43760 43759 0 08:47 ? 00:00:00 php-fpm: pool www
nginx 43761 43759 0 08:47 ? 00:00:00 php-fpm: pool www
root 43771 6577 0 08:48 pts/1 00:00:00 grep php-fpm
[root@www lib]# ps -ef | grep php-fpm | grep -v grep | wc -l
3
vim /application/nginx/html/vps/realm_name/blog/viem_info.php
[root@www lib]# vim /application/nginx/conf/vps/realm_name/blog.conf
server {
listen 80;
server_name blog.test_lnmp.org;
location / {
root html/vps/realm_name/blog;
index index.php index.html index.htm;
}
location ~ .*\.(php|php5)?$ {
root html/vps/realm_name/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /application/nginx/conf/fastcgi.conf;
}
access_log logs/access_blog.log main gzip buffer=32k flush=5s;
}
[root@www lib]# ls -l /application/nginx/html/vps/realm_name/blog
[root@www lib]# vim /application/nginx/html/vps/realm_name/blog/viem_info.php
<?php phpinfo () ; ?>
[root@www lib]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx/conf/nginx.conf test is successful
[root@www lib]# /application/nginx/sbin/nginx -s reload
访问网址:blog.test_lnmp.org/viem_info.php
页内搜索:memcache、pdo_mysql、imagick
插件选取:根据实际业务需求,搭建相关环境进行压力测试,然后根据实际测试结果进行选择。
测试环境:以下三者都可安装,但不能一起配置使用
实际环境:安装一款与相关服务搭配最合适的即可
/application/php/bin/phpize
,在./configure
前执行。phpize脚本
可以建立PHP的外挂模块。在PHP安装编译时未配置的模块,可以通过phpize脚本
添加。./configure --enable-eaccelerator=shared --with-php-config=/application/php/bin/php-config
;PHP安装目录--with-php-config=/application/php/bin/php-config
[root@www tools]# rz
[root@www tools]# tar xf eaccelerator-0.9.6.1.tar.bz2
[root@www tools]# cd eaccelerator-0.9.6.1/
[root@www eaccelerator-0.9.6.1]# /application/php/bin/phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
[root@www eaccelerator-0.9.6.1]# ./configure --enable-eaccelerator=shared --with-php-config=/application/php/bin/php-config
[root@www eaccelerator-0.9.6.1]# make
[root@www eaccelerator-0.9.6.1]# make install
[root@www eaccelerator-0.9.6.1]# ls /application/php/lib/php/extensions/no-debug-non-zts-20090626/
eaccelerator.so imagick.so memcache.so pdo_mysql.so
[root@www eaccelerator-0.9.6.1]# cd ..
mkdir -p /tmp/eaccelerator
chown -R nginx.nginx /tmp/eaccelerator
[root@www lib]# mkdir -p /tmp/eaccelerator
[root@www lib]# chown -R nginx.nginx /tmp/eaccelerator
[root@www lib]# ls -ld /tmp/eaccelerator
drwxr-xr-x. 2 nginx nginx 4096 May 17 09:23 /tmp/eaccelerator
参数 | 说明 |
---|---|
[eaccelerator] | eaccelerator加速模块 |
extension=eaccelerator.so | 加载eAccelcrator加速模块。路径相对于extension_dir的配置。 |
eaccelerator.shm_size=“64” | 存储缓存数据的共享内存大小。如果为0, 则最大值看内核配置/proc/sys/kerael/shmmax。 |
eaccelerator.cache_dir="/tmp/eaccelerator" | 磁盘缓存存储路径。缓存内容为precompiled code、session、data、content 和user entries。默认路径为“/tmp/eaccelerator"。 |
eaccelerator.enable=“1” | eAccelerator 缓存生效开关。1为默认值,即生效;0 为关闭,不生效。 |
eaccelerator.optimizer=“1” | 加速PHP 代码执行速度,1为默认值,表示激活;0 为不激活。用于缓存前的代码加速。 |
eaccelerator.check_mtime=“1” | 检查缓存修改时间,决定代码是否需要重新编译,1为激活,是默认值。 |
eaccelerator.debug=“0” | 缓存加速调试,0为关闭,1为打开,打开后可以看到缓存加速信息。 |
eaccelerator.filter="" | 设定对象是否缓存规则,空表示不设定。 |
eaccelerator.shm_max=“0” | 可以被放罚的缓存最大值,0是不限制。 |
eaccelerator.shm_ttl=“3600” | 缓存文件的生存期。 |
eaccelerator.shm_prune_period=“3600” | 当共享内存空间不够时,从共享内存中移除旧数据的时间周期。 |
eaccelerator.shm_only=“0” | 是否允许缓存数据到磁盘。0为允许,但是对于session data and content caching 无影响。 |
eaccelerator.compress=“1” | 是否开启压缩。1为开启。 |
eaccelerator.compress_level=“9” | 压缩级别。9为最高。 |
eaccelerator.keys=“shm_and_disk” | 控制keys缓存位置。 shm_and_disk: 在共享内存和磁盘上缓存数据(默认值); shm: 如果共享内存已满或数据大于内核设定值,则在共享内存或磁盘两者择一; shm_only: 在共享内存上缓存数据; disk_only: 在磁盘上缓存数据; none: 不缓冲 |
eaccelerator.sessions=“shm_and_disk” | 控制sessions缓存位置 |
eaccelerator.content=“shm_and_disk” | 控制内容缓存位置 |
[root@www lib]# vim php.init
[eaccelerator]
extension=eaccelerator.so
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
/application/php/bin/php -v
[root@www lib]# /application/php/bin/php -v
PHP 5.3.27 (cli) (built: May 14 2021 10:24:11)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator
[root@www lib]# killall php-fpm
[root@www lib]# ps -ef | grep php-fpm
[root@www lib]# /application/php/sbin/php-fpm
[root@www lib]# ps -ef | grep php-fpm
访问检查
访问网址:blog.test_lnmp.org/viem_info.php
页内搜索:eaccelerator
查看缓冲目录
find /tmp/eaccelerator/ -type f | xargs file
查找普通类型(f)的文件find /tmp/eaccelerator/ -type f
;
xargs捕获上一个命令find /tmp/eaccelerator/ -type f
的结果,传递下一个命令file
;
file
辨识文件类型。
/tmp/eaccelerator/4/6/eaccelerator-1502.386231: data
内容为eaccelerator-1502.386231
类型为data
[root@www lib]# ls -l /tmp/eaccelerator/
total 64
drwxrwxrwx. 18 root root 4096 May 17 09:29 0
drwxrwxrwx. 18 root root 4096 May 17 09:29 1
drwxrwxrwx. 18 root root 4096 May 17 09:29 2
drwxrwxrwx. 18 root root 4096 May 17 09:29 3
drwxrwxrwx. 18 root root 4096 May 17 09:29 4
drwxrwxrwx. 18 root root 4096 May 17 09:29 5
drwxrwxrwx. 18 root root 4096 May 17 09:29 6
drwxrwxrwx. 18 root root 4096 May 17 09:29 7
drwxrwxrwx. 18 root root 4096 May 17 09:29 8
drwxrwxrwx. 18 root root 4096 May 17 09:29 9
drwxrwxrwx. 18 root root 4096 May 17 09:29 a
drwxrwxrwx. 18 root root 4096 May 17 09:29 b
drwxrwxrwx. 18 root root 4096 May 17 09:29 c
drwxrwxrwx. 18 root root 4096 May 17 09:29 d
drwxrwxrwx. 18 root root 4096 May 17 09:29 e
drwxrwxrwx. 18 root root 4096 May 17 09:29 f
[root@www lib]# find /tmp/eaccelerator/ -type f | xargs file
/tmp/eaccelerator/4/6/eaccelerator-1502.386231: data
./configure --enable-xcache --with-php-config=/application/php/bin/php-config
[root@www tools]# rz
[root@www tools]# tar xf xcache-3.2.0.tar_2.gz
[root@www tools]# cd xcache-3.2.0/
[root@www xcache-3.2.0]# /application/php/bin/phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
[root@www xcache-3.2.0]# ./configure --enable-xcache --with-php-config=/application/php/bin/php-config
[root@www xcache-3.2.0]# make
[root@www xcache-3.2.0]# make install
[root@www xcache-3.2.0]# ls /application/php/lib/php/extensions/no-debug-non-zts-20090626/
eaccelerator.so imagick.so memcache.so pdo_mysql.so xcache.so
[root@www xcache-3.2.0]# cd ..
参数 | 说明 |
---|---|
[xcache-common] extension=xcache.so |
加载xcache.so, 路径相对于extension_dir的配置。 |
[xcache.admin] xcache.admin.enable_auth=On xcache.admin.user="mOo" xcache.admin.pass=“md5 encrypted password” |
激活管理员认证。指定XCache管理员用户名和密码,密码根据http://xcache.lighttpd.net/demo/cacher/mkpassword.php地址产生,留空表示禁止管理页面 |
[xcache] | XCache缓存参数配置段 |
xcache.shm_scheme=“mmap” | 设置XCache 如何从系统分配共享内存 |
xcache.size=256M | 0为禁止缓存,非0则启用缓存。需要注意系统所允许的mmap最大值 |
xcache.count=2 | 指定将Cache切分成多少块,官方推荐设置为服务器CPU 的数量 |
xcache.slots=8K | hash槽个数的参考值,缓冲超过此数值时也没有任何问题 |
xcache.ttl=86400 | 设定Cache对象的生存期TTL (time to live ), 0 为永不过期 |
xcache.gc_interval=3600 | 回收器扫描过期的对象回收内存空间的间隔,0为不扫描,其他值的单位是秒 |
xcache.var_size=64M xcache.var_count=1 xcache.var_slots=8K xcache.var_ttl=0 xcache.var_gc_interval=300 |
变量缓存 |
xcache.readonly_protection=Off | 如果启用了该参数,将略微降低性能,但会提高一定的安全系数。这个选项对于xcacbe.mmap_patb = /dev/zero无效 |
xcache.mmap_path="/dev/zero" | 对于nix, xcache.mmap_path是一个文件路径而非目录。如果要启用该参数,请使用"/tmp/xcache"这样的路径,而不是"/dev/"。如果开启了xcache. readonly_protection参数,不同进程组的PHP将不会共享同一个/tmp/xcache路径 |
xcache.coredump_directory="" | 当XCache crash后,是否把数据保存到指定路径 |
xcache.disable_on_crash=Off | 当XCache发生crash 时,自动关闭XCache 缓存 |
egrep -v ";|^$" /home/centos/tools/xcache-3.2.0/xcache.ini
";|^$"
:注释符号;
,^$
匹配从开头到结尾-v参数
反选[root@www lib]# egrep -v ";|^$" /home/centos/tools/xcache-3.2.0/xcache.ini
[root@www lib]# vim php.ini
[xcache-common]
extension = xcache.so
[xcache.admin]
xcache.admin.enable_auth = On
xcache.admin.user = "mOo"
xcache.admin.pass = "md5 encrypted password"
[xcache]
xcache.shm_scheme = "mmap"
xcache.size = 256M
xcache.count = 2
xcache.slots = 8K
xcache.ttl = 86400
xcache.gc_interval = 3600
xcache.var_size = 64M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.var_namespace_mode = 0
xcache.var_namespace = ""
xcache.readonly_protection = Off
xcache.mmap_path = "/dev/zero"
xcache.coredump_directory = ""
xcache.coredump_type = 0
xcache.disable_on_crash = Off
xcache.experimental = Off
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off
[xcache.coverager]
xcache.coverager = Off
xcache.coverager_autostart = On
xcache.coveragedump_directory = ""
/application/php/bin/php -v
[root@www lib]# /application/php/bin/php -v
PHP 5.3.27 (cli) (built: May 14 2021 10:24:11)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
with XCache v3.2.0, Copyright (c) 2005-2014, by mOo
with XCache Cacher v3.2.0, Copyright (c) 2005-2014, by mOo
echo -n "xxxx" | md5sum
[root@www lib]# echo -n "xxxx" | md5sum
81dc9bdb52d04dc20089dbd8313ed055 -
[root@www lib]# vim php.ini
[xcache.admin]
xcache.admin.enable_auth = On
xcache.admin.user = "centos"
xcache.admin.pass = "81dc9bdb52d04dc20089dbd8313ed055"
cp -a htdocs/ /application/nginx/html/vps/realm_name/blog/Xcache
chown -R nginx.nginx /application/nginx/html/vps/realm_name/blog/Xcache
[root@www xcache-3.2.0]# cd /home/centos/tools/xcache-3.2.0
[root@www xcache-3.2.0]# cp -a htdocs/ /application/nginx/html/vps/realm_name/blog/Xcache
[root@www xcache-3.2.0]# chown -R nginx.nginx /application/nginx/html/vps/realm_name/blog/Xcache
[root@www xcache-3.2.0]# pkill php-fpm
[root@www xcache-3.2.0]# /application/php/sbin/php-fpm
--enable-opcacbe
,即可。./configure --enable-opcache --with-php-config=/application/php/bin/php-config
[root@www tools]# rz
[root@www tools]# tar xf zendopcache-7.0.5.tgz
[root@www tools]# cd zendopcache-7.0.5
[root@www zendopcache-7.0.5]# /application/php/bin/phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
[root@www zendopcache-7.0.5]# ./configure --enable-opcache --with-php-config=/application/php/bin/php-config
[root@www zendopcache-7.0.5]# make
[root@www zendopcache-7.0.5]# make install
Installing shared extensions: /application/php/lib/php/extensions/no-debug-non-zts-20090626/
[root@www zendopcache-7.0.5]# ls /application/php/lib/php/extensions/no-debug-non-zts-20090626/
eaccelerator.so imagick.so memcache.so opcache.so pdo_mysql.so xcache.so
[root@www zendopcache-7.0.5]# cd ..
参数 | 说明 |
---|---|
opcache.memory_consumption=128 | OPcache共享内存空间大小,用于存放precompiled PHP code,默认为64, 单位为Mbytes |
opcache.interned_strings_buffer=8 | 默认值为4,interned strings 内存的数量,单位是M |
opcache.max_accelerated_files=4000 | 默认值为2000, OPcache散列表的key的最大数量 |
opcache.revalidate_freq=60 | 默认值为2, 检查文件时间戳的频率,用于共享内存分配的变化 |
opcache.fast_shutdown=1 | 默认值为0,如果激活,一个快速的关闭队列将被用来加速代码 |
opcache.enable_cli=1 | 默认值为0,激活PHP_CLI的OPcache,用于测试和调试 |
extension=opcache.so
必须注释掉,否则报错[root@www ~]# cd /application/php/lib
[root@www lib]# vim php.ini
[opcache]
zend_extension=/application/php/lib/php/extensions/no-debug-non-zts-20090626/opcache.so
;extension=opcache.so ;必须注释掉,否则报错
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
/application/php/bin/php -v
[root@www lib]# /application/php/bin/php -v
PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) 'opcache.so' in Unknown on line 0
PHP 5.3.27 (cli) (built: May 14 2021 10:24:11)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.5, Copyright (c) 1999-2015, by Zend Technologies
[root@www lib]# killall php-fpm
[root@www lib]# /application/php/sbin/php-fpm
访问测试
访问网站:blog.test_lnmp.org/viem_info.php
页内搜索:ZendOpcache
[root@www lib]# vim /etc/fstab
tmpfs /tmp/eaccelerator tmpfs rw,relatime,size=16384k 0 0
[root@www lib]# mount -a
[root@www lib]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 19G 2.9G 15G 17% /
tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 190M 53M 128M 30% /boot
tmpfs 16M 0 16M 0% /tmp/eaccelerator
[root@www lib]# grep eacc /proc/mounts
tmpfs /tmp/eaccelerator tmpfs rw,rootcontext=unconfined_u:object_r:user_tmp_t:s0,seclabel,relatime,size=16384k 0 0
[root@www lib]# vim /etc/sysctl.conf
30 # Controls the default maxmimum size of a mesage queue
31 kernel.msgmnb = 65536
32
33 # Controls the maximum size of a message, in bytes
34 kernel.msgmax = 65536
35
36 # Controls the maximum shared segment size, in bytes
37 kernel.shmmax = 68719476736
38
39 # Controls the maximum number of shared memory segments, in pages
40 kernel.shmall = 4294967296
ctags
webbench-1.5/Makefile
,无需./configure
[root@www ~]# yum install -y ctags
[root@www ~]# cd /home/centos/tools
[root@www tools]# rz
[root@www tools]# tar xf webbench-1.5.tar_3.gz
[root@www tools]# cd webbench-1.5
[root@www webbench-1.5]# ./configure
-bash: ./configure: No such file or directory
[root@www webbench-1.5]# tree -L 2
.
|-- COPYRIGHT -> debian/copyright
|-- ChangeLog -> debian/changelog
|-- Makefile
|-- debian
| |-- changelog
| |-- control
| |-- copyright
| |-- dirs
| `-- rules
|-- socket.c
|-- webbench.1
`-- webbench.c
[root@www webbench-1.5]# make
略
install: cannot create regular file `/usr/local/man/man1': No such file or directory
make: *** [install] Error 1
[root@www webbench-1.5]# mkdir -p /usr/local/man/man1
[root@www webbench-1.5]# make install
[root@www webbench-1.5]# make clean
[root@www webbench-1.5]# webbench
webbench [option]... URL
-f|--force Don't wait for reply from server.
-r|--reload Send reload request - Pragma: no-cache.
-t|--time <sec> Run benchmark for <sec> seconds. Default 30.
-p|--proxy <server:port> Use proxy server for request.
-c|--clients <n> Run <n> HTTP clients at once. Default one.
-9|--http09 Use HTTP/0.9 style requests.
-1|--http10 Use HTTP/1.0 protocol.
-2|--http11 Use HTTP/1.1 protocol.
--get Use GET request method.
--head Use HEAD request method.
--options Use OPTIONS request method.
--trace Use TRACE request method.
-?|-h|--help This information.
-V|--version Display program version.
webbench -c 100 -t 30 http://www.baidu.com/
[root@www tools]# webbench -c 100 -t 30 http://www.baidu.com/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://www.baidu.com/
100 clients, running 30 sec.
Speed=612 pages/min, 2354904 bytes/sec.
Requests: 264 susceed, 42 failed.
echo "192.168.10.10 blog.test_lnmp.org" >>/etc/hosts
[root@www tools]# webbench -c 100 -t 30 http://blog.test_lnmp.org/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://blog.test_lnmp.org/
100 clients, running 30 sec.
Connect to server failed. Aborting benchmark.
[root@www tools]# ping http://blog.test_lnmp.org/
ping: unknown host http://blog.test_lnmp.org/
[root@www tools]# echo "192.168.10.10 blog.test_lnmp.org" >>/etc/hosts
[root@www tools]# tail -1 /etc/hosts
192.168.10.10 blog.test_lnmp.org
[root@www tools]# ping -c 3 blog.test_lnmp.org
PING blog.test_lnmp.org (192.168.10.10) 56(84) bytes of data.
64 bytes from blog.test_lnmp.org (192.168.10.10): icmp_seq=1 ttl=64 time=0.009 ms
64 bytes from blog.test_lnmp.org (192.168.10.10): icmp_seq=2 ttl=64 time=0.018 ms
64 bytes from blog.test_lnmp.org (192.168.10.10): icmp_seq=3 ttl=64 time=0.017 ms
--- blog.test_lnmp.org ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.009/0.014/0.018/0.006 ms
[root@www tools]# webbench -c 100 -t 30 http://blog.test_lnmp.org/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://blog.test_lnmp.org/
100 clients, running 30 sec.
Speed=2010 pages/min, 226692 bytes/sec.
Requests: 1005 susceed, 0 failed.
[root@www tools]# webbench -c 500 -t 30 http://blog.test_lnmp.org/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://blog.test_lnmp.org/
500 clients, running 30 sec.
Speed=7268 pages/min, 255686 bytes/sec.
Requests: 3634 susceed, 0 failed.
[root@www tools]# webbench -c 1000 -t 30 http://blog.test_lnmp.org/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://blog.test_lnmp.org/
1000 clients, running 30 sec.
Speed=717534 pages/min, 148908 bytes/sec.
Requests: 3428 susceed, 355339 failed.
❶压力测试工作应该放到产品上线之前,而不是上线以后 ;
❷测试的时候,最好把测试机的监控都打开;
❸测试时尽量跨公网进行,而不是内网;
❹测试时并发应当由小逐渐加大,比如并发100时观察一下网站负载是多少、打开是否流畅,并发200时又是多少、网站打开缓慢时并发是多少、网站打不开时并发又是多少 ;
❺应尽量进行单元测试,如B2C网站可以着重测试购物车、推广页面等,因为这些页面占整个网站访问量比重较大;
❻获得的数据越多越准确。
1、跟老男孩学Linux运维:Web集群实战
2、LC_ALL=C的含义
3、WebBench详解