前提:
解决部分加速软件的Perl编译问题适用于LAMP和LNMP
1)配置环境变量LC_ALL
echo 'export LC_ALL=C'>> /etc/profie#">>"表示文件追加内容
tail -l /etc/profile
source /etc/profie
echo $LC_ALL
2)安装Perl相关依赖
yum -y perl-CPAN或yum -y install perl-devel
#若不安装在安装ImageMagick时可能报错
一、安装加速器扩展
1.eAccelerator缓存加速模块
cd /home/hty/tools
wget http://soft.vpser.net/web/eaccelerator/eaccelerator-eaccelerator-42067ac.tar.gz
tar xf eaccelerator-eaccelerator-42067ac.tar.gz
cd eaccelerator-eaccelerator-42067ac
/application/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/application/php/bin/php-config
make
make install
ls /application/php.3.27/lib/php/extensions/no-debug-non-zts-20090626/
cd ..
出现了如下信息:
[root@instance-yf0xzby9 eaccelerator-eaccelerator-42067ac]# ls /application/php.3.27/lib/php/extensions/no-debug-non-zts-20090626/
eaccelerator.so
2.Xache缓存加速模块
cd /home/hty/tools
wget https://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.bz2
tar xf xcache-3.2.0.tar.bz2
cd xcache-3.2.0
/application/php/bin/phpize
./configure --enable-xcache --with-php-config=/application/php/bin/php-config
make
make install
ls -l /application/php.3.27/lib/php/extensions/no-debug-non-zts-20090626/
cd ..
3.官方加速插件ZendOpcache
cd /home/hty/tools
wget https://pecl.php.net/get/zendopcache-7.0.5.tgz
tar xf zendopcache-7.0.5.tgz
cd zendopcache-7.0.5
/application/php/bin/phpize
./configure --enable-opcache --with-php-config=/application/php/bin/php-config
make
make install
ls -l /application/php.3.27/lib/php/extensions/no-debug-non-zts-20090626/
cd ..
二、数据库缓存及其他PHP扩展插件
1.Memcached缓存软件
优点:开源、支持高性能、高并发、分布式的内存缓存
RDBNS缺点:数据量大,访问集中时,出现负担加重、数据库响应慢、网站打开延迟等问题
目的:提高网站并发能力和可扩展性
功能:一般用来保存网站中经常被读取的对象或数据
cd /home/hty/tools
wget -q https://pecl.php.net/get/memcached-2.2.7.tgz
tar zxf memcached-2.2.7.tgz
cd memcached-2.2.7
/application/php/bin/phpize
./configure --enable-memcache --with-php-config=/application/php/bin/php-config
make
make install
ls -l /application/php.3.27/lib/php/extensions/no-debug-non-zts-20090626/
cd ..
2.安装PDO_MYSQL扩展模块
cd /home/hty/tools
wget -q https://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
tar zxf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2
/application/php/bin/phpize
./configure --with-php-config=/application/php/bin/php-config --with-pdo-mysql=/application/mysql
make
make install
ls -l /application/php.3.27/lib/php/extensions/no-debug-non-zts-20090626/
cd ../
**此步不是安装PHP扩展,因此不会生成.so文件
3.安装图像处理程序及imagick扩展模块
事先在http://www.imagemagick.org/download/ 下载好对应的软件
ls -l ImageMagick-6.5.1-2.tar.gz
tar xf ImageMagick-6.5.1-2.tar.gz
cd ImageMagick-6.5.1-2
./configure
make && make install
cd ..
###echo $?
返回0表示 安装成功,1表示失败
4.安装imagick PHP扩展插件
iamgick插件可以提供PHP调用ImageMagick功能的扩展模块,使ImagicMagick提供的api进行
图片的创建与修改、压缩等操作可以进行
下载地址:http://pecl.php.net/package/imagick
版本号:
imagick:2.3.0.tgz
php:5.3.27
tar zxf imagick-2.3.0.tgz
cd imagick-2.3.0
/application/php/bin/phpize
./configure --with-php-config=/application/php/bin/php-config
make
make install
ls -l /application/php.3.27/lib/php/extensions/no-debug-non-zts-20090626/
cd ../
三、配置PHP加速与缓存相关的扩展插件模块
1.配置Memcache/PDO_MYSQL/imagick模块生效
1)修改PHP的配置文件php.ini
cd /application/php/lib
cp php.ini php.ini.hty.20180929 #备份文件
sed -i 's#; extension_dir = "./"#extension_dir = "/application/php.3.27/lib/php/extensions/no-debug-non-zts-20090626/"#g' php.ini
grep "extension_dir =" php.ini
cat >> /application/php/lib/php.ini<<EOF
;--cache ext start by hty 2018-09-29--
extension = memcache.so
extension = pdo_mysql.so
extension = imagick.so
;--cache ext end by hty 2018-09-29-- #注释为“;”,不是“#”
tail -5 /application/php/lib/php.ini
2.检查配置生效情况
1)重启PHP服务,编写测试程序phpinfo
pkill php-fpm
ps -ef|grep php-fpm|grep -v prep
/application/php/sbin/php-fpm
ps -ef|grep php-fpm|grep -v grep|wc -l
然后在前文blog站点目录下增加phpinfo.php代码文件
cd /application/nginx/conf/extra
cat blog.conf
cat >>/application/nginx/html/blog/view_info.php<<EOF
<?php phpinfo();?>
EOF
cat /application/nginx/html/blog/view_info.php
2)检查Memcached扩展插件
通过快捷键Ctrl+F,在界面搜索相应的插件
配置好客户端的解析,在浏览器中输入http://blog.etiantian.org/view_info.php
则可以看到PHP的界面
3)检查PDO_MYSQL扩展插件
同理搜索PDO_MYSQL
3.配置eAccelerator插件生效并优化参数
1)配置eAccelerator缓存目录
mkdir -p /tmp/eaccelerator
chown -R nginx.nginx /tmp/eaccelerator
ls -ld /tmp/eaccelerator
2)配置eAccelerator参数
cat >> /application/php/lib/php.ini<<EOF
[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"
EOF
tail -15 php.ini
测试缓存的配置情况
/application/php/bin/php -v
重启PHP服务的命令:
pkill php-fpm
ps -ef|grep php-fpm|grep -v prep
/application/php/sbin/php-fpm
ps -ef|grep php-fpm|grep -v grep|wc -l
查看缓存目录/tmp/eaccelerator
ls -l /tmp/eaccelerator
4.使用tmpfs优化eAccelerator缓存目录
mount -t tmpfs -o size=16m tmpfs /tmp/eaccelerator #创建16创建16M大小的tmpfs 类型文件系统挂载到/tmp/eaccelerator
df -h #检查挂载的情况
grep eacc /proc/mounts #检查挂载的情况
tail -1 /etc/fstab #配置永久挂载,生产场景size可以根据实际情况调整
umount /tmp/eaccelerator/
grep eacc /proc/mounts
mount -a #测试永久挂载
grep eacc /proc/mounts
四、压力测试
软件:webbench
cd /home/hty/tools/
wget http://www.ha97.com/code/webbench-1.5.tar.gz
tar zxvf webbench-1.5.tar.gz
cd webbench-1.5
make
make install
****
安装报错:install: cannot create regular file `/usr/local/man/man1': No such file or directory
原因是没有/usr/local/man/man1目录则直接创建目录
mkdir -p /usr/local/man/man1
****
检查安装是否成功
echo $?
测试命令:
webbench -c [并发数] -t [运行时间] URL[网址]
webbench -c 10 -t 10 http://blog.etiantian.org/view_info.php
结果:
[root@instance-yf0xzby9 webbench-1.5]# webbench -c 10 -t 10 http://blog.etiantian.org/view_info.php
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://blog.etiantian.org/view_info.php
10 clients, running 10 sec.
Speed=29262 pages/min, 26821110 bytes/sec.
Requests: 4877 susceed, 0 failed.
测试结果:每秒钟响应请求数:29262 pages/min,每秒传输数据量:26821110 bytes/sec
返回数:4877 susceed, 0 failed
webbench帮助:
查看webbench使用帮助:
[root@web02 ~]# webbench –help
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.