« 新的初中同学录 | 首 页 | [ZT] find 等命令的活用 »

2004 年 07 月 13 日

apache 速度爆慢的问题:MAX CLIENT 和 百度mp3搜索引擎

| 分类: 服务器日志 Server Log |

今天出现了apache打开速度爆慢的问题。检查如下:

ping 的平均时间为 69 ms find /-ctime 1 没有什么大的变动 netstat -anlp | grep 80 | grep tcp | awk {'print $5'} | awk -F: {'print $1'}| sort |uniq -c | sort -nr 有将近145个httpd 的链接, 前几个的每个ip的连接数目都在 10-15左右。

升级apache到2.0.50

$ ./configure --enable-so --enable-speling --enable-rewrite --enable-ssl --with-ssl=/usr/local/ssl
$ make
$ apachectl stop
$ make install
$ apachectl start

问题依然存在。 查看last 和 apache的log文件,并用SSS扫描主机,未发现侵入和漏洞。于是搜索CU上的问题,发现了这个帖子,根据里面的解释,可能是由于我的服务器的virtual hosts在不停地增加,而正常连接数目在不停地增大,而httpd.conf里面没有恰当设置 MAX CLIENT 造成的。

修改了 httpd.conf 里面的 MAX CLIENT 为 256,问题解决!

如果你要继续增加 MAX CLIENT 的数量,请见全文。
推荐阅读 :RFC2616
apache 速度爆慢的问题:MAX CLIENT 和 百度mp3搜索引擎
感谢 HonestQiao

当你将 MAX CLIENT 设置为超过256的时候,会出现

WARNING: MaxClients of 1250 exceeds ServerLimit value of 256 servers,
lowering MaxClients to 256. To increase, please see the ServerLimit
directive.

的错误。

