天天看點

webServer / Apache / apache / apache http server / mod_cluster

apache doc

http://httpd.apache.org/docs/2.2/

http://www.aslibra.com/blog/go.php/category/16/

apache download

http://httpd.apache.org/download.cgi

http://apache.mirror.phpchina.com/httpd/httpd-2.2.8.tar.gz

http://apache.mirror.phpchina.com/httpd/httpd-2.2.8.tar.bz2

http://apache.mirror.phpchina.com/httpd/httpd-2.2.8-win32-src.zip

http://apache.mirror.phpchina.com/httpd/binaries/win32/apache_2.2.8-win32-x86-no_ssl.msi

http://apache.mirror.phpchina.com/httpd/binaries/win32/apache_2.2.8-win32-x86-openssl-0.9.8g.msi

http://apache.mirror.phpchina.com/httpd/

http://labs.xiaonei.com:8081/apache-mirror/httpd/binaries/win32/

http://labs.xiaonei.com:8081/apache-mirror/httpd/binaries/win32/apache_2.2.11-win32-x86-no_ssl.msi

apache montior (server-status)

http://192.168.121.123/server-status

每秒重新整理一次

http://192.168.121.123/server-status?refresh=1

10秒重新整理一次

http://192.168.121.123/server-status?refresh=10

自動重新整理參數值

http://192.168.119.13/server-status?refresh=auto

Total Accesses: 1788997

Total kBytes: 22202823

CPULoad: 4.49397

Uptime: 27953

ReqPerSec: 64.0002

BytesPerSec: 813354

BytesPerReq: 12708.6

BusyWorkers: 100

IdleWorkers: 200

Scoreboard: __K___________K_K__

如何開啟Apache server-status,并禁止直接通過IP通路

(注:如此操作純屬無意義配置,僅作了解,可由它法替代)

http://syq871206.iteye.com/blog/1073585

2.禁止直接通過IP通路

(1)新增一個virtual Host

<VirtualHost *:80>

ServerName 192.168.119.32

DocumentRoot /

<Directory />

Order deny,allow

Deny from all

</Directory>

</VirtualHost>

(2)重新開機一下Apache程序

apache tools webalizer

http://baike.baidu.com/view/1376028.htm

webalizer是一個高效的、免費的web伺服器日志分析程式。

其分析結果以HTML檔案格式儲存,進而可以很友善的通過web伺服器進行浏覽。

Webalizer具有以下一些特性:

  1. 為是用C寫的程式,是以其具有很高的運作效率。在主頻為200Mhz的機器上,webalizer每秒鐘可以分析10000條記錄,是以分析一個40M大小的日志檔案隻需要15秒。

  2. webalizer支援标準的一般日志檔案格式(Common Logfile Format);除此之外,也支援幾種組合日志格式(Combined Logfile Format)的變種,進而可以統計客戶情況以及客戶作業系統類型。并且現在webalizer已經可以支援wu-ftpd xferlog日志格式以及squid日志檔案格式了。

  3. 支援指令行配置以及配置檔案。

  4. 可以支援多種語言,也可以自己進行本地化工作。

  5. 支援多種平台,比如UNIX、linux、NT, OS/2 和 MacOS等。

安裝:

  1.從webalizer的官方站點http://www.mrunix.net/webalizer/下載下傳webalizer,目前的最新版本是webalizer-2.01-06-src.tgz。

  2.首先解開源代碼包:

  tar xvzf webalizer-2.01-06-src.tgz

  3.在生成的目錄中有個lang目錄,該目錄中儲存了各種語言檔案,但是隻有繁體中文版本,可以自己轉換成簡體,或者自己重新翻譯一下。

  4.然後進入生成的目錄:

  ./configure

  make --with-language=chinese

  5.編譯成功後,會産生一個webalizer可執行檔案,可以将其拷貝到/usr/sbin/目錄下:

  cp webalizer /usr/sbin/

  然後就可以開始配置webalizer了。

  配置:

  上面說過,可以通過指令行配置webalizer,也可以通過配置檔案進行配置,在本文中我們将介紹使用指令行參數進行配置,需要了解配置檔案使用方法的朋友可以參考README檔案,裡面有很詳細的介紹。

  可以執行webalizer –h得到所有指令行參數:

  Usage: webalizer [options] [log file]

  -h = 列印幫助資訊

  -v -V = 列印版本資訊

  -d = 列印附加調試資訊

  -F type = 日志格式類型. type= (clf | ftp | squid)

  -i = 忽略曆史檔案

  -p = 保留狀态 (遞增模式)

  -q = 忽略消息資訊

  -Q = 忽略所有資訊

  -Y = 忽略國家圖形

  -G = 忽略小時統計圖形

  -H = 忽略小時統計資訊

  -L = 忽略彩色圖例

  -l num = 在圖形中使用數字背景線

  -m num = 通路逾時 (seconds)

  -T = 列印時間資訊

  -c file = 指定配置檔案

  -n name = 使用的主機名

  -o dir = 結果輸出目錄

  -t name = 指定報告題目上的主機名

  -a name = 隐藏使用者代理名稱

  -r name = 隐藏通路連結

  -s name = 隐藏客戶

  -u name = 隐藏URL

  -x name = 使用檔案擴充名

  -P name = 頁面類型擴充名

  -I name = index别名

  -A num = 顯示前幾名客戶類型

  -C num = 顯示前幾名國家

  -R num = 顯示前幾名連結

  -S num = 顯示前幾名客戶

  -U num = 顯示前幾名URLs

  -e num = 顯示前幾名通路頁面

  -E num = 顯示前幾名不存在的頁面

  -X = 隐藏個别使用者

  -D name = 使用dns緩存檔案

  -N num = DNS 程序數 (0=禁用dns)

  假設,web伺服器主機名為www.test.com,統計站點域名為 www.test.com, 通路日志為/var/log/httpd/access_log, 我們将webalizer分析結果輸出到/var/www/html/log下面。則我們可以建立以下腳本/etc/rc.d/webalizer:

  #!/bin/sh

  run=/usr/sbin/webalizer

  $run -F clf -p -n " " -t "www.test.com"

  -o /var/www/html/log /var/log/httpd/access_log

  說明:

  -F clf 指明我們的web日志格式為标準的一般日志檔案格式(Common Logfile Format)

  -p 指定使用遞增模式,這就是說每作一次分析後,webalizer會生産一個曆史檔案,這樣下一次分析時就可以不分析已經處理過的部分。這樣我們就可以在短時間内轉換我們的日志檔案,而不用擔心通路量太大時日志檔案無限增大了。

  -n “ “ 指定伺服器主機名為空,這樣輸出結果會美觀一些。

  -o “www.test.com” 指定輸出結果标題.

  /var/log/httpd/access_log:指定日志檔案

  然後在/etc/crontab中加入:

  01 1 * * * root /etc/rc.d/webalizer

  即每天淩晨1點執行該腳本。

  然後運作/etc/rc.d/init.d/crond reload重載入crond服務。

  測試:

  執行以下指令:

  # /etc/rc.d/webalizer

  然後在浏覽器中通路http://www.test.com/log/就可以看到webalizer的分析結果了。

  注意:如果您使用了中文語言檔案,但是您的linux不支援中文,則在産生的圖檔中文字可能為亂碼。

apache setup

