什么是LAMP架构?
LANMP网络架构实现在国内外非常流行的Web框架,所谓的LAMP就是:
Linux操作系统
Apache网络服务器:处理http的请求、构建响应报文等自身服务;配置让Apache支持PHP程序的响应(通过PHP模块或FPM);配置Apache具体处理php程序的方法,如通过反向代理将php程序交给fcgi处理;
MySQL数据库:提供PHP程序对数据的存储;提供PHP程序对数据的读取
Perl、PHP或是Python等编程语言:其中的PHP可以提供apache的访问接口,即CGI或Fast CGI(FPM);提供PHP程序的解释器;提供mairadb数据库的连接函数的基本环境。
这是一个相当成熟的架构方案,无论是性能还是成本或是质量都是企业搭建网站的首选平台;

如果直接LAMP架构这就给系统内存提供了极大的挑战,这是我们可以建立分离式架构方案;

分离之后的通信过程:
分离式LAMP架构_第1张图片
构建分离式LAMP架构:
构建环境:
http服务器:172.16.75.2 所需软件安装:yum install httpd -y
Mysql服务器:172.16.75.3 所需软件安装:yum install mariadb-server
Php服务器:172.16.75.4 所软件安装:yum install php php-mysql

http服务器配置:
vim /etc/httpd/conf.d/vhost1.conf
分离式LAMP架构_第2张图片
systemctl start httpd
httpd -tttpd -t
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::8268:e185:d13d:2712. Set the 'ServerName' directive globally to suppress this message
Syntax OK
setenforce 0
iptables -F
然后要在本地服务器上的host文件中保存虚拟主机地址:
172.16.75.2 www.wzc1.com
172.16.75.2 www.wzc2.com
测试虚拟主机是否能用
Mkdir /var/www/html/{www1,www2}
Vim /var/www/html/www1/index.html
www1.wzc.com
Vim /var/www/html/www2/index.html
www2.wzc.com

访问www.wzc1.com和www.wzc2.com成功即可;

Php服务器设置:

vim /etc/php-fpm.d/www.conf
分离式LAMP架构_第3张图片
cd /var/lib/php
chmod -R 755 session
systemctl start php-fpm
分离式LAMP架构_第4张图片
172.16.75.4:9000已经被监听
在php服务器上建立与http服务器上网页DocumentRoot路径,并且编写php测试也,看看是否能够与http连接
Mkdir /var/www/html/{www1,www2}
Vim /var/www/html/www2/index.php
This is wzc2

phpinfo();

?>
进行测试:
分离式LAMP架构_第5张图片
成功;

Mysql服务器:
[root@mysql html]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database wpsdb;
Query OK, 1 row affected (0.11 sec)

MariaDB [(none)]> grant all on wpsdb.* TO 'wpuser'@'172.16.%.%'IDENTIFIED BY'123456';
Query OK, 0 rows affected (0.16 sec)

MariaDB [(none)]> create database pma;
Query OK, 1 row affected (0.01 sec)

MariaDB [(none)]> grant all on pma.* TO 'pmauser'@'172.16.%.%'IDENTIFIED BY'123456';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> \q
Bye
Mysql服务器配置完成;

在php服务器中建立页面进行测试:
vim /var/www/html/www1/index.php
This is wzc1.

    $conn = mysql_connect('172.16.75.3','wpuser','123456');

        if ($conn)

              echo "OK";

        else

              echo "NO";

phpinfo();

?>

vim /var/www/html/www2/index.php
This is wzc2.

    $conn = mysql_connect('172.16.75.3','wpuser','123456');

        if ($conn)

              echo "OK";

        else

              echo "NO";

phpinfo();

?>
访问测试:
分离式LAMP架构_第6张图片
分离式LAMP架构_第7张图片
显示OK,也就是php服务器与mysql服务器也连接成功,这时我们的分离式LAMP架构就构建完成了;

注意:三台服务器都要关闭SELinux:setenforce 0 不然连接不会成功;

