centos7通过RPM包部署LAMP+xcache (php module)
环境要求:
(1)一个虚拟主机提供phpMyadmin
(2)一个虚拟主机提供WordPress
(3)利用xcache缓存来进行页面加速
(4)进行页面压力测试
wp.magedu.com------>提供WordPress
pma.magedu.com---->提供phpMyAdmin
1、安装httpd、php、php-myql、mariadb-server
[root@bogon ~]# yum -y install httpd php php-mysql mariadb-server [root@bogon ~]# rpm -q php php-5.4.16-36.1.el7_2.1.x86_64 [root@bogon ~]# [root@bogon ~]# rpm -q httpd httpd-2.4.6-40.el7.centos.1.x86_64 [root@bogon ~]# [root@bogon ~]# rpm -q php-mysql php-mysql-5.4.16-36.1.el7_2.1.x86_64 [root@bogon ~]# [root@bogon ~]# rpm -q mariadb-server mariadb-server-5.5.47-1.el7_2.x86_64 [root@bogon ~]# [root@bogon ~]# rpm -q mariadb mariadb-5.5.47-1.el7_2.x86_64
2、启动所有的服务查看是否正常
启动httpd服务的时候最好是添加下以下一条,否则要解析,启动老慢了 [root@bogon ~]# vim /etc/httpd/conf/httpd.conf ServerName localhost:80 [root@bogon ~]# systemctl start httpd.service [root@bogon ~]# systemctl start mariadb.service [root@bogon ~]# ss -tnl ####查看下监听地址是否正常 State Recv-Q Send-Q Local Address:Port LISTEN 0 50 *:3306 ##监听的mysql端口 LISTEN 0 5 192.168.122.1:53 LISTEN 0 128 *:22 LISTEN 0 128 :::80 ##监听的httpd服务端口
3、配置虚拟主机,提供两个虚拟主机为WordPress何phpmyadmin做准备
[root@bogon ~]# vim /etc/httpd/conf.d/vhost1.conf ###第一个虚拟主机 <VirtualHost 192.168.1.104:80> DocumentRoot /data/www1/vhost1 ServerName wp.magedu.com ErrorLog "/var/log/www1/vhost1/error_log" ##错误日志 CustomLog "/var/log/www1/vhost1/access_log" common ###访问日志 <Directory "/data/www1/vhost1"> Options None AllowOverride None Require all granted ##此处需要授权,否则无法访网页 </Directory> </VirtualHost> [root@bogon ~]# vim /etc/httpd/conf.d/vhost2.conf ###第二个虚拟主机 <VirtualHost 192.168.1.104:80> DocumentRoot /data/www2/vhost2 ServerName pma.magedu.com ErrorLog "/var/log/www2/vhost2/error_log" CustomLog "/var/log/www2/vhost2/access_log" common <Directory "/data/www2/vhost2"> Options None AllowOverride None Require all granted </Directory> </VirtualHost>
4、准备网页及日志路径等信息
[root@bogon ~]# mkdir -p /data/www1/vhost1 #####DocumentRoot路径 [root@bogon ~]# mkdir -p /data/www2/vhost2 [root@bogon ~]# echo "vhost1" > /data/www1/vhost1/index.html ###网页路径 [root@bogon ~]# echo "vhost2" > /data/www2/vhost2/index.html [root@bogon ~]# mkdir -p /var/log/www1/vhost1 ###日志路径 [root@bogon ~]# mkdir -p /var/log/www2/vhost2
5、检查配置文件是否正常,然后重新加载配置,测试
[root@bogon ~]# httpd -t Syntax OK [root@bogon ~]# systemctl reload httpd.service 注:由于我们有搭建DNS所有此处我就把相关的信息给写在了hosts文件中了
6、此处如果测试网页是没问题的,那我们接下了就要测试下php是否正常,编辑php文件在网页路径下。
[root@bogon ~]# vim /data/www1/vhost1/index.php <?php phpinfo(); ?>
7、测试下php连接数据是否正常
<?php $conn = mysql_connect(‘192.168.1.104‘,‘test‘,‘test‘); if ($conn) echo "mysql is ok"; else echo "mysql is bad"; phpinfo(); ?> 此时测试肯定是不成功的我没有mysq授权用户
8、登录mysq进行授权用户可以进行访问和连接
MariaDB [(none)]> create database wpdb MariaDB [(none)]> grant all on wpdb.* to ‘test‘@‘192.168.%.%‘ identified by ‘test‘;
9、现在在测试下我们php和mysq连接
10、测试结果没有问题那么我们的LAMP环境部署ok可,接下来我们就在两个虚拟主机上分别部署下软件应用
首先我们部署WordPress在第一个wp.magedu.com虚拟主机上 [root@bogon ~]# unzip phpMyAdmin-4.0.5-all-languages.zip [root@bogon ~]# cp -r wordpress /data/www1/vhost1/ [root@bogon wordpress]# cp wp-config-sample.php wp-config.php [root@bogon wordpress]# vim wp-config.php /** WordPress数据库的名称 */ define(‘DB_NAME‘, ‘wpdb‘); /** MySQL数据库用户名 */ define(‘DB_USER‘, ‘test‘); /** MySQL数据库密码 */ define(‘DB_PASSWORD‘, ‘test‘); /** MySQL主机 */ define(‘DB_HOST‘, ‘192.168.1.104‘);
11、ok接下来我们不部署phpMyadmin到pma.magedu.com这个虚拟主机上
[root@bogon ~]# mv phpMyAdmin-4.0.5-all-languages /data/www2/vhost2/ [root@bogon libraries]# cd phpMyAdmin-4.0.5-all-languages/libraries/ [root@bogon libraries]# vim config.default.php $cfg[‘blowfish_secret‘] = ‘W1rBVqdwufYEiymPTfOsUQ‘; $cfg[‘Servers‘][$i][‘host‘] = ‘192.168.1.104‘; $cfg[‘Servers‘][$i][‘user‘] = ‘test‘; $cfg[‘Servers‘][$i][‘password‘] = ‘test‘;
12、接下来我们访问下看看怎么样,其实会包错缺少php-mbstring这个包,那么我们安装下就可以了
[root@bogon ~]# yum -y install php-mbstring [root@bogon ~]# systemctl reload httpd
13、当上这做完了后,我们可以登录到系统了,但是么有权限创建表等,所有在授权下就ok了
MariaDB [(none)]> grant all on *.* to ‘test‘@‘192.168.%.%‘ identified by ‘test‘;
14、现在我们LAMP平台部署软件就到此结束了,但是们网站压力测试怎么样呢??下面我们测试下看看:
Document Path: /wordpress Document Length: 453 bytes Concurrency Level: 100 Time taken for tests: 3.756 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 679000 bytes HTML transferred: 453000 bytes Requests per second: 266.28 [#/sec] (mean) Time per request: 375.551 [ms] (mean) Time per request: 3.756 [ms] (mean, across all concurrent requests) Transfer rate: 176.56 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 3 123 316.7 11 1151 Processing: 4 51 131.4 11 2272 Waiting: 4 45 111.4 11 2272 Total: 9 174 350.8 30 3399 Percentage of the requests served within a certain time (ms) 50% 30 66% 39 75% 47 80% 223 90% 1015 95% 1030 98% 1223 99% 1228 100% 3399 (longest request)
15、我们就下来就安装下xcache来加速php,然后测试下看是否能提升访问速度呢!
[root@bogon ~]# yum list | grep php-xcache php-xcache.x86_64 3.1.1-1.el7 epel [root@bogon ~]# yum -y install php-xcache [root@bogon ~]# cd /etc/php.d/ [root@bogon php.d]# ls curl.ini fileinfo.ini json.ini mbstring.ini mysqli.ini mysql.ini pdo.ini pdo_mysql.ini pdo_sqlite.ini phar.ini sqlite3.ini xcache.ini zip.ini ###安装后生成xcache.ini文件 而且我们php测试页面中也可以看到有xcache加载 [root@bogon ~]# vim /etc/php.d/xcache.ini xcache.size = 300M ####修改下缓存的大小
16、我们现在做下测试看看情况吧:
Document Path: /wordpress Document Length: 453 bytes Concurrency Level: 100 Time taken for tests: 2.133 seconds ##所有请求处理完成花费时间 Complete requests: 1000 ##完成请求数 Failed requests: 0 ##失败数 Write errors: 0 Total transferred: 679000 bytes HTML transferred: 453000 bytes Requests per second: 468.82 [#/sec] (mean) ##每秒请求数的吞吐 Time per request: 213.303 [ms] (mean) ###服务器收到请求响应页面花费时间 Time per request: 2.133 [ms] (mean, across all concurrent requests)#并发每个消耗时间 Transfer rate: 310.87 [Kbytes/sec] received ###平均每秒流量 Connection Times (ms) min mean[+/-sd] median max Connect: 4 68 225.0 15 1014 Processing: 4 56 95.2 20 470 Waiting: 4 55 95.5 19 470 Total: 9 124 259.4 38 1432 Percentage of the requests served within a certain time (ms) 50% 38 66% 44 75% 49 80% 54 90% 256 95% 1015 98% 1224 99% 1228 100% 1432 (longest request)
新手上路有不对的地方请多多指正,谢谢!
centos7部署LAMP+xcache(module模式)
原文地址:http://maweijun.blog.51cto.com/8654192/1827491