RedHat Apache

[[email protected] /]# which apachectl

/usr/sbin/apachectl

[[email protected] /]# whereis apachectl

apachectl: /usr/sbin/apachectl /usr/share/man/man8/apachectl.8.gz

[[email protected] /]# find / -name "apachectl" -print

/usr/sbin/apachectl

#檢視Apache版本

[[email protected] /]#  /usr/sbin/apachectl -v

Server version: Apache/2.2.3

Server built:   Jan 11 2008 08:19:18

[[email protected] /]#  apachectl -v

#檢視Apache httpd版本

http://www.chinalinuxpub.com/bbs/archive/index.php/t-21446.html

在2.0版本以前,是叫做apache的,比如1.3、1.4等等 2.0版本以後,開始叫做httpd了

[[email protected] conf]# rpm -q httpd

httpd-2.2.3-11.el5_1.3

[[email protected] /]# /usr/sbin/httpd -v

Server version: Apache/2.2.3

Server built:   Jan 11 2008 08:19:18

#Apache 啟停服務

[[email protected] sbin]# apachectl stop               --停止apache

[[email protected] sbin]# apachectl start               --啟動apache

[[email protected] sbin]# apachectl restart            --重新開機apache

#Apache httpd 啟停服務

[[email protected] /]# /usr/sbin/httpd -k stop                       --停止Apache httpd

[[email protected] /]# /usr/sbin/httpd -k start                       --啟動Apache httpd

[[email protected] /]# /usr/sbin/httpd -k restart                     --重新開機Apache httpd

[[email protected] /]# which httpd

/usr/sbin/httpd

[[email protected] /]# whereis httpd

httpd: /usr/sbin/httpd /usr/sbin/httpd.worker /etc/httpd /usr/lib/httpd /usr/share/man/man8/httpd.8.gz

[[email protected] /]# find / -name "httpd" -print

/etc/httpd

/etc/sysconfig/httpd

/etc/rc.d/init.d/httpd

/etc/logrotate.d/httpd

/var/lock/subsys/httpd

/var/log/httpd

/usr/lib/httpd

/usr/sbin/httpd

#檢視Apache連接配接數,http程序數

[[email protected] /]# ps -ef | grep httpd

[[email protected] /]# ps -ef | grep httpd | wc -l

#統計Apache的線上使用者數方法,并發請求數及TCP狀态

[[email protected] /]# netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

#如何取出特定内容的access_log

[[email protected] /]# grep /var/log/httpd/access_log_2012-02-12-00_00_53   "GET /webapp/wcs/stores/prdprice" access_log_2012-02-13-16_09_02|awk -F ',' '{ print $6}'|awk '{print $2}'|more

#根據access_log 進行資料分析

url    日期    通路總次數    總通路大小    總響應時間    平均大小    平均時間

/emall/v4secondView    20120306(15:00-16:00)    43125    140886906    2440293299    3267    56587

Red Hat Linux 下配置Apache服務

http://www.linux521.com/2009/system/200907/7396_2.html

http://www.newasp.net/tech/server/14356.html

http://www.newasp.net/tech/server/14356_2.html

http://tech.163.com/06/0206/11/299AMBLT0009159K.html

1.檢查是否安裝Apache服務

[[email protected] /]#rpm -qa|grep httpd

2.Apache服務在第一張安裝CD光牒上

[[email protected] /]#rpm -ivh /mnt/cdrom/RedHat/RPMS/httpd-2.0.40-21.i386.rpm

3.配置Apache

。。。

4.

[[email protected] /]# /etc/init.d/httpd start                   --啟動apache

[[email protected] /]# /etc/init.d/httpd resatart              --重新開機apache

[[email protected] /]# /etc/init.d/httpd stop                    --停止apache

綠色安裝方法

把安裝過的安裝目錄保留,以後不用在安裝了 直接bin/httpd.exe -k install -n servicename, mysql也是。

自己動手打造Apache和Mysql綠色免安裝版

http://inshect.iteye.com/blog/343044

自己動手打造Apache和Mysql綠色免安裝版

我自己用了很久了,雖然很簡單,但相信許多人還不知道,就寫出來和大家共享

下載下傳原版,第一次安裝時,裝到D盤或其他盤

再次安裝系統時,不需要再重新安裝Apache和MySQL,隻需要打幾個簡單的指令即可!

本文出處: http://www.21andy.com/

作者: Andy

重裝完系統後

1. 運作CMD進入指令行

2. 進入apache所在的目錄下的bin目錄,如 d:\apache\bin 運作

httpd -k install

隻要這一步apache服務就安裝好了

3. 進入mysql所在的目錄下的bin目錄,如 d:\mysql\bin 運作

mysqld -install

也隻要這一步Mysql服務就安裝好了

解除安裝

和上面2步一樣,進入bin目錄

apache解除安裝指令

httpd -k uninstall

mysql解除安裝指令

mysqld -remove

RedHat6.2 伺服器安裝 Apache

http://www.bdqnht.com/html/wangluo/fuqi/webf/20071219/1639.html

http://www.drupal8.com/

http://mirror.stormreact.org/

http://fpdownload.macromedia.com/get/flashplayer/current/licensing/win/install_flash_player_active_x.exe

Ubuntu Apache 安裝

http://wiki.ubuntu.org.cn/Apache%E5%AE%89%E8%A3%85%E8%AE%BE%E7%BD%AE?highlight=(Apache)

Apache Http Server server status為檢視目前系統使用者數

Linux 下Apache Http Session為:ps aux grep|httpd wc -l

http://user.qzone.qq.com/170475387/blog/1203489758

Apache使用.htaccess實作圖檔防盜鍊

http://blog.usle.cn/article.asp?id=541

apache 防盜鍊兩例

http://hi.baidu.com/snoworld/blog/item/d9fa5066161fb926ab184c77.html

1. 利用rewrite 确認你的apache 能使用rewrite mod

RewriteEngine on

RewriteCond %{HTTP_REFERER} !^http://80yh.com.cn /.*$ [NC]

RewriteCond %{HTTP_REFERER} !^http://80yh.com.cn $ [NC]

RewriteCond %{HTTP_REFERER} !^http://www.80yh.com.cn /.*$ [NC]

RewriteCond %{HTTP_REFERER} !^http://www.80yh.com.cn $ [NC]

RewriteRule .*.(gif|jpb|png|css|js|swf] )$ http://www.80yh.com.cn [R,NC]

其中有色的地方都是要改為你的:

 紅色 :就是改為你提供下載下傳頁面的位址,也就是隻有通過這個位址才可以下載下傳你所提供的東東。

 藍色 :就是要保護檔案的擴充名( 以| 分開) ,也就是說以這些為擴充名的檔案隻有通過紅色 的位址才可以通路。

 綠色 :如果不是通過紅色 的位址通路藍色 這些為擴充名的檔案時就回重定向到綠色 位址上。

2. 利用SetEnvIfNoCase 和 access

SetEnvIfNoCase Referer "^http://80yh.com.cn " local_ref=1

SetEnvIfNoCase Referer "^http://80yh.com.cn " local_ref=1

<FilesMatch ".(gif|jpb|png|css|js|swf )">

Order Allow,Deny

Allow from env=local_ref

</FilesMatch>

紅色 為信任站點,藍色 為受保護的檔案擴充名。