接下来我们在构建好分离式LAMP架构中部署wordpress和phpadmin:
首先要将安装包上传到php服务器当中,解压然后移动到相应的目录当中:
[root@php ~]# tar -xf phpMyAdmin-3.5.4-all-languages.tar.gz
[root@php ~]# mv phpMyAdmin-3.5.4-all-languages /var/www/html/www2/
[root@php ~]# tar -xf wordpress-4.2-zh_CN.tar.gz
[root@php ~]# mv wordpress /var/www/html/www1
部署wordpress
[root@php ~]# cd /var/www/html/www1
[root@php www1]# cd wordpress/
[root@php wordpress]# mv wp-config-sample.php wp-config.php
[root@php wordpress]# vim wp-config.php
分离式LAMP架构_第8张图片
[root@php wordpress]# cd ..
这里我们要把WordPress这个目录个传到http服务器主页访问的路径下:
[root@php www1]# scp -r wordpress/ [email protected]:/var/www/html/www1/
这里是需要输yes 和另一台主机root密码的输入即可传输
访问测试:
分离式LAMP架构_第9张图片
成功;

部署phpadmin:
[root@php ~]# cd /var/www/html/www2
[root@php www2]# ls
index.php phpMyAdmin-3.5.4-all-languages
[root@php www2]# mv phpMyAdmin-3.5.4-all-languages/ phpmyadmin
[root@php www2]# ls
index.php phpmyadmin
[root@php www2]# vim phpmyadmin/libraries/config.default.php
$cfg['blowfish_secret'] = 'T40Vdxxx0rPrx8k2KYE';
$cfg['Servers'][$i]['host'] = '172.16.75.3';
$cfg['Servers'][$i]['user'] = 'pmauser';
$cfg['Servers'][$i]['password'] = '123456';
访问测试:
分离式LAMP架构_第10张图片
分离式LAMP架构_第11张图片
成功;
接下来我们进行压力测试:
[root@localhost ~]# ab -c 1000 -n 10000 http://www.wzc1.com/wordpress
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.wzc1.com (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests

Server Software:
Server Hostname: www.wzc1.com
Server Port: 80

Document Path: /wordpress
Document Length: 348 bytes

Concurrency Level: 1000
Time taken for tests: 50.764 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Non-2xx responses: 10000
Total transferred: 4980000 bytes
HTML transferred: 3480000 bytes
Requests per second: 196.99 [#/sec] (mean)
Time per request: 5076.371 [ms] (mean)
Time per request: 5.076 [ms] (mean, across all concurrent requests)
Transfer rate: 95.80 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 51 907 3149.9 61 31209
Processing: 51 68 17.1 58 158
Waiting: 51 64 13.3 57 155
Total: 102 975 3147.1 148 31267

Percentage of the requests served within a certain time (ms)
50% 148
66% 168
75% 184
80% 192
90% 1116
95% 3125
98% 15149
99% 15168
100% 31267 (longest request)

接下来我们在php服务器中安装php-xcache:
[root@php ~]# yum install php-xcache -y
[root@php ~]# systemctl restart php-fpm
[root@php ~]# vim /etc/php.d/xcache.ini
xcache.size = 300M
再次测试:
[root@localhost ~]# ab -c 1000 -n 10000 http://www.wzc1.com/wordpress
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.wzc1.com (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests

Server Software:
Server Hostname: www.wzc1.com
Server Port: 80

Document Path: /wordpress
Document Length: 348 bytes

Concurrency Level: 1000
Time taken for tests: 60.032 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Non-2xx responses: 10000
Total transferred: 4980000 bytes
HTML transferred: 3480000 bytes
Requests per second: 366.58 [#/sec] (mean)
Time per request: 6003.162 [ms] (mean)
Time per request: 6.003 [ms] (mean, across all concurrent requests)
Transfer rate: 81.01 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 50 874 2902.1 79 31192
Processing: 51 132 206.6 79 2092
Waiting: 0 131 206.1 79 2092
Total: 100 1007 2893.6 162 31274

Percentage of the requests served within a certain time (ms)
50% 162
66% 295
75% 766
80% 1107
90% 1520
95% 3206
98% 7181
99% 15187
100% 31274 (longest request)

在启用xcache后Requests per second比之前增加,所以性能更好;