部署LAMP动静分离

发布时间:2020-04-13 21:01:19 作者:wx5cc19525285e2
来源:网络 阅读:275

一、LAMP动静分离

Benchmarking 127.0.0.1 (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/2.4.23
Server Hostname:        127.0.0.1
Server Port:            80

Document Path:          /index.html                  # 请求的资源页面
Document Length:        9 bytes                      # HTTP 响应数据的正文长度

Concurrency Level:      500             # 并发个数
Time taken for tests:   0.807 seconds        # 所有这些请求处理完成所花费的时间
Complete requests:      1000            # 完成请求数
Failed requests:        0              # 失败的请求数
Total transferred:      251000 bytes
#表示所有请求的响应数据长度总和,包括每个HTTP响应数据的头信息和正文数据的长度
HTML transferred:       9000 bytes     # 网页文件的大小(去除响应头部的大小)
Requests per second:    1238.40 [#/sec] (mean)
#吞吐量,计算方式:请求的次数/用户等待时间(Complete requests/Time taken for tests)
Time per request:       403.748 [ms] (mean)
#用户平均等待一个页面的时间,计算方式:用户等待时间/完成请求的次数(Complete requests/Concurrency Level)
Time per request:       0.807 [ms] (mean, across all concurrent requests)
#服务器处理一个请求花费的时间,计算方式:用户等待时间/完成请求的次数(Time taken for tests/Complete requests)
Transfer rate:          303.55 [Kbytes/sec] received
#用户请求的数据大小,计算方式:数据的总长度/用户等待时间(Total trnasferred/ Time taken for tests)
#这个统计很好的说明服务器的处理能力达到极限时,其出口宽带的需求量。(即平均每秒网络上的流量)

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   1.6      1       5
Processing:     1   78 138.1      9     802
Waiting:        1   77 138.3      8     802
Total:          2   79 139.2     11     805

Percentage of the requests served within a certain time (ms)
  50%     11
  66%     16
  75%    206
  80%    208
  90%    209
  95%    405
  98%    406
  99%    805
 100%    805 (longest request)
以上部分的数据用于描述每个请求处理时间的分布情况,比如以上测试,80%的请求处理时间都不超过 834ms,这个处理时间是指前面的 Time per request,即对于单个用户而言,平均每个请求的处理时间。

4、ab性能指标:
在进行性能测试过程中有几个指标比较重要:
吞吐率(Requests per second)
服务器并发处理能力的量化描述,单位是 reqs/s,指的是在某个并发用户数下单位时间内处理的请求数。某个并发用户数下单位时间内能处理的最大请求数,称之为最大吞吐率。
注:吞吐率是基于并发用户数的。这句话代表了两个含义:

•   吞吐率和并发用户数相关;
•   不同的并发用户数下,吞吐率一般是不同的。

计算公式:总请求数/处理完成这些请求数所花费的时间,即
Request per second=Complete requests/Time taken for tests
必须要说明的是,这个数值表示当前机器的整体性能,值越大越好。
并发连接数(The number of concurrent connections)
并发连接数指的是某个时刻服务器所接受的请求数目,简单的讲,就是一个会话。
并发用户数(Concurrency Level)
要注意区分这个概念和并发连接数之间的区别,一个用户可能同时会产生多个会话,也即连接数。
用户平均请求等待时间(Time per request)
计算公式:处理完成所有请求数所花费的时间/(总请求数/并发用户数),即:
Time per request=Time taken for tests/(Complete requests/Concurrency Level)
服务器平均请求等待时间(Time per request:across all concurrent requests)
计算公式:处理完成所有请求数所花费的时间/总请求数,即:
Time taken for/testsComplete requests
可以看到,它是吞吐率的倒数。
同时,它也等于用户平均请求等待时间/并发用户数,即
Time per request/Concurrency Level
四、部署PHP加速软件Xcache
Xcache是一款用来为PHP页面做缓存的工具。当然,实际工作环境中,是不会对PHP动态页面来做缓存的,意义不大(动态页面嘛,数据更新较快)又占用内存空间。这里只是为了表现出,PHP动态页面,也是可以做缓存的。
1、安装xcache:

之前下载的软件包中就包含着xcache的源码包
[root@php php]# tar zxf xcache-3.2.0.tar.gz 
[root@php php]# cd xcache-3.2.0/
[root@php xcache-3.2.0]# /usr/local/php5.6/bin/phpize                   # 使用PHP中的phpize生成configure文件
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
[root@php xcache-3.2.0]# ./configure  --enable-xcache  --enable-xcache-coverager --enable-xcache-optimizer --with-php-config=/usr/local/php5.6/bin/php-config && make && make install
#安装完毕后记住最后结尾提示的路劲,会用到:
/usr/local/php5.6/lib/php/extensions/no-debug-non-zts-20131226/

2、创建xcache缓存文件:

[root@php /]# touch /tmp/xcache
[root@php /]# chmod 777 /tmp/xcache          # 需要有写入权限

3、复制xcache后台管理程序到网站根目录:

[root@php /]# cd /php/xcache-3.2.0/
[root@php xcache-3.2.0]# cp -r htdocs/ /var/www/html/xcache

4、配置PHP支持xcache:

[root@php /]# vim /etc/php.ini 
#在配置文件末尾添加以下内容
[xcache-common]
extension = /usr/local/php5.6/lib/php/extensions/no-debug-non-zts-20131226/xcache.so
# 这个就是指定安装xcache后返回的目录
[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 =""
#写完后保存退出
[root@php /]# service php-fpm restart 
Gracefully shutting down php-fpm . done
Starting php-fpm  done

5、配置NFS,并回到Apache服务器挂载NFS共享目录,以便同步网页根目录下的文件:

[root@php /]# vim /etc/exports
/var/www/html/       192.168.171.0/24(rw,sec=sys,sync,no_root_squash)
[root@php /]# systemctl restart nfs               # 重启nfs使之生效
#回到Apache服务器
[root@apache /]# showmount -e 192.168.171.133            # 确认可以查看到PHP共享的目录
Export list for 192.168.171.133:
/var/www/html 192.168.171.0/24
[root@apache /]# mount -t nfs 192.168.171.133:/var/www/html/ /var/www/html/            # 挂载到本地网站根目录
[root@apache /]# df -hT
192.168.171.133:/var/www/html nfs4       50G  4.8G   46G  10% /var/www/html

6、测试:
访问www.test.com/xcache 即可看到如下页面:
部署LAMP动静分离
到此,php的加速软件xcache就安装完成

7、对Apache动态页面测试:

[root@apache /]# ab -c 100 -n 1000   http://192.168.171.134/index.php                    # 第一次测试
.............................    //
Time taken for tests:   0.787 seconds
.............................     //
Requests per second:    1270.78 [#/sec] (mean)
.............................    //
[root@apache /]# ab -c 100 -n 1000  http://192.168.171.134/index.php                  # 第二次测试
.............................       //
Time taken for tests:   0.755 seconds
.............................      //
Requests per second:    1325.23 [#/sec] (mean)
.............................     //

查看Xcache的命中率:
部署LAMP动静分离
五、部署bbs论坛
PHP服务器上操作:
之前下载的软件包中有bbs论坛的源码包,拉过来用即可

[root@php php]# unzip Discuz_7.0.0_FULL_SC_UTF8.zip 
[root@php php]# cd Discuz_7.0.0_FULL_SC_UTF8/
[root@php Discuz_7.0.0_FULL_SC_UTF8]# cp -r upload/ /var/www/html/bbs
[root@php Discuz_7.0.0_FULL_SC_UTF8]# chmod -R 777 /var/www/html/bbs
[root@php /]# vim /etc/php.ini 
......................     // 省略部分内容
short_open_tag = On            # 定位到此行,修改Off为On

[root@php /]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done

配置bbs(使用之前用来测试链接数据库的用户给bbs论坛使用即可)
访问www.test.com/bbs/install

部署LAMP动静分离

部署LAMP动静分离
部署LAMP动静分离
部署LAMP动静分离
部署LAMP动静分离

推荐阅读:
  1. Centos 7.3部署LAMP架构动静分离
  2. Centos7.3 部署 LAMP 架构动静分离

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

lamp la

上一篇:如何在非Activity中启动、绑定Service(服务)

下一篇:mongodb

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》