出處:http://www.phpwind.net/read-htm-tid-153039-fpage-1.html

Apache安裝設定

http://wiki.ubuntu.org.cn/Apache%E5%AE%89%E8%A3%85%E8%AE%BE%E7%BD%AE

apache 封 IP 的方法

http://17zouguo.iteye.com/blog/998929

以Apache 2.2作為伺服器:

1. 在配置檔案httpd.conf裡設定:

Xml代碼   

webServer / Apache / apache / apache http server / mod_cluster
  1. < Directory  “/home/www” >   
  2.     Options Indexes FollowSymLinks  
  3.     AllowOverride None  
  4.     Order allow,deny  
  5.     Allow from all  
  6.     Deny from 172.17.18.80  
  7.     Deny from 60.99.125.110  
  8.     ……  
  9. </ Directory >   

 2.在網站根目錄下建立或打開.htaccess檔案,加入如下内容

Properties代碼   

webServer / Apache / apache / apache http server / mod_cluster
  1. Order allow,deny  
  2. Allow from all  
  3. Deny from 172.17 . 18.80   
  4. Deny from 60.99 . 125.110   
  5. ……  

D:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf

配置ApacheSSL 轉發

http://whb.iteye.com/blog/368514

The Apache + SSL on Win32 HOWTO

http://www.apacheforum.com/archive/index.php/t-8.html

http://www.apacheforum.com/showthread.php?t=8

配置SSL 

參考:http://tud.at/programm/apache-ssl-win32-howto.php3

1 安裝apache

apache_2.2.11-win32-x86-openssl-0.9.8i.msi

按照提示一步一步,安裝即可。

*下文中用{apache}代表apache安裝目錄,本例中是:D:/devel/apache2.2/

2 配置SSL

(1)apache_2.2.11-win32-x86-openssl-0.9.8i.msi已經安裝了 OpenSSL and mod_ssl

(2)下載下傳OpenSSL配置檔案

openssl.cnf ,下載下傳檔案,儲存到{apache}\bin下

(3)生成證書

Command代碼

   1. openssl req -config openssl.cnf -new -out my-server.csr 

   2. openssl rsa -in privkey.pem -out my-server.key 

   3. openssl x509 -in my-server.csr -out my-server.cert -req -signkey my-server.key -days 365   

第一條指令提示比較多,大概的輸入些資料就可以了。

“密碼”必須輸入;

“Common Name (eg, your websites domain name) []:”也必須輸入,沒有域名就随便寫一個。

(4)配置SSL

去除conf/httpd.conf下面兩句的注釋,使之生效:

Apache config代碼

   1. LoadModule ssl_module modules/mod_ssl.so 

   2. Include conf/extra/httpd-ssl.conf  

複制{apache}目錄下的, 上述生成的檔案:

bin/my-server.cert => conf/ssl/my-server.cert

bin/my-server.key => conf/ssl/my-server.key

修改conf/extra/httpd-ssl.conf

Apache config代碼

   1. SSLCertificateFile  "D:/devel/apache2.2/conf/server.crt"  => 

   2. SSLCertificateFile "D:/devel/apache2.2/conf/ssl/my-server.cert"  

   3.  

   4. SSLCertificateKeyFile "D:/devel/apache2.2/conf/server.key"  => 

   5. SSLCertificateKeyFile "D:/devel/apache2.2/conf/ssl/my-server.key"   

現在SSL配置完成。下面配置代理

配置代理 

去除conf/httpd.conf下面兩句的注釋,使之生效:

Apache config代碼

   1. LoadModule proxy_module modules/mod_proxy.so 

   2. LoadModule proxy_connect_module modules/mod_proxy_connect.so 

   3. LoadModule proxy_http_module modules/mod_proxy_http.so  

在conf/httpd.conf結尾添加如下配置:

Apache config代碼

   1. ProxyRequests Off 

   2. <Proxy *> 

   3.  Order deny,allow 

   4.  Allow from all 

   5. </proxy> 

   6. ProxyPass / https://{those_compute_ip}/ 

   7. ProxyPassReverse / https://{those_compute_ip}/  

修改conf/extra/httpd-ssl.conf,添加

Apache config代碼

   1. SSLProxyEngine on  

Apache按照端口号配置反向代理

http://whb.iteye.com/blog/402746

Xml代碼

   1. Listen 8001 

   2. Listen 8002 

   3.  

   4. < VirtualHost  _default_:8001 >  

   5. ProxyPass /bob http://192.168.254.30:8001/bob 

   6. ProxyPassReverse /bob http://192.168.254.30:8001/bob 

   7. </ VirtualHost >   

   8.  

   9. < VirtualHost  _default_:8002 >  

  10. ProxyPass /bob https://192.168.254.30:8002/bob 

  11. ProxyPassReverse /bob https://192.168.254.30:8002/bob 

  12. </ VirtualHost >   

Apache Portable Runtime  apr

ref

http://redalx.iteye.com/blog/162246

http://blog.csdn.net/tingya/archive/2006/04/15/664304.aspx

apr說白了就是如何在Tomcat中使用JNI的方式來讀取檔案以及進行網絡傳輸, 提高tomcat 的IO效率。

apr可以大大提升Tomcat對靜态檔案的處理性能,同時如果你使用了HTTPS方式傳輸的話,也可以提升SSL的處理性能。

doc

http://apr .apache.org/

http://tomcat.apache.org/tomcat-5.5-doc/apr.html

http://tomcat .apache.org/tomcat -6.0-doc/apr .html

down

http://tomcat.heanet.ie/native/

http://tomcat.heanet.ie/native/1.1.9/binaries/win32/tcnative-1.dll

setup for Windows

直接下載下傳編譯好的二進制版本的dll庫檔案

http://tomcat.heanet.ie/native/1.1.9/binaries/win32/tcnative-1.dll來使Tomcat啟用APR

如何删除windows 服務apache2.2 

C:\Users\Lindows>sc delete Apache2.2

[SC] DeleteService SUCCESS

setup for linux

在Linux下,可以直接解壓和安裝bin目錄下的tomcat_native.tar.gz檔案,編譯之前要確定apr庫已經安裝,安裝的方式:

# ./configure --with-apr=/usr/local/apr

# make

# make install

安裝成功後還需要對tomcat設定環境變量,方法是在catalina.sh檔案中增加一行:

CATALINA_OPTS="-Djava.library.path=/usr/local/apr/lib"

怎麼才能判斷Tomcat是否已經啟用了APR庫呢?方法是通過看Tomcat的啟動日志

如果沒有啟用APR,則啟動日志一般有這麼一條:

org.apache.coyote.http11.Http11Protocol start

如果啟用了APR,則這條日志就會變成:

使用了apr 之後,如果使用了https,https的配置也需要作改變。需要用到openssl來進行證書檔案的生成。

<!-- ssl for apr -->

<Connector port="8443" maxHttpHeaderSize="8192"

maxThreads="150" minSpareThreads="25" maxSpareThreads="75"

enableLookups="false" disableUploadTimeout="true"

acceptCount="100" scheme="https" secure="true"

clientAuth="false"

SSLEngine="on"

SSLCertificateFile="..\conf\ca\server.crt"

SSLCertificateKeyFile="..\conf\ca\server.key" />

linux下編譯

