此次实验准备3台CentOS7服务器,版本号:CentOS Linux release 7.2.1511。

搭建Apache服务器

  • 通过 yum -y install httpd 安装Apache:

  • 访问正常:

  • 修改配置文件,添加2个虚拟主机,一个提供phpMyAdmin,一个提供wordpress:
[root@happiness ~]# vim /etc/httpd/conf/httpd.conf
#启用解析,加速httpd服务的启动
ServerName localhost:80
#注销默认主目录
#DocumentRoot "/var/www/html" [root@happiness ~]# vim /etc/httpd/conf.d/vhost.conf
#默认主页
DirectoryIndex index.php
#虚拟主机a,后期提供phpMyAdmin
<VirtualHost 192.168.4.119:80>
ServerName www.aaa.net
DocumentRoot /var/www/aaa
ProxyRequests off
ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.4.118:9000/var/www/php_aaa/$1
<Directory "/var/www/aaa">
Options None
Allowoverride None
Require all granted
</Directory>
</VirtualHost>
#虚拟主机b,后期提供wordpress
<VirtualHost 192.168.4.119:80>
ServerName www.bbb.net
DocumentRoot /var/www/bbb
ProxyRequests off
ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.4.118:9000/var/www/php_bbb/$1
<Directory "/var/www/bbb">
Options None
Allowoverride None
Require all granted
</Directory>
</VirtualHost>
  • 测试2个虚拟主机静态资源是否可用:
#在虚拟主机a中新建测试页aaa.html
[root@happiness ~]# vim /var/www/aaa/aaa.html
<h1>test virtualhost aaa</h1>
#在虚拟主机b中新建测试页bbb.html
[root@happiness ~]# vim /var/www/bbb/bbb.html
<h1>test virtualhost bbb</h1> 访问结果:(实验中没搭建dns服务,修改要访问Apache的主机的hosts文件,添加 192.168.4.119  www.aaa.net 和 192.168.4.119  www.bbb.net,来完成访问)

   

搭建php服务器

  • 通过 yum -y install php-fpm php-mysql php-mbstring 搭建php:

  • 修改php配置文件:
[root@happiness ~]# vim /etc/php-fpm.d/www.conf
#监听本地能与外部通信的地址
listen = 192.168.4.118:9000
#允许哪些主机访问
listen.allowed_clients = 192.168.4.119
#确保user、group跟Apache服务器httpd进程的user、group一致
user = apache
group = apache
#session目录不存在,需要手动创建
php_value[session.save_path] = /var/lib/php/session
[root@happiness ~]# mkdir /var/lib/php/session
[root@happiness ~]# chown apache:apache /var/lib/php/session
[root@happiness ~]# ll -hd /var/lib/php/session/
drwxr-xr-x. 2 apache apache 4.0K Jun 21 10:28 /var/lib/php/session/
#虚拟机a新建php测试页
[root@happiness ~]# cat /var/www/php_aaa/index.php
<h1>a</h1>
<?php
phpinfo();
?>
#虚拟机b新建php测试页
[root@happiness ~]# cat /var/www/php_bbb/testbbb.php
<h1>b</h1>
<?php
phpinfo();
?> 访问结果:(注意,如果访问结果出现:File not found类似的提示时,需要关闭php服务器的selinux,临时关闭通过命令 setenforce Permissive 进行,永久关闭修改配置文件 vim /etc/sysconfig/selinux)

  

搭建Mariadb服务器

  • 通过 yum -y install mariadb-server 安装mariadb:

  • 创建mariadb用户访问权限:
MariaDB [(none)]> CREATE USER 'wpuser'@'192.168.4.118' IDENTIFIED BY 'wppasswd';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON wordpressdb.* TO 'wpuser'@'192.168.4.118';
MariaDB [(none)]> CREATE USER 'pmauser'@'192.168.4.118' IDENTIFIED BY 'pmapasswd';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON pmadb.* TO 'pmauser'@'192.168.4.118';
MariaDB [(none)]> FULSH PRIVILEGES;
MariaDB [(none)]> CREATE DATABASE wordpressdb DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
MariaDB [(none)]> CREATE DATABASE pmadb DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
  • 分别在虚拟机a和b中建立测试页,看能否成功连接mariadb服务器:
[root@happiness ~]# cat /var/www/php_aaa/mysql_conn.php
<h1>aaa</h1>
<?php
$conn = mysql_connect('192.168.4.117','pmauser','pmapasswd');
if($conn)
echo "aaa connects successfully";
else
echo "aaa fails to connect.";
?>
[root@happiness ~]# cat /var/www/php_bbb/mysql_conn.php
<h1>bbb</h1>
<?php
$conn = mysql_connect('192.168.4.117','wpuser','wppasswd');
if($conn)
echo "bbb connects successfully.";
else
echo "bbb fails to connect.";
?> 访问结果:

搭建phpMyAdmin和WordPress

  • 分别从官网下载 phpMyAdmin 和 WordPress 源码包,分别解压于对应的虚拟机主目录下:(此时最新的 phpMyAdmin-4.8.1版本仅支持 PHP 5.5 to 7.2 and MySQL 5.5,而实验中PHP版本为5.4,故下载了 phpMyAdmin-4.4.15.10版本)

  • 搭建phpMyAdmin:
