網(wǎng)站建設(shè)英文怎么說(shuō)百度一下你就知道官網(wǎng)網(wǎng)址
fcgi 模式編譯安裝 LAMP+xcache
php 的工作模式:
php 在 lamp 環(huán)境下共有三種工作模式:CGI 模式、apache 模塊、FastCGI 模式。CGI 模式下運(yùn)行 PHP,性能不是很好。作為 apache 的模塊方式運(yùn)行,在以前的課程中編譯安裝 lamp 已經(jīng)介紹過(guò)了。FastCGI 的方式和 apache 模塊的不同點(diǎn)在于:FastCGI 方式 PHP 是一處獨(dú)立的進(jìn)程,所有 PHP 子進(jìn)程都由 PHP 的一個(gè)叫作 php-fpm 的組件負(fù)責(zé)管理;而 apache 模塊化方式運(yùn)行的 PHP,則是 apache 負(fù)責(zé)調(diào)用 PHP 完成工作。PHP 的 FastCGI 方式性能要比 apache
模塊化方式強(qiáng)很多,今天我們以 FastCGI 方式編譯安裝 lamp。
FastCGI 工作機(jī)制:
Linux Web服務(wù)器 PHP MySQL數(shù)據(jù)庫(kù) xcache
Centos7 Httpd-2.4.23 php-5.4.26 M Mysql5.7 xcache-3.1.0
首先客戶端發(fā)起請(qǐng)求,請(qǐng)求分為 2 種,一種是靜態(tài)請(qǐng)求它可以直接由 Apache 直接響應(yīng)返回;另一種是動(dòng)態(tài)的請(qǐng)求,如其中包含中 php 或者 Perl 這種腳本解釋性語(yǔ)言,則由 Apache 服務(wù)器通過(guò) fastcgi 協(xié)議調(diào)用 php 服務(wù)器執(zhí)行并返回給Apache由 Apache返回解釋執(zhí)行后的結(jié)果,如果這個(gè)過(guò)程中涉及到對(duì)數(shù)據(jù)的操作,此時(shí) php 服務(wù)器還會(huì)還會(huì)通過(guò) mysql 協(xié)議調(diào)用 mysql服務(wù)器。 編譯環(huán)境及各軟件版本: 主機(jī)規(guī)劃(關(guān)掉防火墻、SELinux)
至少 3 臺(tái)主機(jī),操作系統(tǒng)都是 centos7.2.網(wǎng)段在 192.168.24.0/24 網(wǎng)關(guān) 192.168.24.1
分配如下:
1 臺(tái) httpd 服務(wù)器(192.168.24.128)
1 臺(tái) php 服務(wù)器(192.168.24.129)
1 臺(tái) mysql 服務(wù)器(192.168.24.130)
編譯安裝 LAMP
編譯安裝 apache(請(qǐng)參考前面 apache 的安裝)
編譯安裝 mysql(請(qǐng)參考 mysql 安裝)
FastCGI 方式安裝 php
1、解決依賴關(guān)系
在安裝中顯示libmcrypt和PHP沒(méi)有安裝上,這就我要我們手動(dòng)安裝。
安裝libmcrypt
注:/usr/local前面沒(méi)有空格
2、編譯安裝PHP
相關(guān)選項(xiàng)的解釋:
--prefix=/usr/local/php5.6//安裝位置
--with-mysql=mysqlnd //支持 mysql
--with-pdo-mysql=mysqlnd //支持 pdo 模塊
--with-mysqli=mysqlnd //支持 mysqli 模塊
注:上面的三選項(xiàng)的作用:數(shù)據(jù)庫(kù)與 php 不在一個(gè)服務(wù)器上,指定此種方式,安裝數(shù)據(jù)庫(kù)
連接驅(qū)動(dòng)
--with-openssl//支持 openssl 模塊
--enable-fpm//支持 fpm 模式
--enable-sockets//啟用 socket 支持
--enable-sysvshm//啟用系統(tǒng)共享內(nèi)存支持
--enable-mbstring//多字節(jié)字串、像我們的中文就是多字節(jié)字串
--with-freetype-dir//支持 freetype、就要裝 freetype-devel、跟字體相關(guān)的、字體解析工具
--with-jpeg-dir
--with-png-dir
注:上面的二選項(xiàng)的作用:處理 jpeg、png 圖片的、php 可以動(dòng)態(tài)生成 jpeg 圖片
--with-zlib//是個(gè)壓縮庫(kù)、在互聯(lián)網(wǎng)傳輸時(shí)用來(lái)壓縮傳輸?shù)?--with-libxml-dir=/usr//這個(gè) libxml 是用來(lái)解析 xml 的、指定/usr 下
--enable-xml //支持 xml 的
--with-mhash//支持 mhash
--with-mcrypt=/usr/local/libmcrypt //libmcrypt-devel 這個(gè)程序包所指定的
--with-config-file-path=/etc //指定配置文件的存放路徑的
--with-config-file-scan-dir=/etc/php.d //配置文件掃描路徑
--with-bz2 //支持 BZip2
為了支持 apache 的 worker 或 event 這兩個(gè) MPM,編譯時(shí)使用了--enable-maintainer-zts 選項(xiàng)
如果使用 PHP5.3 以上版本,為了鏈接 MySQL 數(shù)據(jù)庫(kù),可以指定 mysqlnd,這樣在本機(jī)就不需要先安裝 MySQL 或 MySQL 開(kāi)發(fā)包了。mysqlnd 從 php 5.3 開(kāi)始可用,可以編譯時(shí)綁定到它(而不用和具體的 MySQL 客戶端庫(kù)綁定形成依賴),但從 PHP 5.4 開(kāi)始它就是默認(rèn)設(shè)置了。
3、提供 php 配置文件
4、為 php-fpm 提供腳本