cd apache-tomcat -5.5.14/bin/tomcat -native-1.1.1/jni/native/

./configure --with-apr =/usr/bin/apr -1-config --with-java-home=/usr/java/jdk1.5.0_06/

make

make install

bin/catalina.sh

加上

CATALINA_OPTS="-Djava.library.path=/usr/local/apr /lib"

分割apache日志 access.log / 截取access.log特定行段内容

[[email protected] ~]# cat /etc/httpd/logs/access_log.1 | gawk 'BEGIN{i=0;}{i=i+1;if((i>1)&&(i<54)) print $0;}' > /etc/httpd/logs/access_cut.log

分割apache日志 rotatelogs cronolog

如何快速統計RoR網站的通路量

http://robbin.iteye.com/blog/97287

webServer tomcat 5 /  tomcat6 / tomcat7

http://lindows.iteye.com/blogs/213348

http://www.iteye.com/topic/810862

Linux下運作的Web伺服器Apache,預設日志檔案是不分割的,一個整檔案既不易于管理,也不易于分析統計。

安裝cronolog後,可以将日志檔案按時間分割,易于管理和分析。

http://blog.jianghu.taobao.com/u/Nzg0MjkwNTY=/blog/blog_detail.htm?aid=22448334

方法一:

配置httpd.conf,找到CustomLog logs/access.log common,用#注解掉這行,在下面加入:

ErrorLog "|bin/rotatelogs.exe logs/error_%Y-%m-%d.log 86400 480"

CustomLog "|bin/rotatelogs.exe logs/access_%Y-%m-%d.log 86400 480" combined

86400表示1天,480是與UTC相差的時間,8×60=480分鐘。

方法二:

去http://cronolog.org/download/index.html下載下傳一個合适版本,我用的是 Win 32 version,

将cronolog.exe解壓到 Apache的bin目錄下,

配置httpd.conf

找到CustomLog logs/access.log common,用#注解掉這行,在下面加入:

CustomLog "|bin/cronolog.exe logs/access_%Y-%m-%d.log" combined

Mcrypt響應慢的一個原因

http://www.laruence.com/2012/09/24/2810.html

Linux随機數發生器導緻Apache程序全部Block的問題追查

http://jarfield.iteye.com/blog/1739834#comments

Linux伺服器在運作時,既沒有鍵盤事件,也沒有滑鼠事件,如何快速積累熵池呢?

google了一下資料,發現有一些程式可以自動補充熵池,例如rngd 或rng-tools 。

我在Linode VPS上嘗試了一下rngd,效果非常明顯。

先觀察rngd啟動前的熵池大小: watch cat /proc/sys/kernel/random/entropy_avail ,在100~200之間。

然後啟動rngd:sudo rngd -r /dev/urandom -o /dev/random -f -t 1

熵池立刻飙升到3712,接近4096的上限。

php / 如果業務依賴随機數,那麼最好使用工具主動補充熵池。

網站項目性能之個人談

http://wangxizhao.iteye.com/blog/651992

            對于并發量很大的網站項目,最容易産生資料庫瓶頸問題。是以我們要優化我們的網站,最常用的莫過于使用網頁靜态化和緩存技術,當然這裡的靜态化不包括僞靜态。有人靜态化生成.html檔案,可是如何在html檔案中包含其他檔案呢?,有人想到iframe,沒錯,可以實作,但是效率不好。是以個人更建議使用SSI技術生成.shtml檔案,縱觀新浪,sohu等幾大門戶網站無不使用此技術。  

    SSI技術優點:SSI技術是通用技術,它不受限于運作環境,在java、dotnet、CGI、ASP、PHP下都可以使用SSI技術;解釋SSI的效率比解釋JSP的效率快很多,因為JSP規範提供了太多的功能,這些功能都需要servlet引擎一一進行解釋,是以效率比較低。  

    生成.shtml檔案,我選用velocity模闆引擎,但是要注意在生成.shtml檔案的時候,模闆會将<!--#include  file="" --> 中的include指令解析成自己的模闆語言,此時我們需要将#轉義成普通字元。  

    解釋.shtml檔案最佳伺服器是APACHE  HTTP SERVER。同時對于靜态檔案我們更需要專業的apache 幫我們解析。其性能遠遠高于tomcat等servlet容器。此刻我們又不得不使用負載均衡将apache和tomcat整合了。之前一直困擾于負載均衡之後的apache如何通路tomcat上的靜态檔案這個問題?百思不得其解,終于在一陣“摸爬滾打”中找到了答案,其實在apache的配置檔案httpd.conf中可以配置:DocumentRoot "D:/apache-tomcat-6.0.18/webapps"  。如此我們怎麼知道我們現在伺服器上的應用已經動靜态分離了呢?可以用這個方法簡單測試下:分别通路一個應用中存在的檔案和不存在的檔案,檢視浏覽器報錯資訊。  

    對于緩存,個人更建議使用全局緩存政策(緩存靜态頁),比如oscache,jbosscache等,而不是使用hibernate的二級緩存。這裡就不作詳細介紹了.

檢視apache連接配接數

http://hi.baidu.com/kson34/blog/item/4b16a77a824928e12f73b37d.html

檢視Apache并發請求數及其TCP連接配接狀态

http://brucectl.iteye.com/blog/284783

Apache檢視連接配接數和限制目前的連接配接數

http://zhengdl126.iteye.com/blog/802520

http://www.linuxidc.com/Linux/2010-10/29069.htm

起因:線上的一台伺服器,最近總是出現 通路 很慢的情況發生,點選一個連結要2秒鐘以上才能打開,按照我們對于通路人數的估計,伺服器應該不至于響應這麼慢,進而需要針對這個問題進行分析,來解決網站通路過慢。

分析:

1、首先,在頁面通路變慢情況發生時,使用 top 指令檢視了伺服器的負載情況,發現負載并不高,初步估計不是程式的問題。 

2、然後,檢視了線程中的 httpd 的數量, ps -aux | grep httpd | wc -l 發現,線程數已經達到了 apache 設定的最大值。由此斷定是網站通路人數過多造成了通路過慢。 

3、為了驗證,檢視了連接配接數和目前的連接配接數,分别是 

    netstat -ant | grep $ip:80 | wc -l 

    netstat -ant | grep $ip:80 | grep EST | wc -l 

    發現果然,連接配接數特别多,遠遠超過我們的估計值。 

4、剛開始的時候,對于伺服器的 MPM 配置方式不是特别的熟悉,認為修改伺服器配置可以解決問題。主要的配置部分包括 prefork 模式 或者 work 模式的配置,

5、後來想到需要檢視使用者都是通路的那些頁面,将配置中的 access_log 打開,發現85%以上的通路都是直接通路的資源檔案,由此判定,使用者可能使用了多線程的下載下傳工具,或者這些資源遭受了盜鍊。

6、找到了問題所在,進行解決也就比較好辦了。想到了兩個方法: 

    A、對單個IP進行連接配接的線程限制,不允許多線程連接配接資源。 

    B、添加URL重寫,防止盜鍊。 

修改Linux核心參數,減少TCP連接配接中的TIME-WAIT sockets

http://brucectl.iteye.com/blog/284763

[[email protected] ~]# netstat -na|grep ESTABLISHED|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -r +0n

[[email protected] ~]# netstat -na|grep SYN|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -r +0n