#修改phpMyAdmin配置文件
[root@happiness ~]# vim /var/www/php_aaa/phpmyadmin/libraries/config.default.php
#可通过 openssl rand -base64 32 随机字符串
  $cfg['blowfish_secret'] = 'w14hLCZeyOtg4+9izK9O3oW8BLjTpJVAzF1GCAtJ7U4=';
  $cfg['Servers'][$i]['host'] = '192.168.4.117';
  $cfg['Servers'][$i]['user'] = 'pmauser';
  $cfg['Servers'][$i]['password'] = 'pmapasswd'; #修改完配置后复制一整份 phpmyadmin文件到Apache服务器
[root@happiness ~]# scp -r /var/www/php_aaa/phpmyadmin/ root@192.168.4.119:/var/www/aaa/ 访问结果:
  • 搭建WordPress:
#修改WordPress配置文件
[root@happiness ~]# cp /var/www/php_bbb/wordpress/wp-config-sample.php /var/www/php_bbb/wordpress/wp-config.php
[root@happiness ~]# vim /var/www/php_bbb/wordpress/wp-config.php
  define('DB_NAME', 'wordpressdb');
  define('DB_USER', 'wpuser');
  define('DB_PASSWORD', 'wppasswd');
  define('DB_HOST', '192.168.4.117'); #修改完配置后复制一整份wordpress到Apache服务器:
[root@happiness ~]# scp -r /var/www/php_bbb/wordpress root@192.168.4.119:/var/www/bbb/ 访问结果:

借助php-xcache加速访问

  • 没安装php-xcache进行的压力测试:
