kjfhgds 发表于 2016-7-19 09:02:16

LAMP 搭建和压力测试

LAMP 搭建和压力测试 (1) CentOS 7, apm+xcache, rpm包, phpmodule;
                   a)一个虚拟主机提供phpMyAdmin,另一个虚拟主机提供wordpress;
                   b)为phpMyAdmim提供https服务;         
(2) CentOS 7, amp + xcache, rpm包,php-fpm;
                   a)httpd, php, mariadb分别部署在一个单独的主机上;
                   b)一个虚拟主机提供phpMyAdmin,另一个虚拟主机提供wordpress;
                   c)为phpMyAdmim提供https服务;
(3) 对以上所有部署做压力测试,并对比测试结果,写出测试报告;

Server规划
                   CentOS71(172.16.126.1)                            httpd+php+mariadb
                   CentOS72(172.16.126.3192.168.0.72)php-fpm
                   CentOS73(192.168.0.74)                            mariadb
搭建
(1).
         a).安装相应软件(Cent71):
                   yuminstall httpd mod_ssl
                   yuminstall php php-mysql php-mbstring php-xcache
                   yuminstall mariadb mariadb-server
                   ls/var/www/html
                   drwxr_xr_x…………………………………………….wordpress
                   drwxr_xr_x……………………………………………..phpMyAdmin
                   rm–f /etc/httpd/cond.f/ssl.conf
         b).配置文件:
                   cat/etc/httpd/conf.d/vhost.conf
                   Listen443
<VirtualHost 172.16.126.1:443>                            ServerName www.pma.magedu.com
                            DocumentRoot /data/web/www1

                            SSLENGINE on
                            SSLCertificateFile /etc/httpd/CA/cacert.pem
         SSLCertificateKeyFile/etc/httpd/CA/cakey.pem#密钥证书在上一博客有申请
                            <Directory /data/web/www1 >
                                    Options ALL
                                    AllowOverride none
                                    Require all granted
                            </Directory>            
</VirtualHost>
<VirtualHost 172.16.126.1:80>                            ServerName www.wordpress.magedu.com
                            DocumentRoot /data/web/www1
                            <Directory /data/web/www1>
                                    Options ALL
                                    AllowOverride none
                                    Require all granted
                           </Directory>
</VirtualHost>         systemctlstart httpd
         systemctlstart mariadb
         mysql
         Mariadb>createdatabase wordpress
         Mariadb>grantall on wordpress.* ‘testuser’@’172.16.%.%’ identified by ‘password’
         Mariadb>\q
         -----文件/data/web/www1/wordpress/wp-config.php修改
define('DB_NAME', 'wordpress');define('DB_USER', 'testuser');define('DB_PASSWORD', 'passwrod');define('DB_HOST', '172.16.126.1');         ---------文件 /data/web/www1/phpMyAdmin/libraries/config.default.php修改
                            $cfg['blowfish_secret']= 'HmVGDMOPXOSH2xH';
                            $cfg['Servers'][$i]['host']= '172.16.126.1';
                            $cfg['Servers'][$i]['port']= '3306';
############################ok

2).
         a).安装软件与配置
echo–e “ProxyRequests off\nProxyPassMatch ^/(.*\.php)$fcgi://172.16.126.3:9000/data/web/www1\n”>> /etc/httpd/conf.d/vhost.conf
                   yuminstall mariabd mariadb-server
                   systemctlstart mariadb
                   mysql
                   Mariadb>createdatabase wordpress
Mariadb>grantALL on wordpres.* to ‘testuser’@’192.168.0.%’ identified by ‘passwrod’Mariadb>\q
                   yuminstall php-fpm php-mysql php-mbstring php-mysql
                   ----文件/etc/php-fpm.d/www.conf中
                                     listen= 172.16.126.3:9000
                                     listen.allowed_clients= 172.16.126.1
                   tail-2 /etc/php-fpm.d/www.conf
                            php_value= files
php_value = /var/lib/php/session
                   mkdir/var/lib/php/session
                   chonwapache:apache /var/lib/php/session
                  
                   mkdir–p /data/web~
                   scproot@172.16.126.1:/data/web/www1/data/web/
                   -----文件/data/web/www1/wordpress/wp-config.php修改
define('DB_NAME', 'wordpress');define('DB_USER', 'testuser');define('DB_PASSWORD', 'passwrod');define('DB_HOST', '192.168.0.74');                   ---------文件 /data/web/www1/phpMyAdmin/libraries/config.default.php修改
                            $cfg['blowfish_secret']= 'HmVGDMOPXOSH2xH';
                            $cfg['Servers'][$i]['host']= '192.168.0.74';
                            $cfg['Servers'][$i]['port']= '3306';

                   systemctlstart php-fpm
################################ok

压力测试Point 测试脚本:
cat netyali
#!/bin/bash
#usage netyali
#url 测试url如:http://172.16.126.1/index.php
#file 数据保存的路径
for i in 1 2 4 8 16 32 64 128
do
         forj in10 100 200 500 1000 15002000 25003000 4000
         do
                   if[ $i -le $j ]; then

                   /usr/local/apache24/bin/ab-c $i -n $j $1 |sed -r -e '/^$/d'-e'/^[[:space:]]/d'|tail-n +5|head -16|tr -s " "|gawk -F:'{ printf("%s\t",$2)}END{print}' >>$2
                   fi
         done
done
#####测试https时 将head-16 中的16 改成17 因为ab多了一条SLLprotocol
----数据格式化命令:gawk-F "\t" '{for(i=1;i<NF;i++){split($i,a," "); b=a}for (j in b){printf("%s ",b)} printf("\n")}'
#注意命令的数据左右位置和ab命令上下位置不一致每次测试出75条记录

cat/data/web/www1/inde.php
172.16.126.1
<?php
                   $conn= mysql_connect('172.16.126.1','testuser','mageedu');
                   if($conn)
                            echo" 172.16.126.1 OK";
                   else
                            echo"172.16.126.1 Failure";
?>
<?php
         phpinfo();
?>
cat /data/web/www1/inde.php
172.16.126.3
<?php
                $conn =mysql_connect('192.168.0.74','testuser','mageedu');
                if($conn)
                        echo "192.168.0.74 OK";
                else
                        echo "192.168.0.74Failure";
?>
<?php
         phpinfo();
?>



页: [1]
查看完整版本: LAMP 搭建和压力测试