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
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之间是否正常
客户端测试httpd是否连接php-fpm:
http://www1.b.com
9、配置mariadb
a.创建授权用户
[root@station188 ~]#mysql -uroot -p
b.Php和mysql的链接测试
[root@station222 ~]# vim /data/vhost1/www1/index.php
客户端测试php是否连接mysql:
http://www1.b.com
10、部署WordPress:
define('DB_HOST', '172.16.251.188');
[root@station222 www1]#scp -r wordpress/ [email protected]:/data/vhost1/www1/
11、部署phpmyadmin:
$cfg['Servers'][$i]['password'] = 'pma123';
[root@station222 www2]# scp -r phpmyadmin/ [email protected]:/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