Apache之FCGI模式部署LAMP

FCGI模式编译安装 LAMP+xcache


php 的工作模式:

php 在 lamp 环境下共有三种工作模式:CGI 模式、apache 模块、FastCGI 模式。CGI 模式下 运行 PHP,性能不是很好。作为 apache 的模块方式运行,在以前编译安装 lamp 已 经介绍过了。FastCGI 的方式和 apache 模块的不同点在于:FastCGI 方式 PHP 是一处独立的 进程,所有 PHP 子进程都由 PHP 的一个叫作 php-fpm 的组件负责管理;而 apache 模块化方 式运行的 PHP,则是 apache 负责调用 PHP 完成工作。PHP 的 FastCGI 方式性能要比 apache 模块化方式强很多,今天我们以 FastCGI 方式编译安装 lamp

FastCGI 工作机制:

首先客户端发起请求,请求分为 2 种,一种是静态请求它可以直接由 Apache 直接响应返回; 另一种是动态的请求,如其中包含中 php 或者 Perl 这种脚本解释性语言,则由 Apache 服务 器通过 fastcgi 协议调用 php 服务器执行并返回给Apache由 Apache返回解释执行后的结果, 如果这个过程中涉及到对数据的操作,此时 php 服务器还会还会通过 mysql 协议调用 mysql 服务器

编译环境及各软件版本:

LinuxWeb服务器PHPMysql数据库xcache
Centos7.5Httpd-2.4.23php-5.6.27Mysql5.7xcache-3.1.0

本文用到的软件连接

提取码:vzsu

主机规划

至少 3 台主机,操作系统都是 centos7.5.网段在 192.168.1.0/24 网关 192.168.1.250

分配如下:

1台httpd服务器(192.168.1.70)

1台php服务器(192.168.1.50)

1台mysql服务器(192.168.1.40)

一、编译安装 LAMP

编译安装 apache(请参考前面 apache 的安装

MySQL直接使用脚本意一键安装

FastCGI 方式安装 php
1、解决依赖关系
[root@phpserver ~]# yum -y install libxml2-devel lzip2-devel libcurl-devel libmcrypt-devel openssl-devel bzip2-devel

安装libmcrypt

[root@phpserver ~]# tar zxf libmcrypt-2.5.7.tar.gz 
[root@phpserver ~]# cd libmcrypt-2.5.7/
[root@phpserver libmcrypt-2.5.7]# ./configure --prefix=/usr/local/libmcrypt && make && make install
2、编译安装php
[root@phpserver ~]# tar zxf php-5.6.27.tar.gz
[root@phpserver ~]# cd  php-5.6.27/
[root@phpserver php-5.6.27]# ./configure --prefix=/usr/local/php5.6 --with-mysql=mysqlnd \
>  --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-fpm \
>  --enable-sockets --enable-sysvshm --enable-mbstring --with-freetype-dir --with-jpeg-dir \
>  --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-mhash \
>  --with-mcrypt=/usr/local/libmcrypt --with-config-file-path=/etc \
>  --with-config-file-scan-dir=/etc/php.d --with-bz2--enable-maintainer-zts
[root@phpserver php-5.6.27]# make && make install

相关选项解释:

--prefix=/usr/local/php5.6:安装位置

--with-mysql=mysqlnd:支持 mysql

--with-pdo-mysql=mysqlnd:支持 pdo 模块

--with-mysqli=mysqlnd:支持 mysqli 模块

注:上面的三选项的作用:数据库与 php 不在一个服务器上,指定此种方式,安装数据库 连接驱动

--with-openssl:支持 openssl 模块

--enable-fpm:支持 fpm 模式

--enable-sockets:启用 socket 支持

--enable-sysvshm:启用系统共享内存支持

--enable-mbstring:多字节字串、像我们的中文就是多字节字串

--with-freetype-dir:支持 freetype、就要装 freetype-devel、跟字体相关的、字体解析工具

--with-jpeg-dir

--with-png-dir

注:上面的二选项的作用:处理 jpeg、png 图片的、php 可以动态生成 jpeg 图片

--with-zlib:是个压缩库、在互联网传输时用来压缩传输的

--with-libxml-dir=/usr:这个 libxml 是用来解析 xml 的、指定/usr 下

--enable-xml:支持 xml 的

--with-mhash:支持 mhash

--with-mcrypt=/usr/local/libmcrypt:libmcrypt-devel 这个程序包所指定的

--with-config-file-path=/etc:指定配置文件的存放路径的

--with-config-file-scan-dir=/etc/php.d:配置文件扫描路径

--with-bz2:支持 BZip2

为了支持 apache 的 worker 或 event 这两个 MPM,编译时使用了--enable-maintainer-zts 选项

如果使用 PHP5.3 以上版本,为了链接 MySQL 数据库,可以指定 mysqlnd,这样在本机就不 需要先安装 MySQL 或 MySQL 开发包了。mysqlnd 从 php 5.3 开始可用,可以编译时绑定到它 (而不用和具体的 MySQL 客户端库绑定形成依赖),但从 PHP 5.4 开始它就是默认设置了

3、提供php配置文件
[root@phpserver php-5.6.27]# cp php.ini-production /etc/php.ini
4、为php-fpm提供脚本
[root@phpserver php-5.6.27]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@phpserver php-5.6.27]# chmod +x /etc/init.d/php-fpm 
[root@phpserver php-5.6.27]# chkconfig --add php-fpm
[root@phpserver php-5.6.27]# chkconfig php-fpm on
5、提供php-fpm配置文件并编辑
[root@phpserver ~]# cp /usr/local/php5.6/etc/php-fpm.conf.default /usr/local/php5.6/etc/php-fpm.conf
[root@phpserver ~]# vim /usr/local/php5.6/etc/php-fpm.conf
修改内容如下:
pid = run/php-fpm.pid
listen = 192.168.1.50:9000
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35