[[email protected] ~]# netstat -an | grep 80 | awk '{print $6}' | sort | uniq -c | sort -rn

    179 TIME_WAIT

    140 ESTABLISHED

      6 FIN_WAIT2

      6 FIN_WAIT1

      4 CONNECTED

      2 LISTEN

      2

      1 STREAM

      1 CLOSE_WAIT

      1 8804

      1 6980

apache域名綁定

http://javantsky.iteye.com/blog/852982

需求背景:

系統中使用者注冊後會根據id生成其首頁,如http://www.test.com/index/2

使用者希望實作一級域名綁定,即,通過通路http://www.demo.com也能直接通路到其首頁

....balabala....

順便說一個很簡單的二級域名綁定方式

在www.test.com的vhost中添加如下内容:

Java代碼

  1. RewriteEngine on  
  2. RewriteCond %{HTTP_HOST} ^[0 - 9 ]+\.test.com$  
  3. RewriteRule ^/?$ /%{HTTP_HOST}  
  4. RewriteRule ^/([0 - 9 ]+)\.test\.com/?$ /index/$ 1  [R,L]  
RewriteEngine on
RewriteCond %{HTTP_HOST} ^[0-9]+\.test.com$
RewriteRule ^/?$ /%{HTTP_HOST}
RewriteRule ^/([0-9]+)\.test\.com/?$ /index/$1 [R,L]
           

 這樣通過通路http://2.test.com也能範圍到http://www.test.com/index/2中同樣内容了

apache域名綁定的關鍵是urlrewrite,需要一點正則表達的知識。

apache 多站點配置

怎麼在Apache環境下建立N個站點的配置方法

http://www.woplus.com/phptech/apache-website-peizhi/

假設你的主機IP是:127.0.0.1你的主機上有三個域名:

www.a.com     網頁檔案放在E:\web\www\1

www.b.com     網頁檔案放在E:\web\www\2

www.c.com     網頁檔案放在E:\web\www\3

在apache的httpd.conf中加入

#設定不同的域名到不同的目錄

NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>  

DocumentRoot “E:\web\www\a”   

ServerName www.a.com                

</VirtualHost>

<VirtualHost 127.0.0.1>  

DocumentRoot “E:\web\www\b”   

ServerName www.b.com                

</VirtualHost>

<VirtualHost 127.0.0.1>  

DocumentRoot “E:\web\www\c”   

ServerName www.c.com                

</VirtualHost>

配置好後重新開機Apache,OK了!

使用Apache做負載均衡Link_out

http://www.iteye.com/articles/280

ab - Apache HTTP server benchmarking tool  apache ab壓力測試

http://httpd.apache.org/docs/2.0/programs/ab.html

ab

is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs. This especially shows you how many requests per second your Apache installation is capable of serving.

apache ab 壓力測試的輕量級具體做法

http://www.oschina.net/question/234345_56911

一:壓力測試中需要掌握的幾個基本概念

1:吞吐率(Requests per second)

伺服器并發處理能力的量化描述,機關是reqs/s,指的是某個并發使用者數下機關時間内處理的請求數。某個并發使用者數下機關時間内能處理的最大請求數,稱之為最大吞吐率。

記住:吞吐率是基于并發使用者數的。這句話代表了兩個含義,1:吞吐率和并發使用者數相關;2:不同的并發使用者數下,吞吐率一般是不同的。

計算公式:總請求數  / 處理完成這些請求數所花費的時間,即

Request per second = Complete requests  / Time taken for tests

2:并發連接配接數(The number of concurrent connections)

并發連接配接數指的是某個時刻伺服器所接受的請求數目,簡單的講,就是一個會話。

3:并發使用者數(The number of concurrent users,Concurrency Level)

要注意區分這個概念和并發連接配接數之間的差別,一個使用者可能同時會産生多個會話,也即連接配接數。在HTTP/1.1下,IE7支援兩個并發連接配接,IE8支援6個并發連接配接,FireFox3支援4個并發連接配接,是以相應的,我們的并發使用者數就得除以這個基數。

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

二:具體做法

1:壓力測試工具選擇

重量級的工具有Visual Studio 自帶的工具,還有Loader Runner(LR),輕量級的工具有Apache項目中的ApacheBench,簡稱ab。你可以在這裡下載下傳:ab.zip。

2:ab的簡單使用及參數介紹

image

webServer / Apache / apache / apache http server / mod_cluster

以上測試,基于我的一個asp.net的頁面。對于壓力測試,必須時時刻刻做,如果不知道自己的應用能夠承載多少的并發使用者數,那基本上就是在扔定時炸*彈。

原文連結:http://www.cnblogs.com/luminji/archive/2011/09/02/2163525.html

apache ab壓力測試

http://blog.chinaunix.net/space.php?uid=12318776&do=blog&cuid=537944

使用Apache AB實作bugfree登入的腳本

http://www.mamicode.com/info-detail-399524.html

apache 自帶的ab.exe 測試網站的并發量(網站壓力測試)

http://djw0101.iteye.com/blog/1233758

APACHE自帶的測試工具AB(apache benchmark).在APACHE的bin目錄下。

