1、實驗環境:
Linux服務器操作系統版本:CentOS 7.2
http IP: 172.16.251.138
httpd-2.4.6.tar apr-util-1.5.2.tar
wordpress-4.3.1-zh_CN apr-1.5.0.tar
phpMyAdmin-4.4.14.1-all-languages
php-fpm IP:172.16.251.222
xcache-3.1.0.tar php-5.4.26.tar
mariadb IP:172.16.251.188
mariadb-5.5.46-linux-x86_64.tar (二進制包)
客戶端 IP:172.16.251.164
2、實驗準備:
[root@station138 ~]# iptables –F //關閉防火牆
[root@station138 ~]#setenforce0 //關閉SeLinux
[root@station138 ~]# rpm –e httpd mod_ssl mod_perlsystem-config-httpd php php-cli php-ldap php-common php-mairadb mariadb-server //卸載相關軟件,防止衝突
3、安裝開發包組,安裝支持軟件解決依賴關係:
[root@station138 ~]#yum -y groupinstall "Development
Tools" "Server Platform Development"
[root@station138 ~]#tar xf apr-1.5.0.tar.bz2
[root@station138 apr-1.5.0]# ./configure --prefix=/usr/local/apr
[root@station138 apr-1.5.0]# make && make install
[root@station138 ~]#tar xf apr-util-1.5.2.tar.bz2
[root@station138 apr-util-1.5.2]#./configure --prefix=/usr/local/apr-util \
> --with-apr=/usr/local/apr
[root@station138 apr-util-1.5.2]#make && make install
[root@station138 ~]# yum -y install pcre-devel openssl-devel libevent-devel
4、源代碼安裝Apache:
a.編譯httpd
> --enable-rewrite //支持URL重寫
[root@station138 httpd-2.4.6]# make && make install
b.添加PATH環境變量:
[root@station138 ~]# vim /etc/profile.d/httpd24.sh
export PATH=/usr/local/apache/bin:$PATH
[root@station138 ~]# source /etc/profile.d/httpd24.sh
c.啓動服務:
[root@station138 ~]# ln -sv /usr/local/apache/include/ /usr/include/httpd24
[root@station138 ~]# ss -tnl
5、二進制安裝mariadb:
a.建立mysql用戶和組
[root@station188 ~]# useradd -r -M mysql
b.建立數據存放的目錄
[root@station188 ~]# mkdir -p /data/mydata
[root@station188 ~]# chown -R mysql:mysql /data/mydata/
c.解壓mariadb安裝包
[root@station188 ~]# ln -sv /usr/local/mariadb-5.5.46-linux-x86_64/ mysql
[root@station188 ~]# chown -R root.mysql /usr/local/mysql/*
c.使用scripts腳本文件mysql_install_db文件來安裝數據庫
[root@station188 mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mydata
d.提供配置文件
[root@station188 mysql]# cp support-files/my-large.cnf /etc/my.cnf
[root@station188 mysql]# vim /etc/my.cnf
datadir=/data/mydata //指明mysql的數據存放路徑
innodb_file_per_table = ON //成爲獨立表空間
skip_name_resolve = ON //跳過名稱解析
e.提供mysql服務啓動腳本
f.添加環境變量
[root@station188 ~]# source /etc/profile.d/mysql.sh
g.導出頭文件
[root@station188 ~]# ln -s /usr/local/include/ /usr/include/mysql
h.導出庫文件:
[root@station188 ~]# vim /etc/ld.so.conf.d/mysql.conf
i.啓動服務
[root@station188 ~]# ss -tnl
LISTEN 0 50 *:3306 *:*
6、源代碼安裝PHP
a.安裝開發包組及依賴關係的包
[root@station222 ~]# yum -y groupinstall "Development Tools" "Server Platform Development"
[root@station222 ~]# yum -y install bzip2-devel libmcrypt-devel libxml2-devel openssl-devel
b.編譯php
[root@station222 php-5.4.26]# ./configure\
--prefix=/usr/local/php --with-openssl --with-mysql=mysqlnd
--with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2
[root@station222 php-5.4.26]# make && make install
c.php提供配置文件
[root@station222 php-5.4.26]# cp php.ini-production /etc/php.ini
d.提供php-fpm腳本
[root@station222 php-5.4.26]# chkconfig --add php-fpm
e.提供php-fpm配置文件
[root@station222 php-5.4.26]# cp etc/php-fpm.conf.default etc/php-fpm.conf
f.啓動服務
LISTEN 0 128 127.0.0.1:9000 *:*
7、httpd配置
a.支持fastFCGI的模塊
[root@station138 ~]# vim /etc/httpd24/httpd.conf
Include /etc/httpd24/extra/httpd-vhosts.conf
AddType application/x-httpd-php-source .phps
b.配置虛擬主機
ProxyRequests off
Directoryindex index.php
ProxyRequests off
Directoryindex index.php
</VirtualHost>
c.測試重啓服務
[root@station138 ~]# mkdir -p /data/vhost1/www1
[root@station138 ~]# mkdir -p /data/vhost2/www2
[root@station138 ~]# apachectl -t
[root@station138 ~]# apachectl restart
8、配置php-fpm
[root@station222 ~]# vim /usr/local/php/etc/php-fpm.conf
listen = 172.16.251.222:9000
LISTEN 0 128 172.16.251.222:9000 *:*
測試php和http之間是否正常
<?php
客戶端測試httpd是否連接php-fpm:
9、配置mariadb
a.創建授權用戶
[root@station188 ~]#mysql -uroot -p
b.Php和mysql的鏈接測試
[root@station222 ~]# vim /data/vhost1/www1/index.php
客戶端測試php是否連接mysql:
10、部署WordPress:
define('DB_HOST', '172.16.251.188');
[root@station222 www1]#scp -r wordpress/ root@172.16.251.138:/data/vhost1/www1/
11、部署phpmyadmin:
$cfg['Servers'][$i]['password'] = 'pma123';
[root@station222 www2]# scp -r phpmyadmin/ root@172.16.251.138:/data/vhost2/www2/
12.壓力測試
a.測試wordpress
[root@station222 ~]# ab -c 100 -n 1000 http://www1.b.com/wordpress
Concurrency Level: 100
Time taken for tests: 3.347 seconds
Completerequests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 174000 bytes
HTML transferred: 2000 bytes
Requests per second: 298.75 [#/sec] (mean)
Time per request: 334.730 [ms] (mean)
Time per request: 3.347 [ms] (mean, across all concurrentrequests)
Transfer rate: 50.76 [Kbytes/sec] received
b.編譯安裝xcache緩存加速
[root@station222 xcache-3.2.0]# ./configure \
> --enable-xcache --with-php-config=/usr/local/php/bin/php-config
c.安裝xcache後再測試
[root@station222 ~]# ab -c 100 -n 1000 http://www1.b.com/wordpress