5、提供 php-fpm 配置文件并編輯:

pid = run/php-fpm.pid
listen = 192.168.24.129:9000
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
啟動(dòng) php-fpm 服務(wù):
在該主機(jī)上新建虛擬主機(jī)目錄用于存放網(wǎng)頁(yè)文件
至此 php 安裝配置完畢,下面配置 apache 通過(guò) fastcgi 協(xié)議調(diào)用 php
6、配置 apache(切換到 apache 主機(jī)上操作)
使用腳本安裝Apache,把需要的包上傳到相關(guān)的目錄下。

上圖顯示Apache安裝成功
在 Apache2.4 以后已經(jīng)專門有一個(gè)模塊針對(duì) FastCGI 的實(shí)現(xiàn),此模塊為 mod_proxy_fcgi.so,
它其實(shí)是作為 mod_proxy.so 模塊的擴(kuò)充,因此,這兩個(gè)模塊都要加載 LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
過(guò)濾一下這兩個(gè)模塊是否開(kāi)啟
建立一個(gè)目錄作為虛擬主機(jī)的家目錄
[root@http-24 conf]# mkdir -p /var/www/benet
編輯主配置文件 httpd.conf,開(kāi)啟虛擬主機(jī)
啟用 Include conf/extra/httpd-vhosts.conf(474行)
同時(shí)定位 AddType;添加下面兩行:讓 apache 能識(shí)別 php 格式的頁(yè)面
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
并且定位至 DirectoryIndex:支持 php 格式的主頁(yè)
DirectoryIndex index.php index.html #添加 index.php(最好添加在最前面)
<IfModule dir_module>DirectoryIndex index.php index.html (258行)
</IfModule>
配置虛擬主機(jī)支持使用 fcgi
[root@www ~]# vi /usr/local/http-2.4.23/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>ServerAdmin webmaster@benet.comDocumentRoot "/var/www/benet"ServerName www.benet.comServerAlias benet.comErrorLog "logs/benet.com-error_log"CustomLog "logs/benet.com-access_log" commonProxyRequests Off
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://192.168.31.141:9000/var/www/benet/$1#<LocationMatch "^(.*\.php(/.*)?)$"># ProxyPass fcgi://192.168.31.141:9000/var/www/benet#</LocationMatch>
<Directory "/var/www/benet">Options FollowSymLinksAllowOverride NoneRequire all granted
</Directory>
</VirtualHost>
其中:
ProxyRequests off #關(guān)閉正向代理
ProxyPassMatch:把以.php 結(jié)尾的文件請(qǐng)求發(fā)送到 php-fpm 進(jìn)程,php-fpm 至少需要知道運(yùn)行的目錄和 URI,所以這里直接在 fcgi://192.168.31.141:9000 后指明了這兩個(gè)參數(shù),其它的參數(shù)的傳遞已經(jīng)被 mod_proxy_fcgi.so 進(jìn)行了封裝,不需要手動(dòng)指定。特別注意的是,紅色字體部分需要與<VirtualHost >中的 DocumentRoot 后的路徑一致
ProxyPassMatch
只有滿足特定正則模式的內(nèi)容才會(huì)匹配并執(zhí)行此規(guī)則,這里的模式是,^/(.*\.php(/.*)?)$從網(wǎng)站(虛擬主機(jī)<VirtualHost >的根目錄開(kāi)始,匹配任何以 .php 結(jié)尾,或者在 .php 之后緊跟一個(gè) / 再跟別的內(nèi)容的路徑。^ (caret) 和 $ (dollar)標(biāo)志要匹配的路徑的開(kāi)始和結(jié)束( )括號(hào)里的內(nèi)容可以用 $1 來(lái)表示,以方便后面引用它。fcgi://192.168.31.141:9000 通過(guò) mod_proxy_fcgi 來(lái)轉(zhuǎn)發(fā)的代理,使用 fastCGI 協(xié)議,轉(zhuǎn)到PHP-FPM 監(jiān)聽(tīng)的端口。/path/to/your/documentroot/非常重要!必須與虛擬主機(jī)的路徑匹配,且必須是對(duì)應(yīng) php 文件在操作系統(tǒng)中的絕對(duì)路徑。否則會(huì)找不到文件。
$1 可以從原始請(qǐng)求擴(kuò)展成整個(gè)請(qǐng)求路徑的變量,這里指代前面( ) 里面匹配的那個(gè)路徑(uri)
充:Apache httpd 2.4 以前的版本中,要么把 PHP 作為 Apache 的模塊運(yùn)行,要么添加一個(gè)第三方模塊支持 PHP-FPM 實(shí)現(xiàn)。 三、腳本安裝MySQL
在 mysql 主機(jī)上創(chuàng)建用于 php 服務(wù)器連接的 mysql 賬戶
mysql> grant all on *.* to testuser@'%' identified by '123456’;
注意防火墻要允許 mysql 連接。
在 php 服務(wù)器上的/var/www/benet 目錄下創(chuàng)建.php 的測(cè)試頁(yè):
[root@phpserver ~]# cat /var/www/benet/index.php
<?php
phpinfo();
?>
[root@phpserver ~]# cat /var/www/benet/test1.php
<?php
$link=mysql_connect('192.168.31.225','testuser','123456');
if ($link)echo "connection success......";
mysql_close();
?>
測(cè)試訪問(wèn) php 測(cè)試頁(yè):

看到上面兩個(gè)測(cè)試頁(yè)說(shuō)明 apache、php、mysql 之間可以協(xié)同工作了。 7、壓力測(cè)試
網(wǎng)站性能壓力測(cè)試是服務(wù)器網(wǎng)站性能調(diào)優(yōu)過(guò)程中必不可缺少的一環(huán)。只有讓服務(wù)器處在高壓情況下,才能真正體現(xiàn)出軟件、硬件等各種設(shè)置不當(dāng)所暴露出的問(wèn)題。性能測(cè)試工具目前最常見(jiàn)的有以下幾種:ab、http_load、webbench、siege。今天我們專門來(lái)介紹 ab。
ab 是 apache 自帶的壓力測(cè)試工具。ab 非常實(shí)用,它不僅可以對(duì) apache 服務(wù)器進(jìn)行網(wǎng)站訪問(wèn)壓力測(cè)試,也可以對(duì)或其它類型的服務(wù)器進(jìn)行壓力測(cè)試。比如 nginx、tomcat、IIS 等。下面我們開(kāi)始介紹有關(guān) ab 命令的使用:
1.ab 的原理
2.ab 的安裝
3.ab 參數(shù)說(shuō)明
4.ab 性能指標(biāo)
5.ab 實(shí)際使用
6.測(cè)試 nginx 性能
1)ab 的原理
ab 是 apachebench 命令的縮寫。
ab 的原理:ab 命令會(huì)創(chuàng)建多個(gè)并發(fā)訪問(wèn)線程,模擬多個(gè)訪問(wèn)者同時(shí)對(duì)某一 URL 地址進(jìn)行訪
問(wèn)。它的測(cè)試目標(biāo)是基于 URL 的,因此,它既可以用來(lái)測(cè)試 apache 的負(fù)載壓力,也可以測(cè)
試 nginx、lighthttp、tomcat、IIS 等其它 Web 服務(wù)器的壓力。
ab 命令對(duì)發(fā)出負(fù)載的計(jì)算機(jī)要求很低,它既不會(huì)占用很高 CPU,也不會(huì)占用很多內(nèi)存。但
卻會(huì)給目標(biāo)服務(wù)器造成巨大的負(fù)載,其原理類似 CC 攻擊。自己測(cè)試使用也需要注意,否則
一次上太多的負(fù)載??赡茉斐赡繕?biāo)服務(wù)器資源耗完,嚴(yán)重時(shí)甚至導(dǎo)致死機(jī)。
2)ab 的安裝
ab 的安裝非常簡(jiǎn)單,如果是源碼安裝 apache 的話,那就更簡(jiǎn)單了。apache 安裝完畢后 ab
命令存放在 apache 安裝目錄的 bin 目錄下。如下:
/usr/local/http2.4.23/bin/ab
如果 apache 是通過(guò) yum 的 RPM 包方式安裝的話,ab 命令默認(rèn)存放在/usr/bin 目錄下。如
下:
which ab
注意:如果不想安裝 apache 但是又想使用 ab 命令的話,我們可以直接安裝 apache 的工具
包 httpd-tools。如下:
yum -y install httpd-tools
查看 ab 是否安裝成功,可以切換到上述目錄下,使用 ab –V 命令進(jìn)行檢測(cè)。如下: [root@www ~]# /usr/local/http-2.4.23/bin/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/
如上圖,如果 ab –V 命令出錯(cuò),可以 exporexport LD_LIBRARY_PATH="/usr/local/openssl/lib/",
就可以了。
3)ab 參數(shù)說(shuō)明
有關(guān) ab 命令的使用,我們可以通過(guò)幫助命令進(jìn)行查看。如下:
[root@cent05 ~]# ab --help
下面我們對(duì)這些參數(shù),進(jìn)行相關(guān)說(shuō)明。如下:
-n:在測(cè)試會(huì)話中所執(zhí)行的請(qǐng)求個(gè)數(shù)(即總請(qǐng)求數(shù))。
-c:一次產(chǎn)生的請(qǐng)求個(gè)數(shù)(即并發(fā)用戶數(shù))。 [root@mysql-24 src]# ab -c 500 -n 10000 http://192.168.24.128/index.html
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 192.168.24.128 (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 requestsServer Software: Apache/2.4.23
Server Hostname: 192.168.24.128
Server Port: 80Document Path: /index.html #請(qǐng)求的資源
Document Length: 312 bytes#HTTP 響應(yīng)數(shù)據(jù)的正文長(zhǎng)度
Concurrency Level: 500#并發(fā)個(gè)數(shù)(并發(fā)用戶數(shù))
Time taken for tests: 1.452 seconds#所有這些請(qǐng)求處理完成所花費(fèi)的時(shí)間
Complete requests: 10000#完成請(qǐng)求數(shù)
Failed requests: 0#失敗的請(qǐng)求數(shù)
Non-2xx responses: 10000
Total transferred: 4760000 bytes#表示所有請(qǐng)求的響應(yīng)數(shù)據(jù)長(zhǎng)度總和,包括每個(gè) HTTP響應(yīng)數(shù)據(jù)的頭信息和正文數(shù)據(jù)的長(zhǎng)度。注意這里不包括 HTTP 請(qǐng)求數(shù)據(jù)的長(zhǎng)度,僅僅為 web服務(wù)器流向用戶 PC 的應(yīng)用層數(shù)據(jù)總長(zhǎng)度。HTML transferred: 3120000 bytes# 表示所有請(qǐng)求的響應(yīng)數(shù)據(jù)中正文數(shù)據(jù)的總和,也就是減去了 Total transferred 中 HTTP 響應(yīng)數(shù)據(jù)中的頭信息的長(zhǎng)度。
Requests per second: 7530.93 [#/sec] (mean) #吞吐量-每秒請(qǐng)求數(shù)。計(jì)算公式:
Complete requests/Time taken for tests
Time per request: 66.393 [ms] (mean) #用戶平均請(qǐng)求等待時(shí)間,計(jì)算公式:Time token for tests/(Complete requests/Concurrency Level)。
Time per request: 0.133 [ms] (mean, across all concurrent requests)#服務(wù)器平均請(qǐng)求等待時(shí)間,計(jì)算公式:Time taken for tests/Complete requests。
Transfer rate: 3500.71 [Kbytes/sec] received#表示這些請(qǐng)求在單位時(shí)間內(nèi)從服務(wù)器獲取的數(shù)據(jù)長(zhǎng)度,計(jì)算公式:Total trnasferred/ Time taken for tests,這個(gè)統(tǒng)計(jì)很好的說(shuō)明服務(wù)器的處理能力達(dá)到極限時(shí),其出口寬帶的需求量。(即平均每秒網(wǎng)絡(luò)上的流量)Connection Times (ms)min mean[+/-sd] median max
Connect: 0 40 143.1 21 1039
Processing: 6 53 92.8 32 935
Waiting: 5 46 91.6 26 920
Total: 12 93 174.4 58 1467Percentage of the requests served within a certain time (ms)50% 5866% 6675% 7480% 7990% 9495% 27898% 104399% 1069100% 1467 (longest request)
這部分?jǐn)?shù)據(jù)用于描述每個(gè)請(qǐng)求處理時(shí)間的分布情況,比如以上測(cè)試,80%的請(qǐng)求處理時(shí)間都不超過(guò) 66ms,這個(gè)處理時(shí)間是指前面的 Time per request,即對(duì)于單個(gè)用戶而言,平均每個(gè)請(qǐng)求的處理時(shí)間。
繼續(xù)壓力測(cè)試我們?cè)賮?lái)進(jìn)行一次壓力測(cè)試,此時(shí)并發(fā)用戶數(shù)為 1000,其他條件不變,查看兩次測(cè)試結(jié)果的吞吐量差別
4)ab 性能指標(biāo)
在進(jìn)行性能測(cè)試過(guò)程中有幾個(gè)指標(biāo)比較重要:
1、吞吐率(Requests per second)
服務(wù)器并發(fā)處理能力的量化描述,單位是 reqs/s,指的是在某個(gè)并發(fā)用戶數(shù)下單位時(shí)間內(nèi)處理的請(qǐng)求數(shù)。某個(gè)并發(fā)用戶數(shù)下單位時(shí)間內(nèi)能處理的最大請(qǐng)求數(shù),稱之為最大吞吐率記住:吞吐率是基于并發(fā)用戶數(shù)的。這句話代表了兩個(gè)含義:
a、吞吐率和并發(fā)用戶數(shù)相關(guān)
b、不同的并發(fā)用戶數(shù)下,吞吐率一般是不同的
計(jì)算公式:總請(qǐng)求數(shù)/處理完成這些請(qǐng)求數(shù)所花費(fèi)的時(shí)間,即
Request per second=Complete requests/Time taken for tests
必須要說(shuō)明的是,這個(gè)數(shù)值表示當(dāng)前機(jī)器的整體性能,值越大越好。
2、并發(fā)連接數(shù)(The number of concurrent connections)
并發(fā)連接數(shù)指的是某個(gè)時(shí)刻服務(wù)器所接受的請(qǐng)求數(shù)目,簡(jiǎn)單的講,就是一個(gè)會(huì)話。
3、并發(fā)用戶數(shù)(Concurrency Level)
要注意區(qū)分這個(gè)概念和并發(fā)連接數(shù)之間的區(qū)別,一個(gè)用戶可能同時(shí)會(huì)產(chǎn)生多個(gè)會(huì)話,也即連接數(shù)。
4、用戶平均請(qǐng)求等待時(shí)間(Time per request)
計(jì)算公式:處理完成所有請(qǐng)求數(shù)所花費(fèi)的時(shí)間/(總請(qǐng)求數(shù)/并發(fā)用戶數(shù)),即:
Time per request=Time taken for tests/(Complete requests/Concurrency Level)
5、服務(wù)器平均請(qǐng)求等待時(shí)間(Time per request:across all concurrent requests)計(jì)算公式:處理完成所有請(qǐng)求數(shù)所花費(fèi)的時(shí)間/總請(qǐng)求數(shù),即:Time taken for/testsComplete requests
可以看到,它是吞吐率的倒數(shù)。同時(shí),它也等于用戶平均請(qǐng)求等待時(shí)間/并發(fā)用戶數(shù),即Time per request/Concurrency Level 8、CentOS7.2 下安裝 php 加速軟件 Xcache(在 php 主機(jī)上完成下面的操作) 說(shuō)明:
php 安裝目錄:/usr/local/php5.6
php.ini 配置文件路徑:/etc/php.ini
php 網(wǎng)頁(yè)根目錄:/var/www/benet 1)安裝 xcache
wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz #下載 [root@php-24 src]# tar zxf xcache-3.2.0.tar.gz
[root@php-24 src]# cd xcache-3.2.0/
[root@php-24 xcache-3.2.0]# /usr/local/php5.6/bin/phpize
[root@php-24 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
Installing shared extensions:
/usr/local/php5.6/lib/php/extensions/no-debug-zts-20131226/
安裝完成之后,出現(xiàn)下面的界面,記住以下路徑,后面會(huì)用到
/usr/local/php5.6/lib/php/extensions/no-debug-zts-20131226/ 2)創(chuàng)建 xcache 緩存文件
# touch /tmp/xcache
# chmod 777 /tmp/xcache
3)拷貝 xcache 后臺(tái)管理程序到網(wǎng)站根目錄 [root@php-24 xcache-3.2.0]# cp -r htdocs/ /var/www/benet/xcache
4)配置 php 支持 xcache
vi / etc/php.ini #編輯配置文件,在最后一行添加以下內(nèi)容 [xcache-common]
extension = /usr/local/php5.6/lib/php/extensions/no-debug-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 主機(jī)的網(wǎng)頁(yè)文檔目錄下
[root@phpserver ~]# scp -r /var/www/benet/xcache/ 空格root@192.168.31.83:/var/www/benet/ 6)測(cè)試
service php-fpm restart #重啟 php-fpm
瀏覽器打開(kāi)網(wǎng)站根目錄下面的 xcache
http://http://192.168.24.128/xcache 可以看到如下頁(yè)面:
至此,Linux 下安裝 php 加速軟件 Xcache 教程完成
執(zhí)行 ab 壓力測(cè)試:
執(zhí)行第一次壓力測(cè)試
[root@mysql-24 src]# ab -c 100 -n 1000 http://192.168.24.128/index.php
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 192.168.24.128 (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 requestsServer Software: Apache/2.4.23
Server Hostname: 192.168.24.128
Server Port: 80Document Path: /index.php
Document Length: 84914 bytesConcurrency Level: 100
Time taken for tests: 2.087 seconds
Complete requests: 1000
Failed requests: 90(Connect: 0, Receive: 0, Length: 90, Exceptions: 0)
Write errors: 0
Total transferred: 85084899 bytes
HTML transferred: 84913899 bytes
Requests per second: 479.21 [#/sec] (mean)
Time per request: 208.675 [ms] (mean)
Time per request: 2.087 [ms] (mean, across all concurrent requests)
Transfer rate: 39818.21 [Kbytes/sec] receivedConnection Times (ms)min mean[+/-sd] median max
Connect: 0 3 2.7 2 11
Processing: 40 195 27.4 202 255
Waiting: 19 189 27.3 195 236
Total: 46 198 25.9 203 256Percentage of the requests served within a certain time (ms)50% 20366% 20775% 20980% 21090% 21495% 21798% 22599% 231100% 256 (longest request)
執(zhí)行第二次壓力測(cè)試
[root@mysql-24 src]# ab -c 100 -n 1000 http://192.168.24.128/index.php
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 192.168.24.128 (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 requestsServer Software: Apache/2.4.23
Server Hostname: 192.168.24.128
Server Port: 80Document Path: /index.php
Document Length: 84914 bytesConcurrency Level: 100
Time taken for tests: 2.101 seconds
Complete requests: 1000
Failed requests: 89(Connect: 0, Receive: 0, Length: 89, Exceptions: 0)
Write errors: 0
Total transferred: 85084903 bytes
HTML transferred: 84913903 bytes
Requests per second: 475.85 [#/sec] (mean)
Time per request: 210.150 [ms] (mean)
Time per request: 2.101 [ms] (mean, across all concurrent requests)
Transfer rate: 39538.83 [Kbytes/sec] receivedConnection Times (ms)min mean[+/-sd] median max
Connect: 0 6 7.8 3 30
Processing: 34 194 27.4 199 265
Waiting: 10 184 27.3 189 261
Total: 43 200 23.5 202 294Percentage of the requests served within a certain time (ms)50% 20266% 20775% 20980% 21190% 21795% 22698% 24399% 261100% 294 (longest request)
9、部署 bbs 論壇
Discuz 的程序文件解壓,并且將 upload 中所有文件放置到網(wǎng)站目錄(php 服務(wù)器的操作)
#unzip Discuz_7.0.0_FULL_SC_UTF8.zip -d discus
[root@php-24 src]# mvdiscus/Discuz_7.0.0_FULL_SC_UTF8/ /var/www/benet/bbs
設(shè)置 php-fpm 的服務(wù)用戶為下面文件的屬主或者對(duì)其設(shè)置寫權(quán)限,否則安裝時(shí)會(huì)報(bào)錯(cuò)
#cd /var/www/benet/bbs
#chown -R nobody config.inc.php attachments/forumdata/
uc_client/data/cache/ templates/
#chmod -R 777 uc_server/data/
修改 php.ini 文件
short_open_tag = On
# service php-fpm restart
web 服務(wù)器也需要有靜態(tài)文件(apache 服務(wù)器上操作)
#unzip Discuz_7.0.0_FULL_SC_UTF8.zip -d discus
# mv Discuz/upload/ /var/www/benet/bbs
設(shè)置 httpd 的服務(wù)用戶對(duì)指定文件也需要有寫權(quán)限
#cd /var/www/benet/bbs
#chown -R daemon config.inc.php attachments/forumdata/
uc_client/data/cache/ templates/
在數(shù)據(jù)庫(kù)服務(wù)器上創(chuàng)建 bbs 數(shù)據(jù)庫(kù)及授權(quán)帳戶
mysql> create database bbsdb;
Query OK, 1 row affected (0.01 sec)
mysql> grant all on bbsdb.* to runbbs@'%'identified by 'pwd@123';
Query OK, 0 rows affected, 1 warning (0.03 sec)
置完成之后,輸入 httd://192.168.24.128/bbs/install 即可安裝
填寫數(shù)據(jù)庫(kù)的相關(guān)信息,添加數(shù)據(jù)庫(kù)服務(wù)器的地址和 MariaDB 創(chuàng)建的數(shù)據(jù)庫(kù)和用戶密碼,而后在設(shè)置 bbs 的管理員帳號(hào)密碼就可以繼續(xù)安裝了。剩下的根據(jù)提示安裝即可。
出現(xiàn)上面這種情況是由于 php 服務(wù)器安裝了 discuz 之后導(dǎo)致程序發(fā)生變化從而導(dǎo)致動(dòng)態(tài)服務(wù)器和靜態(tài)服務(wù)器的程序不一致,只需要手動(dòng)把 bbs 服務(wù)器的文件和 web 服務(wù)器進(jìn)行一次同步即可,如果想實(shí)現(xiàn)自動(dòng)同步,需要使用其他服務(wù),如 initory+rsync、sersync 等工具。
#scp -r /var/www/benet/bbs/* root@192.168.31.83:/var/www/benet/bbs/
動(dòng)態(tài)服務(wù)器和靜態(tài)服務(wù)器同步文件之后,再次訪問(wèn) bbs 的網(wǎng)址就正常了。