启动php-fpm

[root@phpserver ~]# service php-fpm start
Starting php-fpm  done
[root@phpserver ~]# netstat -anpt | grep php-fpm
tcp        0      0 192.168.1.50:9000       0.0.0.0:*               LISTEN      114068/php-fpm: mas
[root@phpserver ~]# firewall-cmd --permanent --add-port=9000/tcp
success
[root@phpserver ~]# firewall-cmd --reload
Success

在该主机上新建虚拟主机目录用于存放网页文件

[root@phpserver ~]# mkdir -p /var/www/benet

至此 php 安装配置完毕,下面配置 apache 通过 fastcgi 协议调用 php

6、配置 apache(切换到 apache 主机上操作)

在 Apache2.4 以后已经专门有一个模块针对 FastCGI 的实现,此模块为 mod_proxy_fcgi.so, 它其实是作为 mod_proxy.so 模块的扩充,因此,这两个模块都要加载

[root@apache ~]# vim /usr/local/http-2.4.23/conf/httpd.conf
去掉一下注释
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
[root@apache ~]# apachectl restart
[root@apache ~]# apachectl -M | grep proxy
 proxy_module (shared)
 proxy_fcgi_module (shared)

建立一个目录作为虚拟主机的家目录

[root@apache ~]# mkdir -p /var/www/benet

编辑主配置文件 httpd.conf,开启虚拟主机

[root@apache ~]# vim /usr/local/http-2.4.23/conf/httpd.conf
启用 Include conf/extra/httpd-vhosts.conf
Include conf/extra/httpd-vhosts.conf # 去掉注释
同时定位 AddType;添加下面两行:让 apache 能识别 php 格式的页面
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
并且定位至 DirectoryIndex:支持 php 格式的主页
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>
添加 index.php(最好添加在最前面)

配置虚拟主机支持使用 fcgi

[root@apache ~]# vim /usr/local/http-2.4.23/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
 ServerAdmin webmaster@benet.com
 DocumentRoot "/var/www/benet"
 ServerName www.benet.com
 ServerAlias benet.com
 ErrorLog "logs/benet.com-error_log"
 CustomLog "logs/benet.com-access_log" common
 ProxyRequests Off
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://192.168.1.50:9000/var/www/benet/$1
 #<LocationMatch "^(.*\.php(/.*)?)$">
 # ProxyPass fcgi://192.168.1.50:9000/var/www/benet
 #</LocationMatch>
<Directory "/var/www/benet">
 Options FollowSymLinks
 AllowOverride None
 Require all granted
</Directory>
</VirtualHost>

其中:

ProxyRequests off:关闭正向代理

