什麼是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數據庫的鏈接函數的基本環境。
這是一個至關成熟的架構方案,不管是性能仍是成本或是質量都是企業搭建網站的首選平臺;php
若是直接LAMP架構這就給系統內存提供了極大的挑戰,這是咱們能夠創建分離式架構方案;html
分離以後的通訊過程:
構建分離式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 mysql
http服務器配置:
vim /etc/httpd/conf.d/vhost1.conf
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.comsql
訪問www.wzc1.com和www.wzc2.com成功便可;數據庫
Php服務器設置:apache
vim /etc/php-fpm.d/www.conf
cd /var/lib/php
chmod -R 755 session
systemctl start php-fpm
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編程
<?phpvim
phpinfo();服務器
?>
進行測試:
成功;網絡
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.
<?php
$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.
<?php
$conn = mysql_connect('172.16.75.3','wpuser','123456'); if ($conn) echo "OK"; else echo "NO";
phpinfo();
?>
訪問測試:
顯示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
[root@php wordpress]# cd ..
這裏咱們要把WordPress這個目錄個傳到http服務器主頁訪問的路徑下:
[root@php www1]# scp -r wordpress/ root@172.16.75.2:/var/www/html/www1/
這裏是須要輸yes 和另外一臺主機root密碼的輸入便可傳輸
訪問測試:
成功;
部署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';
訪問測試:
成功;
接下來咱們進行壓力測試:
[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比以前增長,因此性能更好;