[root@happiness ~]# ab -n 10000 -c 1000 http://www.bbb.net/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.bbb.net (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: Apache/2.4.6
Server Hostname: www.bbb.net
Server Port: 80 Document Path: /wordpress
Document Length: 237 bytes Concurrency Level: 1000
Time taken for tests: 12.966 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Non-2xx responses: 10000
Total transferred: 4650000 bytes
HTML transferred: 2370000 bytes
Requests per second: 771.26 [#/sec] (mean)
Time per request: 1296.588 [ms] (mean)
Time per request: 1.297 [ms] (mean, across all concurrent requests)
Transfer rate: 350.23 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 47 206.0 0 1004
Processing: 5 136 1056.6 14 12899
Waiting: 1 136 1056.6 14 12899
Total: 10 183 1085.0 15 12947 Percentage of the requests served within a certain time (ms)
50% 15
66% 15
75% 16
80% 17
90% 25
95% 1208
98% 1676
99% 1679
100% 12947 (longest request)
  • 在php服务器上通过 yum -y install php-cache 安装cache:

  • systemctl reload php-fpm.service,并进行压力测试,可以看到访问速度有了很大提升:
[root@happiness ~]# ab -n 10000 -c 1000 http://www.bbb.net/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.bbb.net (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: Apache/2.4.6
Server Hostname: www.bbb.net
Server Port: 80 Document Path: /wordpress
Document Length: 237 bytes Concurrency Level: 1000
Time taken for tests: 1.973 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Non-2xx responses: 10000
Total transferred: 4650000 bytes
HTML transferred: 2370000 bytes
Requests per second: 5068.89 [#/sec] (mean)
Time per request: 197.282 [ms] (mean)
Time per request: 0.197 [ms] (mean, across all concurrent requests)
Transfer rate: 2301.79 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 56 220.6 4 1011
Processing: 5 39 90.4 13 1102
Waiting: 1 36 90.5 10 1101
Total: 10 95 245.2 16 1222 Percentage of the requests served within a certain time (ms)
50% 16
66% 17
75% 19
80% 20
90% 220
95% 1019
98% 1029
99% 1213
100% 1222 (longest request)
  • 修改xcache配置文件,修改缓存大小为100M,再进行压力测试,可以看到访问速度略有提高:
[root@happiness ~]# vim /etc/php.d/xcache.ini
xcache.size = 100M [root@happiness ~]# ab -n 10000 -c 1000 http://www.bbb.net/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.bbb.net (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: Apache/2.4.6
Server Hostname: www.bbb.net
Server Port: 80 Document Path: /wordpress
Document Length: 237 bytes Concurrency Level: 1000
Time taken for tests: 1.642 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Non-2xx responses: 10000
Total transferred: 4650000 bytes
HTML transferred: 2370000 bytes
Requests per second: 6088.82 [#/sec] (mean)
Time per request: 164.235 [ms] (mean)
Time per request: 0.164 [ms] (mean, across all concurrent requests)
Transfer rate: 2764.94 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 57 226.4 3 1011
Processing: 6 49 171.5 11 1613
Waiting: 1 47 171.7 8 1612
Total: 8 106 310.0 14 1636 Percentage of the requests served within a certain time (ms)
50% 14
66% 16
75% 22
80% 23
90% 219
95% 1028
98% 1409
99% 1418
100% 1636 (longest request)

CentOS7部署LAMP+xcache (php-fpm模式)的更多相关文章

  1. Centos7部署LAMP平台之架构之路

    部署LAMP平台搭建 一.源码安装LAMP 1. 安装apache [root@localhost ~]# yum -y install gcc* apr-devel apr-util-devel p ...

  2. FastCGI模式编译安装LAMP+Xcache

    PHP的工作模式:php在lamp环境下共有三种工作模式:CGI模式.apache模块.FastCGI模式.CGI模式下运行PHP,性能不是很好.(已淘汰)FastCGI的方式和apache模块的不同 ...

  3. CentOS6编译LAMP基于FPM模式的应用wordpress

    CentOS6编译LAMP基于FPM模式的应用wordpress 引言:其实我们可以直接使用yum安装LAMP(Linux+Apache[httpd]+Mysql+PHP),比手动编译安装LAMP要简 ...

  4. 阿里云服务器 ECS 部署lamp:centos+apache+mysql+php安装配置方法 (centos7)

    阿里云服务器 ECS 部署lamp:centos+apache+mysql+php安装配置方法 (centos7) 1.效果图 1 2. 部署步骤 1 1. mysql安装附加(centos7) 7 ...

  5. 部署LAMP+NFS实现双Web服务器负载均衡

    一.需求分析 1.前端需支持更大的访问量,单台Web服务器已无法满足需求了,则需扩容Web服务器: 2.虽然动态内容可交由后端的PHP服务器执行,但静态页面还需要Web服务器自己解析,那是否意味着多台 ...

  6. 部署lamp服务器

    系统:CentOS 6.5 64位 1.卸载旧版本软件 rpm -qa | grep mysql #查询是否已经安装MySQL,如有执行下面的操作将其全部删除 rpm -e mysql --nodep ...

  7. CentOS6系统编译部署LAMP(Linux, Apache, MySQL, PHP)环境

    我们一般常规的在Linux服务器中配置WEB系统会用到哪种WEB引擎呢?Apache还是比较常用的引擎之一.所以,我们在服务器中配置LAMP(Linux, Apache, MySQL, PHP)是我们 ...

  8. rhel6+apache2.4+mysql5.7+php5.6部署LAMP架构

    rhel6+apache2.4+mysql5.7+php5.6部署LAMP架构 2017年10月01日 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~准备阶段~~~~~~~~~~~~~ ...

  9. centos7 部署 docker ce

    =============================================== 2019/4/9_第1次修改                       ccb_warlock === ...

随机推荐

  1. Bootsrap Table表格分页

    一 bootsrap简介 Bootstrap,来自 Twitter,是目前很受欢迎的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加 ...

  2. 利用DOS命令做伪装成图片的压缩包,看上去是图片其实是个压缩包用2条命令即搞定

    在很多地方我们看到一张图片,然后把这张图片下载到本地,改后缀名为xx.rar,即变成了压缩包. 比如下面这个图片:(把以下图片保存到本地,后缀名xx.png 改为 xx.rar,解压试试) 怎么样,是 ...

  3. [Java][Servlet] Failed to destroy end point associated with ProtocolHandler ["http-nio-8080"]

    Background: Servlet version 3.1(3.0之后就有了@WebServlet注解) Error 严重: Failed to destroy end point associa ...

  4. Eureka与ZooKeeper 的比较

    Eureka的优势 1.在Eureka平台中,如果某台服务器宕机,Eureka不会有类似于ZooKeeper的选举leader的过程:客户端请求会自动切换到新的Eureka节点:当宕机的服务器重新恢复 ...

  5. 设置 text-align: center;line-height:height 居中无效

    1.设置文字水平居中 内联元素(行内元素)使用: text-align: center: 使用后文字仍然没有居中 解决方法:设置width:100%: 块元素使用: margin: 0 auto; 2 ...

  6. 轻松完成excel读写操作- 基于POI的框架BingExcel的使用(2)

    在进行 类转换时候,系统默认注册了一些转换器,当然你也可以自定局部或者全局的转换器.下面进行具体使用说明  java类说明 对应的java实体类,其属性必须要有__@CellConfig__注解,此注 ...

  7. Android Studio快捷键【Android学习入门】

    Studio快捷键[Android学习入门]" title="Android Studio快捷键[Android学习入门]"> 提示 Ctrl+P方法参数提示 Ct ...

  8. 【起航计划 023】2015 起航计划 Android APIDemo的魔鬼步伐 22 App->Menu->Inflate from XML 使用xml资源展示菜单

    本例MenuInflateFromXml.java演示了如何从Menu 资源(XML 定义)展开菜单项.这个例子的onCreate 采用了使用代码来创建Activity 界面的方法 而通常的方法是采用 ...

  9. ArcGIS for Service中JavaScript预览在内网环境无法使用

    1.问题说明 在使用ArcGIS for Service时经常会遇到一个问题,那就是我们需要对已经发布的服务进行预览,预览时点击对应服务,选择View in中的ArcGIS JavaScript就可在 ...

  10. EF--Model First

    Model First先设计Model对象,再由对象生成数据库. 1.新建控制台项目,名称ModelFirst,确定. 2.点击选中项目,右键-->添加-->新建项目--选择数据模板--& ...