查看prefork 的相关说明,将idle的进程减少了。
(因为在我的 # apachectl -l 只有 prefork.c

MaxSpareServers 6

追究原因 百度的 mp3 搜索器搞的鬼

210.54.49.45 - - [13/Jul/2004:13:37:23 +0800] "GET /archives/images/jiangnan.mp3 HTTP/1.1" 206 "http://list.mp3.baidu.com/topso/9/984_tsomp3.htm" "Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)"
原来是我的“江南”这首歌,被百度搜索到,不停的被下载。而且就是今天的事情。 查看流量日志
2004年 七月 12 21 40 149 228.94 M字节 2004年 七月 13 17 25 8821 50.78 G字节

所以利用阻止图片盗链的方法,在apache里面设置。

######## Preventing Image 'Theft' ######## ## http://apache-server.com/tutorials/ATimage-theft.html

# Images can only be fetched if they were linked to from one of your pages.
# local_ref=1 ==> forbidden

SetEnvIfNoCase Referer "fjhr\.org" !local_ref
SetEnvIfNoCase Referer "hzmjp\.com" !local_ref
SetEnvIfNoCase Referer "dalouis\.com" !local_ref
SetEnvIfNoCase Referer "necktie\.gov\.cn" !local_ref
SetEnvIfNoCase Referer "necktie\.net\.cn" !local_ref
SetEnvIfNoCase Referer "hzboxing\.com" !local_ref
SetEnvIfNoCase Referer "-" !local_ref

SetEnvIf Request_URI "/images/logo(.)+" local_ref
SetEnvIf Request_URI "/images/snap(.)+" local_ref
SetEnvIf Request_URI "/images/close(.)+" local_ref
SetEnvIf Request_URI "/favicon.ico" local_ref
SetEnvIf Request_URI "matrix.jpg" local_ref

# Agree to download at mediaplayer
BrowserMatch "RealMedia" local_ref

<FilesMatch "\.(png|gif|jpg|mp3|wma)">
Order Allow,Deny
Allow from env=local_ref
</FilesMatch>

重启apache以后立刻速度爆增!

[Tue Jul 13 13:40:54 2004] [error] [client 61.176.103.33] client denied by server configuration: /home/kreny/mt/weblog/archives/images/jiangnan.mp3, referer: http://list.mp3.baidu.com/topso/9/984_tsomp3.htm

但是发现情况并没有好转:请看如下记录。

218.31.243.201 - - [14/Jul/2004:18:48:15 +0800] "GET /archives/images/jiangnan.mp3 HTTP/1.1" 206 623094 "http://mp3.baidu.com/m?tn=baidump3&ct=134217728&rn=&word=%BD%AD%C4%CF+%C1%D6%BF%A1%BD%DC&lm=-1" "Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)"

206代码表示获取部分数据。这就有可能是类似于flashget或者netants的分块下载。查看了flashget,发现里面有“发送引用页”这个部分,可以欺骗服务器的reffer (可恶~)。 所以使用了 BrowserMatch 来限制下载mp3的浏览器类型。 比如 mediaplayer 和 realplayer。这样就可以阻止类似于 flashget的下载。 (当然,你也可以填写代理以适应我的服务器要求,不过,没那么多人为了一首歌会搞的这么复杂吧?嘿嘿~) 以下是代码(里面的match内容不是真实的噢~)。

# Agree to play by mediaplayer or mediaplayer
BrowserMatch "RealPlayer" local_media=0
BrowserMatch "MediaPlayer" local_media=0
<FilesMatch "\.(mp3|wma)">
Order Deny,Allow
Deny from all
Allow from env=local_media
</FilesMatch>

如果要减轻log文件的记录量,我们可以分离从百度来的referer,在你的virtual host里面做以下设置:

SetEnvIf Referer "baidu\.com" baidu_ref=0
CustomLog logs/weblog.kreny.com-access_log combined env=!baidu_ref
CustomLog logs/poachers_log combined env=baidu_ref

注意:不能单纯地设置 !baidu_ref,而要用 baidu_ref=0 或者 baidu_ref=1 来设置。

终结方法制止直接下载:

# If client use the Mozilla or Non-media explorer to download, then redirect
# to a unavaluable file to response a 404(Not Found) error. ;)
# This rule is not effective when it is written in TOP part(www.dalouis.com)
RewriteCond %{HTTP_USER_AGENT} Mozilla|Flashget|Netants|Lynx
RewriteRule .mp3$ /HTTP_NOT_FOUND.html [L]

结果:在直接输入 mp3 地址后的 log 文件:
221.95.221.22 - - [16/Jul/2004:10:48:53 +0800] "GET /archives/images/queen_2004.mp3 HTTP/1.1" 404 370 "http://weblog.kreny.com/archives/images" "Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)" [Fri Jul 16 10:48:53 2004] [error] [client 221.95.221.22] File does not exist: /home/kreny/mt/weblog/HTTP_NOT_FOUND.html-, referer: http://weblog.kreny.com/archives/images
转向了首页。若改为一个不存在的页面,则可以response一个404错误了。注意:rewrite必须写在每个virtual hosts 才有效!


最后设置 robot.txt 了

User-agent: * Disallow: /cgi-bin Disallow: /archives/images
(END)

引用

引用本文的 URL:
http://weblog.kreny.com/cgi-bin/mt/mt-tb.cgi/103.

以下是参考 apache 速度爆慢的问题:MAX CLIENT 和 百度mp3搜索引擎 的 blog 链接:

» 无聊的牢骚 的 apache 速度爆慢的问题:MAX CLIENT 和 百度mp3搜索引擎
今天出现了apache打开速度爆慢的问题。检查如下:ping 的平均时间为 69 ms find /-ctime 1 没有什么大的变动 netstat -anlp &line; grep 80 &line; grep tcp &line; .. [Read More]

发表评论

(如果您还为在此成功留言,也许是因为需要管理员逐一审核留言内容后放可看到您的评论。请稍后并感谢您的耐心等待。)

阅览更多文章请访问 首页过去的存档