格式: ./ab [options] [http://]hostname[:port]/path

參數:

    -n requests     Number of requests to perform

    //在測試會話中所執行的請求個數。預設時,僅執行一個請求

    -c concurrency Number of multiple requests to make

    //一次産生的請求個數。預設是一次一個。

    -t timelimit    Seconds to max. wait for responses

    //測試所進行的最大秒數。其内部隐含值是-n 50000。它可以使對伺服器的測試限制在一個固定的總時間以内。預設時,沒有時間限制。

    -p postfile     File containing data to POST

    //包含了需要POST的資料的檔案.

    -T content-type Content-type header for POSTing

    //POST資料所使用的Content-type頭資訊。

    -v verbosity    How much troubleshooting info to print

    //設定顯示資訊的詳細程度 - 4或更大值會顯示頭資訊, 3或更大值可以顯示響應代碼(404, 200等), 2或更大值可以顯示警告和其他資訊。 -V 顯示版本号并退出。

    -w              Print out results in HTML tables

    //以HTML表的格式輸出結果。預設時,它是白色背景的兩列寬度的一張表。

    -i              Use HEAD instead of GET

   // 執行HEAD請求,而不是GET。

    -x attributes   String to insert as table attributes

    //

    -y attributes   String to insert as tr attributes

    //

    -z attributes   String to insert as td or th attributes

    //

    -C attribute    Add cookie, eg. 'Apache=1234. (repeatable)

    //-C cookie-name=value 對請求附加一個Cookie:行。 其典型形式是name=value的一個參數對。此參數可以重複。

    -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: xxxx'

                    Inserted after all normal header lines. (repeatable)

    -A attribute    Add Basic WWW Authentication, the attributes

                    are a colon separated username and password.

    -P attribute    Add Basic Proxy Authentication, the attributes

                    are a colon separated username and password.

    //-P proxy-auth-username:password 對一個中轉代理提供BASIC認證信任。使用者名和密碼由一個:隔開,并以base64編碼形式發送。無論伺服器是否需要(即, 是否發送了401認證需求代碼),此字元串都會被發送。

    -X proxy:port   Proxyserver and port number to use

    -V              Print version number and exit

    -k              Use HTTP KeepAlive feature

    -d              Do not show percentiles served table.

    -S              Do not show confidence estimators and warnings.

    -g filename     Output collected data to gnuplot format file.

    -e filename     Output CSV file with percentages served

    -h              Display usage information (this message)

    //-attributes 設定 屬性的字元串. 缺陷程式中有各種靜态聲明的固定長度的緩沖區。另外,對指令行參數、伺服器的響應頭和其他外部輸入的解析也很簡單,這可能會有不良後果。它沒有完整地實作 HTTP/1.x; 僅接受某些'預想'的響應格式。 strstr(3)的頻繁使用可能會帶來性能問題,即, 你可能是在測試ab而不是伺服器的性能。

參數很多,一般我們用 -c 和 -n 參數就可以了. 例如:

./ab -c 1000 -n 1000 http://127.0.0.1/index.php

這個表示同時處理1000個請求并運作1000次index.php檔案.

#/usr/local/xiaobai/apache2054/bin/ab -c 1000 -n 1000 http://127.0.0.1/index.html.zh-cn.gb2312

This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $> apache-2.0

Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/

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

Finished 1000 requests

Server Software:        Apache/2.0.54

//平台apache 版本2.0.54

Server Hostname:        127.0.0.1

//伺服器主機名

Server Port:            80

//伺服器端口

Document Path:          /index.html.zh-cn.gb2312

//測試的頁面文檔

Document Length:        1018 bytes

//文檔大小

Concurrency Level:      1000

//并發數

Time taken for tests:   8.188731 seconds

//整個測試持續的時間

Complete requests:      1000

//完成的請求數量

Failed requests:        0

//失敗的請求數量

Write errors:           0

Total transferred:      1361581 bytes

//整個場景中的網絡傳輸量

HTML transferred:       1055666 bytes

//整個場景中的HTML内容傳輸量

Requests per second:    122.12 [#/sec] (mean)

//大家最關心的名額之一,相當于 LR 中的 每秒事務數 ,後面括号中的 mean 表示這是一個平均值

Time per request:       8188.731 [ms] (mean)

//大家最關心的名額之二,相當于 LR 中的 平均事務響應時間 ,後面括号中的 mean 表示這是一個平均值

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

//每個請求實際運作時間的平均值

Transfer rate:          162.30 [Kbytes/sec] received

//平均每秒網絡上的流量,可以幫助排除是否存在網絡流量過大導緻響應時間延長的問題

Connection Times (ms)

              min mean[+/-sd] median   max

Connect:        4 646 1078.7     89    3291

Processing:   165 992 493.1    938    4712

Waiting:      118 934 480.6    882    4554

Total:        813 1638 1338.9   1093    7785

//網絡上消耗的時間的分解,各項資料的具體算法還不是很清楚

Percentage of the requests served within a certain time (ms)

50%   1093

66%   1247

75%   1373

80%   1493

90%   4061

95%   4398

98%   5608

99%   7368

100%   7785 (longest request)

//整個場景中所有請求的響應情況。在場景中每個請求都有一個響應時間,其中50%的使用者響應時間小于1093 毫秒,60% 的使用者響應時間小于1247 毫秒,最大的響應時間小于7785 毫秒

      由于對于并發請求,cpu實際上并不是同時處理的,而是按照每個請求獲得的時間片逐個輪轉處理的,是以基本上第一個Time per request時間約等于第二個Time per request時間乘以并發請求數

apache使用的一些心得

http://www.chinaunix.net/jh/13/488448.html

freebsd apache

lindowsmatoMacBook-Pro:varnish-3.0.2 root# /usr/sbin/httpd -v

Server version: Apache/2.2.20 (Unix)

Server built:   Sep 12 2011 17:42:56

lindowsmatoMacBook-Pro:varnish-3.0.2 root# whereis httpd

/usr/sbin/httpd

lindowsmatoMacBook-Pro:varnish-3.0.2 root# /usr/sbin/httpd -?

Usage: /usr/sbin/httpd [-D name] [-d directory] [-f file]

                       [-C "directive"] [-c "directive"]

                       [-k start|restart|graceful|graceful-stop|stop]

                       [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S]

Options:

  -D name            : define a name for use in <IfDefine name> directives

  -d directory       : specify an alternate initial ServerRoot

  -f file            : specify an alternate ServerConfigFile

  -C "directive"     : process directive before reading config files

  -c "directive"     : process directive after reading config files

  -e level           : show startup errors of level (see LogLevel)

  -E file            : log startup errors to file

  -v                 : show version number

  -V                 : show compile settings

  -h                 : list available command line options (this page)

  -l                 : list compiled in modules

  -L                 : list available configuration directives

  -t -D DUMP_VHOSTS  : show parsed settings (currently only vhost settings)

  -S                 : a synonym for -t -D DUMP_VHOSTS

  -t -D DUMP_MODULES : show all loaded modules

  -M                 : a synonym for -t -D DUMP_MODULES

  -t                 : run syntax check for config files

  -T                 : start without DocumentRoot(s) check

chkconfig 和 systemctl 指令有什麼異同呢?

http://bbs.csdn.net/topics/390809658

https://fedoraproject.org/wiki/SysVinit_to_Systemd_Cheatsheet/zh

linux中service與chkconfig的替代者systemctl

http://www.111cn.net/sys/linux/65797.htm

http://dl2.iteye.com/upload/attachment/0105/4485/a134f98d-ef7e-3c07-8262-658306075059.png

最近在玩ubuntu和opensuse時發現了systemctl指令了,後來在試玩centos7時也發現了該指令,systemctl是systemd下的一個工具。網上查了下,該指令已經存在很久了。該指令是用來替代service和chkconfig兩個指令的 --- 盡管個人感覺還是後者好用。 為了順應時間的發展,這裡總結下。在目前很多linux的新發行版本裡,系統對于daemon的啟動管理方法不再采用SystemV形式,而是使用了sytemd的架構來管理daemon的啟動。

webServer / Apache / apache / apache http server / mod_cluster
任務 舊指令 新指令
使某服務自動啟動 chkconfig --level 3 httpd on systemctl enable httpd.service
使某服務不自動啟動 chkconfig --level 3 httpd off systemctl disable httpd.service
檢查服務狀态 service httpd status

systemctl status httpd.service (服務詳細資訊)

systemctl is-active httpd.service (僅顯示是否 Active)

加入自定義服務 chkconfig --add  test systemctl   load test.service
删除服務 chkconfig --del  xxx 停掉應用,删除相應的配置檔案
顯示所有已啟動的服務 chkconfig --list systemctl list-units --type=service
啟動某服務 service httpd start systemctl start httpd.service
停止某服務 service httpd stop systemctl stop httpd.service
重新開機某服務 service httpd restart systemctl restart httpd.service

apache webdav / skunkdav-1.0.2.4.jar

配置Apache Basic和Digest認證

http://blog.jobbole.com/41519/

Redhat enterprise liunx 6.4 64bit webdav伺服器安裝

http://blog.sina.com.cn/s/blog_71d9aee40101oe9h.html

Apache2.2開啟WebDav功能

http://my.oschina.net/u/699015/blog/471663

AnyClient_webdav.rar 

https://wiki.archlinux.org/index.php/WebDAV 

3

IIS7.5上的REST服務的Put操作發生HTTP Error 405.0 - Method Not Allowed 解決方法

http://www.cnblogs.com/shanyou/archive/2012/03/23/2414252.html

WebDAV 是超文本傳輸協定 (HTTP) 的一組擴充,為 Internet 上計算機之間的編輯和檔案管理提供了标準.利用這個協定使用者可以通過Web進行遠端的基本檔案操作,如拷貝、移動、删除等。在IIS 7.0中,WebDAV是作為獨立擴充子產品,需要單獨進行下載下傳,而IIS 7.5中将內建WebDAV,然而WebDav把Put,Delete給咔嚓了。是以在IIS 7.5上部署的RESTful服務(WCF Data Service,WCF Rest Service,ASP.NET Web API,ASP.NET MVC)就悲劇了,當發送Put請求就會發生HTTP Error 405.0 – Method  Not Allowed錯誤,解決方法也很簡單,在Web.config裡面加入如下設定:

<system.webServer> 

  <modules> 

    <remove name="WebDAVModule" /> 

  </modules> 

  <handlers> 

    <remove name="WebDAV" /> 

  </handlers> 

</system.webServer>

http://brockallen.com/2012/10/18/cors-iis-and-webdav/

[Fri Dec 18 18:08:00 2015] [error] [client 10.19.95.1] The locks could not be queried for verification against a possible "If:" header.  [500, #0]

[Fri Dec 18 18:08:00 2015] [error] [client 10.19.95.1] Could not open the lock database.  [500, #400]

[Fri Dec 18 18:08:00 2015] [error] [client 10.19.95.1] (13)Permission denied: Could not open property database.  [500, #1]

解決方法:

我司http自定義http版本,端口80有如上異常,原因暫未知,先全部修改8080端口,然後建立使用者davadmin啟動

033-Apache負載不均衡問題 loadblance 

http://wiki.cns*****.com/pages/viewpage.action?pageId=26315529 

1 關于Apache+Jboss+Mysql架構壓測CPU波動問題----短時間大量連接配接

1.1 問題現象

Apache+Jboss+Mysql的架構模式,在壓測過程中發現,幾乎所有的系統都存在應用伺服器CPU波動的情況。

多個嘗試後,發現單壓jboss,CPU還是比較穩定的,

隻有經過Apache分發的,會出現類似問題。

webServer / Apache / apache / apache http server / mod_cluster

             伺服器CPU波動圖

1.2 問題分析

1.2.1  原因要約

通過tcpdump抓包發現,該現象是由于apache的負載不均衡導緻的:在某一時刻請求全部負載給1個機器,在另一時刻,請求負載給另一台機器,使得單台機器CPU發生周期性波動。

webServer / Apache / apache / apache http server / mod_cluster
webServer / Apache / apache / apache http server / mod_cluster

             Tcpdump圖1                                                  Tcpdump圖2

Tcpdump圖1是測試剛開始的情況,此時apache的負載是在2台機器上輪流負載的。

Tcpdump圖2是CPU波動時的情況,此時apache的負載是一段時間集中在1台機器,下一段時間集中的另一台機器。

經過對源碼的debug發現,apache的負載不均衡是由于JBOSS提供的負載子產品mod_proxy_cluster中,權重值參數的更新功能對多程序之間的競争考慮不足引起的。

在高并發模式下,負載均衡算法中2個參數更新發生異常,導緻負載均衡算法異常,後端Jboss伺服器承載不均衡。直接表現為CPU發生定期波動。

1.2.2  原因詳細

子產品mod_proxy_cluster負載均衡的算法

使用了一個權重計算公式:status = lbstatus + (elected - oldelected) * 1000)/lbfactor

其中

Lbstatus

每隔LBstatusRecalTime時間的計算結果

計算公式 (elected - oldelected) * 1000) /lbfactor

Elected

目前時間點,後端節點被選中的次數

Oldelected

上一次計算lbstatus時後端節點被選中的次數

例如:

某時刻T1 時  , 

Status1 =  lbstatus1 + (elected1 – oldelected1) * 1000/ lbfactor

在時刻T2 = T1+LBstatusRecalTime時,需要重新計算lbstatus和Oldelected

    Lbstatus2 = (elected2 – oldelected1)*1000/ lbfactor

    oldelected2 = elected2

在時刻T3 < T1+ 2*LBstatusRecalTime時,

    Status3 = Lbstatus2 + (elected3 - oldelected2) *1000/ lbfactor

每個後端伺服器都有自己的status值,使用者的請求會負載到status值最小的後端伺服器上。

問題發生在T2時刻,當多程序并發時,T2時刻的計算有可能會發生多次!!!

第1次T2時刻計算後,

    Lbstatus2 = (elected2 – oldelected1)*1000/ lbfactor

    oldelected2 = elected2

第2次T2時刻計算後,

    Lbstatus2_2 = (elected2_2 – oldelected2)*1000/ lbfactor

    oldelected2_2 = elected2_2

    這個時刻,負載可能未開始或者剛開始

    是以   elected2_2 等于elected2

              oldelected2等于elected2

              elected2_2等于 oldelected2

    Lbstatus2_2的計算結果等于0

當進入時刻T3,

    status_bug = Lbstatus2_2 +  (elected3 - oldelected2_2) *1000/ lbfactor,

              =  0 +  (elected3 - oldelected2) *1000/ lbfactor

而status_ok =  Lbstatus2 + (elected3 - oldelected2) *1000/ lbfactor

status_bug比status_ok小,是以問題發生後,權重值會比正常時小。

這時,apache就會把請求全部負載給status_bug對應的後端伺服器,直到所有伺服器的負載重新平衡。

在下一次LBstatusRecalTime時,上一輪的負載不均衡會延續到本輪計算!!!

負載均衡的權重計算公式是status = lbstatus + (elected - oldelected) * 1000)/lbfactor

    在上一輪負載較多伺服器,lbstatus會很大,計算後status會很大,

    而上一輪負載較少伺服器,lbstatus會很小,計算後status會很小。

于是apache就會把請求全部負載給上一輪負載較少的伺服器。

Bug現象的不定期發生和apache負載的自平衡一起形成周期性循環。

1.3  解決方法

1.3.1  目前方法:已實施

調整apache配置,

加入 LBstatusRecalTime  1

說明:該功能定期更新負載均衡算法中的2個參數,預設值為5  (秒)

把這個值改成1,是為了在負載不平衡的情況剛發生時,就更新參數,重新計算權重值,

以此達到整體平衡的目的。

1.3.2   最終方法:未實施

考慮加入一把程序鎖,完全解決多程序的競争性問題。

未實施是因為考慮到對apache的代碼了解不夠深入,修改後可能導入性能等其他問題。

1.4 修正效果

與測試部門王強協作,得到以下2個效果圖。

webServer / Apache / apache / apache http server / mod_cluster
webServer / Apache / apache / apache http server / mod_cluster

修正前的CPU情況                                      修正後的CPU情況

從對比結果看,apache負載不均衡引起的CPU的波動問題已得到解決。

-------------------------------------------------------------------------------------------------------------------------------------------------------------

2 Post請求apache負載不均衡問題----長時間少量連接配接

2.1 問題現象

Apache+Jboss在測試過程中發現,一段時間後,大量負載都集中的1-2台Jboss上。

webServer / Apache / apache / apache http server / mod_cluster

2.2  問題分析

2.2.1  原因要約

通過apache的debug日志發現,該現象是由于發包的間隔時間遠大于LBstatusRecalTime的值引起的。

查找關鍵字” proxy: byrequests balancer DONE”,觀察日志:

[Fri Sep 11 16:00:09 2015] [debug] mod_proxy_cluster.c(2221): proxy: byrequests balancer DONE (ajp://10.104.62.33:9109)

[Fri Sep 11 16:00:10 2015] [debug] mod_proxy_cluster.c(2221): proxy: byrequests balancer DONE (ajp://10.104.62.37:9109)

[Fri Sep 11 16:01:00 2015] [debug] mod_proxy_cluster.c(2221): proxy: byrequests balancer DONE (ajp://10.104.62.36:9109)

[Fri Sep 11 16:01:00 2015] [debug] mod_proxy_cluster.c(2221): proxy: byrequests balancer DONE (ajp://10.104.62.37:9009)

[Fri Sep 11 16:01:30 2015] [debug] mod_proxy_cluster.c(2221): proxy: byrequests balancer DONE (ajp://10.104.62.36:9109)

[Fri Sep 11 16:01:45 2015] [debug] mod_proxy_cluster.c(2221): proxy: byrequests balancer DONE (ajp://10.104.62.36:9109)

[Fri Sep 11 16:02:00 2015] [debug] mod_proxy_cluster.c(2221): proxy: byrequests balancer DONE (ajp://10.104.62.36:9109)

[Fri Sep 11 16:02:15 2015] [debug] mod_proxy_cluster.c(2221): proxy: byrequests balancer DONE (ajp://10.104.62.36:9109)

在請求時間間隔比較大的情況下,都是選擇10.104.62.36:9109。

在請求時間間隔比較小的情況下,則會分别選擇不同的機器和端口。

總結:在低并發模式,低請求頻率的場合,從某時刻來看負載時均衡的;從一段時間的總體上來看,負載是不均衡的。

2.2.2  原因詳細

子產品mod_proxy_cluster負載均衡的算法

使用了一個權重計算公式:status = lbstatus + (elected - oldelected) * 1000)/lbfactor

其中

Lbstatus

每隔LBstatusRecalTime時間的計算結果

計算公式 (elected - oldelected) * 1000) /lbfactor

Elected

目前時間點,後端節點被選中的次數

Oldelected

上一次計算lbstatus時後端節點被選中的次數

每個後端jboss的端口都會對應一個自己的status,當新連接配接到來時,apache選擇第一個status值最小的作為負載的jboss。

問題場景,假設LBstatusRecalTime的值是1秒,每5秒1個post請求

在時刻T1

        status0 = lbstatus0 + (elected0 - oldelected0) * 1000)/lbfactor; 

在時刻T1+1,沒有新的post請求

        lbstatus1 = (elected0 - oldelected0) * 1000)/lbfactor

        oldelected1 = elected0

        elected1 = oldelected1 (因為沒有新的post請求,是以沒有變化)

        status1 = lbstatus1 + (elected1 - oldelected1) * 1000)/lbfactor; 

                    = (elected0 - oldelected0) * 1000)/lbfactor + 0

在時刻T1+2,沒有新的post請求

        lbstatus2 = (elected1 - oldelected1) * 1000)/lbfactor

                      =  0

        oldelected2 = elected2 = elected0

status2 = lbstatus2 + (elected2 - oldelected2)* 1000/lbfactor

                    = 0

在時刻T1+3,沒有新的post請求,status3 = 0

在時刻T1+4,沒有新的post請求,status4 = 0

在時刻T1+5,新的post請求到來,

        此時所有的jboss的status都是0,于是,就會選擇後端清單裡第1個jboss

然後把elected加1

        如果在T1+5時刻,還有其他post請求到來,會選擇後端清單裡第2個jboss

               第1個jboss的status = 1000/lbfactor

               第2個jboss的status = 0

如果在T1+5時刻,沒有其他post請求,就會變成時刻T1的狀态,繼續循環。

2.3 解決方法

2.3.1  目前方法:已測試

調整apache配置,

加入 LBstatusRecalTime  1200

說明:該功能定期更新負載均衡算法中的2個參數,預設值為5  (秒)

把這個值改成1200,是為了降低算法的執行頻率,使請求到達的間隔時間低于算法執行的間隔時間,以此達到整體平衡的目的。

2.4 修正效果

webServer / Apache / apache / apache http server / mod_cluster

2.5 備注

該問題與實際通路頻率相關,不應歸于bug,可以不做修改。

-------------------------------------------------------------------------------------------------------------------------------------------------------------

使用mod_cluster進行負載均衡初步預研

http://pengtyao.iteye.com/blog/794855

http://docs.jboss.org/mod_cluster/1.3.0/html/

http://mod-cluster.jboss.org/mod_cluster/downloads/1-3-1-Final-bin

http://docs.jboss.org/mod_cluster/1.3.0/pdf/Mod_cluster-UserGuide.pdf

Apache web伺服器擴容 / WildFly應用伺服器擴容 mod_cluster

http://wiki.cns*****.com/pages/viewpage.action?pageId=18678515 

WildFly-Mod_Cluster配置.docx

http://wiki.cns*****.com/pages/viewpage.action?pageId=16614107

http://wiki.cns*****.com/download/attachments/16614107/WildFly-Mod_Cluster%E9%85%8D%E7%BD%AE.docx

問題現象1:apache modcluster叢集有單台apache響應時間異常

運費系統FIMS發現apache叢集中一台apache某個點逾時很多,檢視apache日志描述是子線程有處理異常的連接配接不能釋放 然後被殺 重新起一個新線程 為什麼會産生這種情況,不清楚,他建議重新開機這台apache。

webServer / Apache / apache / apache http server / mod_cluster

查找方案:bug 2.2.x版本已經修複,apache叢集+jboss叢集,apache modcluster 路由jboss叢集機器重新整理新舊節點問題已經修複。現象和apache官方的bug 43857一樣。

https://bz.apache.org/bugzilla/show_bug.cgi?id=43857 

When a prefork child exits (either graceful, or chosen as an idle child to die)
- the last request's pool is not cleared.

Server pool cleanups can depend on request pool cleanups having been run.  An
example is APR reslist.  If the last request acquired a resource, relist cleanup
will fail an assertion:

  httpd: misc/apr_reslist.c:157: reslist_cleanup: Assertion `rl->ntotal == 0'
failed.
  [Wed Nov 14 10:44:02 2007] [notice] child pid 7491 exit signal Aborted (6)      
Index: server/mpm/prefork/prefork.c
===================================================================
--- server/mpm/prefork/prefork.c	(revision 593523)
+++ server/mpm/prefork/prefork.c	(working copy)
@@ -637,6 +637,7 @@
             die_now = 1;
         }
     }
+    apr_pool_clear(ptrans);
     clean_child_exit(0);
 }
       

解決方案:

webServer / Apache / apache / apache http server / mod_cluster

運費系統apache子線程退出問題原因查明,該jboss叢集node名稱做過變更,聯合的apache(modcluster)服務沒有重新開機,導緻舊node節點在apache中的路由資訊依然存在(如上圖),觸發apache(modcluster) bug.

建議波浪重新開機該叢集的所有apache伺服器,重新整理路由資訊。

end