ProxyPassMatch:把以.php 结尾的文件请求发送到 php-fpm 进程,php-fpm 至少需要知道运 行的目录和 URI,所以这里直接在 fcgi://192.168.31.141:9000 后指明了这两个参数,其它的 参数的传递已经被 mod_proxy_fcgi.so 进行了封装,不需要手动指定

特别注意的是,目录需要与中的 DocumentRoot 后的路径一致

ProxyPassMatch

只有满足特定正则模式的内容才会匹配并执行此规则,这里的模式是,^/(.*\.php(/.*)?)$ 从网站(虚拟主机的根目录开始,匹配任何以 .php 结尾,或者在 .php 之后 紧跟一个 / 再跟别的内容的路径

^ (caret) 和 $ (dollar)标志要匹配的路径的开始和结束

( )括号里的内容可以用 $1 来表示,以方便后面引用它

fcgi:// 192.168.1.50:9000 通过 mod_proxy_fcgi 来转发的代理,使用 fastCGI 协议,转到 PHP-FPM 监听的端口

/path/to/your/documentroot/

非常重要!必须与虚拟主机的路径匹配,且必须是对应 php 文件在操作系统中的绝对路径。 否则会找不到文件

$1 可以从原始请求扩展成整个请求路径的变量,这里指代前面( ) 里面匹配的那个路径(uri)

补充:

Apache httpd 2.4 以前的版本中,要么把 PHP 作为 Apache 的模块运行,要么添加一个第 三方模块支持 PHP-FPM 实现
7、测试 LAMP 环境:

在 mysql 主机上创建用于 php 服务器连接的 mysql 账户

mysql> grant all on *.* to testuser@'%' identified by '123';
Query OK, 0 rows affected, 1 warning (0.00 sec)

注意防火墙要允许 mysql 连接

在 php 服务器上的/var/www/benet 目录下创建.php 的测试页:

[root@phpserver ~]# cat /var/www/benet/index.php 
<?php
phpinfo();
?>
[root@phpserver ~]# cat /var/www/benet/test1.php 
<?php
$link=mysql_connect('192.168.1.40','testuser','123');
if ($link)echo "connection success......";
mysql_close();
?>

测试访问php测试页


看到上面两个测试页说明 apache、php、mysql 之间可以协同工作了

二、压力测试

网站性能压力测试是服务器网站性能调优过程中必不可缺少的一环。只有让服务器处在高压 情况下,才能真正体现出软件、硬件等各种设置不当所暴露出的问题

性能测试工具目前最常见的有以下几种:ab、http_load、webbench、siege。今天我们专门 来介绍 ab

ab 是 apache 自带的压力测试工具。ab 非常实用,它不仅可以对 apache 服务器进行网站访 问压力测试,也可以对或其它类型的服务器进行压力测试。比如 nginx、tomcat、IIS 等

下面我们开始介绍有关 ab 命令的使用:

  1. ab 的原理
  2. ab 的安装
  3. ab 参数说明
  4. ab 性能指标
  5. ab 实际使用
  6. 测试 nginx 性能
1)ab的原理

ab 是 apachebench 命令的缩写

ab 的原理:

ab 命令会创建多个并发访问线程,模拟多个访问者同时对某一 URL 地址进行访 问。它的测试目标是基于 URL 的,因此,它既可以用来测试 apache 的负载压力,也可以测 试 nginx、lighthttp、tomcat、IIS 等其它 Web 服务器的压力

ab 命令对发出负载的计算机要求很低,它既不会占用很高 CPU,也不会占用很多内存。但 却会给目标服务器造成巨大的负载,其原理类似 CC 攻击。自己测试使用也需要注意,否则 一次上太多的负载。可能造成目标服务器资源耗完,严重时甚至导致死机

2)ab的安装

ab 的安装非常简单,如果是源码安装 apache 的话,那就更简单了。apache 安装完毕后 ab 命令存放在 apache 安装目录的 bin 目录下。如下:

/usr/local/http-2.4.23/bin/ab

如果 apache 是通过 yum 的 RPM 包方式安装的话,ab 命令默认存放在/usr/bin 目录下。如 下:

which ab

注意:如果不想安装 apache 但是又想使用 ab 命令的话,我们可以直接安装 apache 的工具 包 httpd-tools。如下:

