centos7部署LAMP+xcache(module模式)
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# yum -y install httpd php php-mysql mariadb-server
# rpm -q php
php-5.4.16-36.1.el7_2.1.x86_64
#
# rpm -q httpd
httpd-2.4.6-40.el7.centos.1.x86_64
#
# rpm -q php-mysql
php-mysql-5.4.16-36.1.el7_2.1.x86_64
#
# rpm -q mariadb-server
mariadb-server-5.5.47-1.el7_2.x86_64
#
# rpm -q mariadb
mariadb-5.5.47-1.el7_2.x86_64
2、启动所有的服务查看是否正常
1
2
3
4
5
6
7
8
9
10
11
12
13
启动httpd服务的时候最好是添加下以下一条,否则要解析,启动老慢了
# vim /etc/httpd/conf/httpd.conf
ServerName localhost:80
# systemctl start httpd.service
# systemctl start mariadb.service
# 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做准备
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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>
# 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、准备网页及日志路径等信息
1
2
3
4
5
6
7
8
# mkdir -p /data/www1/vhost1#####DocumentRoot路径
# mkdir -p /data/www2/vhost2
# echo "vhost1" > /data/www1/vhost1/index.html###网页路径
# echo "vhost2" > /data/www2/vhost2/index.html
# mkdir -p /var/log/www1/vhost1###日志路径
# mkdir -p /var/log/www2/vhost2
5、检查配置文件是否正常,然后重新加载配置,测试
1
2
3
4
5
# httpd -t
Syntax OK
# systemctl reload httpd.service
注:由于我们有搭建DNS所有此处我就把相关的信息给写在了hosts文件中了
6、此处如果测试网页是没问题的,那我们接下了就要测试下php是否正常,编辑php文件在网页路径下。
1
2
3
4
# vim /data/www1/vhost1/index.php
<?php
phpinfo();
?>
7、测试下php连接数据是否正常
1
2
3
4
5
6
7
8
9
<?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进行授权用户可以进行访问和连接
1
2
MariaDB [(none)]> create database wpdb
MariaDB [(none)]> grant all on wpdb.* to 'test'@'192.168.%.%' identified by 'test';
9、现在在测试下我们php和mysq连接
10、测试结果没有问题那么我们的LAMP环境部署ok可,接下来我们就在两个虚拟主机上分别部署下软件应用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
首先我们部署WordPress在第一个wp.magedu.com虚拟主机上
# unzip phpMyAdmin-4.0.5-all-languages.zip
# cp -r wordpress /data/www1/vhost1/
# cp wp-config-sample.php wp-config.php
# 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这个虚拟主机上
1
2
3
4
5
6
7
# mv phpMyAdmin-4.0.5-all-languages /data/www2/vhost2/
# cd phpMyAdmin-4.0.5-all-languages/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这个包,那么我们安装下就可以了
1
2
# yum -y install php-mbstring
# systemctl reload httpd
13、当上这做完了后,我们可以登录到系统了,但是么有权限创建表等,所有在授权下就ok了
1
MariaDB [(none)]> grant all on *.* to 'test'@'192.168.%.%' identified by 'test';
14、现在我们LAMP平台部署软件就到此结束了,但是们网站压力测试怎么样呢??下面我们测试下看看:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 (mean)
Time per request: 3.756 (mean, across all concurrent requests)
Transfer rate: 176.56 received
Connection Times (ms)
minmean[+/-sd] median max
Connect: 3123 316.7 11 1151
Processing: 4 51 131.4 11 2272
Waiting: 4 45 111.4 11 2272
Total: 9174 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,然后测试下看是否能提升访问速度呢!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# yum list | grepphp-xcache
php-xcache.x86_64 3.1.1-1.el7 epel
# yum -y install php-xcache
# cd/etc/php.d/
# ls
curl.inifileinfo.inijson.inimbstring.inimysqli.inimysql.inipdo.ini
pdo_mysql.inipdo_sqlite.iniphar.inisqlite3.inixcache.inizip.ini
###安装后生成xcache.ini文件
而且我们php测试页面中也可以看到有xcache加载
# vim /etc/php.d/xcache.ini
xcache.size= 300M####修改下缓存的大小
16、我们现在做下测试看看情况吧:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 (mean) ###服务器收到请求响应页面花费时间
Time per request: 2.133 (mean, across all concurrent requests)#并发每个消耗时间
Transfer rate: 310.87 received ###平均每秒流量
Connection Times (ms)
minmean[+/-sd] median max
Connect: 4 68 225.0 15 1014
Processing: 4 5695.2 20 470
Waiting: 4 5595.5 19 470
Total: 9124 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)
新手上路有不对的地方请多多指正,谢谢!
页:
[1]