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)
新手上路有不對的地方請多多指正,謝謝!