yum -y install httpd-tools

查看 ab 是否安装成功,可以切换到上述目录下,使用 ab –V 命令进行检测。如下:

[root@apache ~]# /usr/local/http-2.4.23/bin/ab -V

如果ab -V命令出错,可以export LD_LIBRARY_PATH="/usr/local/openssl/lib/",就可以了

[root@apache ~]# export LD_LIBRARY_PATH="/usr/local/openssl/lib/"
[root@apache ~]# ab -V
This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
3)ab参数说明

有关 ab 命令的使用,我们可以通过帮助命令进行查看。如下:

[root@apache ~]# ab --help

下面我们对这些参数,进行相关说明。如下:

n:在测试会话中所执行的请求个数(即总请求数)

-c:一次产生的请求个数(即并发用户数)

[root@apache ~]# ab -c 500 -n 10000 http://192.168.1.70/index.html
This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.1.70 (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
Server Hostname:        192.168.1.70
Server Port:            80

Document Path:          /index.html 
Document Length:        208 bytes 

Concurrency Level:      500 
Time taken for tests:   25.787 seconds 
Complete requests:      10000 
Failed requests:        4 
   (Connect: 0, Receive: 0, Length: 4, Exceptions: 0)
Non-2xx responses:      10000
Total transferred:      3720000 bytes #
HTML transferred:       2080000 bytes 
Requests per second:    387.80 [#/sec] (mean) 
Time per request:       1289.329 [ms] (mean) 
Time per request:       2.579 [ms] (mean, across all concurrent requests) 
Transfer rate:          140.88 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1  31.7      0    3008
Processing:     2  302 1687.9      9   25773
Waiting:        2  294 1641.2      9   25773
Total:          6  303 1689.6      9   25781

Percentage of the requests served within a certain time (ms)
  50%      9
  66%     10
  75%     10
  80%     10
  90%     11
  95%    939
  98%   6460
  99%  12908
 100%  25781 (longest request)

Document Path: /index.html :

请求的资源

Document Length: 208 bytes :

响应数据的正文长度

Concurrency Level: 500 :

并发个数(并发用户数)

Time taken for tests: 25.787 seconds :

所有这些请求处理完成所花费的时间

Complete requests: 10000 :

完成请求数

Failed requests: 4 :

失败的请求数

Total transferred: 3720000 bytes :

表示所有请求的响应数据长度总和,包括每个 HTTP响应数据的头信息和正文数据的长度。注意这里不包括 HTTP 请求数据的长度,仅仅为 web服务器流向用户 PC 的应用层数据总长度

HTML transferred: 2080000 bytes :

表示所有请求的响应数据中正文数据的总和,也就是减去了 Total transferred 中 HTTP 响应数据中的头信息的长度

Requests per second: 387.80 [:/sec] (mean) :

吞吐量-每秒请求数

计算公式:Complete requests/Time taken for tests

Time per request: 1289.329 [ms] (mean) :

用户平均请求等待时间

计算公式:Timetoken for tests/(Complete requests/Concurrency Level)

Time per request: 2.579 [ms] (mean, across all concurrent requests) :

服务器平均请求等待时间

计算公式:Time taken for tests/Complete requests

Transfer rate: 140.88 [Kbytes/sec] received

表示这些请求在单位时间内从服务器获取的数据长度

计算公式:Total trnasferred/ Time taken for tests,这个统计很好的说明服务器的处理能力达到极限时,其出口宽带的需求量。(即平均每秒网络上的流量)

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1  31.7      0    3008
Processing:     2  302 1687.9      9   25773
Waiting:        2  294 1641.2      9   25773
Total:          6  303 1689.6      9   25781

Percentage of the requests served within a certain time (ms)
  50%      9
  66%     10
  75%     10
  80%     10
  90%     11
  95%    939
  98%   6460
  99%  12908
 100%  25781 (longest request)

这部分数据用于描述每个请求处理时间的分布情况,比如以上测试,80%的请求处理时间 都不超过 66ms,这个处理时间是指前面的 Time per request,即对于单个用户而言,平均 每个请求的处理时间

4)ab 性能指标

在进行性能测试过程中有几个指标比较重要:

1、吞吐率(Requests per second)

服务器并发处理能力的量化描述,单位是 reqs/s,指的是在某个并发用户数下单位时间内处 理的请求数。某个并发用户数下单位时间内能处理的最大请求数,称之为最大吞吐率。 记住:吞吐率是基于并发用户数的。这句话代表了两个含义:

a、吞吐率和并发用户数相关

b、不同的并发用户数下,吞吐率一般是不同的

计算公式:总请求数/处理完成这些请求数所花费的时间,即:

Request per second=Complete requests/Time taken for tests

必须要说明的是,这个数值表示当前机器的整体性能,值越大越好

2、并发连接数(The number of concurrent connections)

并发连接数指的是某个时刻服务器所接受的请求数目,简单的讲,就是一个会话

3、并发用户数(Concurrency Level)

要注意区分这个概念和并发连接数之间的区别,一个用户可能同时会产生多个会话,也即连 接数

4、用户平均请求等待时间(Time per request)

计算公式:处理完成所有请求数所花费的时间/(总请求数/并发用户数),即:

Time per request=Time taken for tests/(Complete requests/Concurrency Level)

5、服务器平均请求等待时间(Time per request:across all concurrent requests)

计算公式:处理完成所有请求数所花费的时间/总请求数,即:

Time taken for/testsComplete requests

可以看到,它是吞吐率的倒数。同时,它也等于用户平均请求等待时间/并发用户数,即:Time per request/Concurrency Level

三、php加速软件Xcache

(在 php 主机上完成下面的操作)

说明:

php 安装目录:/usr/local/php5.6

php.ini 配置文件路径:/etc/php.ini

php 网页根目录:/var/www/benet

1、安装xcache
[root@phpserver ~]# wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz
[root@phpserver ~]# tar zxf xcache-3.2.0.tar.gz 
[root@phpserver ~]# cd xcache-3.2.0/
# 用 phpize 生成 configure 配置文件
[root@phpserver xcache-3.2.0]# /usr/local/php5.6/bin/phpize
[root@phpserver xcache-3.2.0]# ./configure --enable-xcache --enable-xcache-coverager \
>  --enable-xcache-optimizer --with-php-config=/usr/local/php5.6/bin/php-config
[root@phpserver xcache-3.2.0]# make && make install

安装完成后最后出现的目录要记住,后面会用到

Installing shared extensions:     /usr/local/php5.6/lib/php/extensions/no-debug-non-zts-20131226/
2、创建 xcache 缓存文件
[root@phpserver xcache-3.2.0]# touch /tmp/xcache
[root@phpserver xcache-3.2.0]# chmod 777 /tmp/xcache
3、拷贝xcache 后台管理程序到网站根目录
[root@phpserver xcache-3.2.0]# cp -r htdocs/ /var/www/benet/xcache
4、配置php支持xcache
[root@phpserver ~]# vim /etc/php.ini
# 在最后添加以下内容
[xcache-common]
extension = /usr/local/php5.6/lib/php/extensions/no-debug-non-zts-20131226/xcache.so # 这个路径就是之前保存的路径
[xcache.admin]
xcache.admin.enable_auth = Off
[xcache]
xcache.shm_scheme ="mmap"
xcache.size=60M
xcache.count =1
xcache.slots =8K
xcache.ttl=0
xcache.gc_interval =0
xcache.var_size=64M
xcache.var_count =1
xcache.var_slots =8K
xcache.var_ttl=0
xcache.var_maxttl=0
xcache.var_gc_interval =300
xcache.test =Off
xcache.readonly_protection = Off
xcache.mmap_path ="/tmp/xcache"
xcache.coredump_directory =""
xcache.cacher =On
xcache.stat=On
xcache.optimizer =Off
[xcache.coverager]
xcache.coverager =On
xcache.coveragedump_directory =""

将 xcache 目录拷贝到 apache 主机的网页文档目录下

[root@phpserver ~]# scp -r /var/www/benet/xcache/ root@192.168.1.70:/var/www/benet/
5、测试

重启 php-fpm

[root@phpserver ~]# service php-fpm restart

浏览器打开网站根目录下面的 xcache

192.168.1.70/xcache可以看到如下页面:

至此,Linux 下安装 php 加速软件 Xcache 教程完成

执行 ab 压力测试:

执行第一次压力测试:

[root@apache ~]# ab -c 100 -n 1000 http://192.168.1.70/index.php
This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.1.70 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache
Server Hostname:        192.168.1.70
Server Port:            80

Document Path:          /index.php
Document Length:        84474 bytes

Concurrency Level:      100
Time taken for tests:   1.464 seconds
Complete requests:      1000
Failed requests:        85
   (Connect: 0, Receive: 0, Length: 85, Exceptions: 0)
Total transferred:      84719909 bytes
HTML transferred:       84473909 bytes
Requests per second:    683.19 [#/sec] (mean)
Time per request:       146.373 [ms] (mean)
Time per request:       1.464 [ms] (mean, across all concurrent requests)
Transfer rate:          56523.11 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.6      0       2
Processing:    23  139  21.1    143     192
Waiting:        9  135  20.9    138     157
Total:         25  140  20.6    143     192

Percentage of the requests served within a certain time (ms)
  50%    143
  66%    145
  75%    147
  80%    148
  90%    152
  95%    157
  98%    160
  99%    161
 100%    192 (longest request)

执行第二次压力测试

[root@apache ~]# ab -c 100 -n 1000 http://192.168.1.70/index.php
This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.1.70 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache
Server Hostname:        192.168.1.70
Server Port:            80

Document Path:          /index.php
Document Length:        84474 bytes

Concurrency Level:      100
Time taken for tests:   1.510 seconds
Complete requests:      1000
Failed requests:        101
   (Connect: 0, Receive: 0, Length: 101, Exceptions: 0)
Total transferred:      84719889 bytes
HTML transferred:       84473889 bytes
Requests per second:    662.27 [#/sec] (mean)
Time per request:       150.995 [ms] (mean)
Time per request:       1.510 [ms] (mean, across all concurrent requests)
Transfer rate:          54792.57 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       2
Processing:     8  144  24.0    150     184
Waiting:        4  137  23.6    143     155
Total:          9  144  23.7    150     184

Percentage of the requests served within a certain time (ms)
  50%    150
  66%    152
  75%    152
  80%    153
  90%    155
  95%    157
  98%    158
  99%    160
 100%    184 (longest request)

查看 xcache 的命中率:

四、部署bbs论坛
1、Discuz 的程序文件解压,并且将 upload 中所有文件放置到网站目录(php 服务器的操作)
[root@phpserver ~]# mkdir discus
[root@phpserver ~]# unzip Discuz_7.0.0_FULL_SC_UTF8.zip -d discus
[root@phpserver ~]# mv discus/Discuz_7.0.0_FULL_SC_UTF8/upload/ /var/www/benet/bbs
2、设置 php-fpm 的服务用户为下面文件的属主或者对其设置写权限,否则安装时会报错
[root@phpserver ~]# chmod -R 777 /var/www/benet/bbs/
3、修改 php.ini 文件
[root@phpserver ~]# vim  /etc/php.ini
short_open_tag = On # 将Off改为On,否则程序无法正常运行
4、重启 php-fpm
[root@phpserver ~]# service php-fpm restart
5、web 服务器也需要有静态文件
[root@phpserver ~]# scp -r /var/www/benet/bbs/ root@192.168.1.70:/var/www/benet/
6、在数据库服务器上创建 bbs 数据库及授权帐户
mysql> create database bbsdb;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on bbsdb.* to runbbs@'%' identified by 'pwd@123';
Query OK, 0 rows affected, 1 warning (0.00 sec)

置完成之后,输入 httd//192.168.1.70/bbs/install 即可安装

填写数据库的相关信息,添加数据库服务器的地址和 MariaDB 创建的数据库和用户密码,而 后在设置 bbs 的管理员帐号密码就可以继续安装了


出现上面这种情况是由于 php 服务器安装了 discuz 之后导致程序发生变化从而导致动态服 务器和静态服务器的程序不一致,只需要手动把 bbs 服务器的文件和 web 服务器进行一次 同步即可,如果想实现自动同步,需要使用其他服务,如 initory+rsync、sersync 等工具

[root@phpserver ~]# scp -r /var/www/benet/bbs/* root@192.168.1.70:/var/www/benet/bbs/

动态服务器和静态服务器同步文件之后,再次访问 bbs 的网址就正常了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值