Skip to content


nginx应用日三百万pv记录

使用nginx架构的php应用负载5以下达到了日pv三百五十万,平均连接数六千多,并且保持了不错的响应速度。 具体安装: nginx+php(FCGI)+xcache+mysql on as4

以下为awstats一天的详细统计数据

广告系统(简单php+js)

  参观者 参观人次 网页数 文件数 字节
浏览器流量 * 96823   130818 (1.35 参观人次/参观者) 713865 (5.45 网页数/参观) 7163660 (54.76 文件数/参观) 763.43 M字节 (5.97 K字节/参观)
非浏览器流量 *     7471 11096 1.01 M字节

sns(一般复杂php+mysql)

  参观者 参观人次 网页数 文件数 字节
浏览器流量 * 30300   35773 (1.18 参观人次/参观者) 102488 (2.86 网页数/参观) 339758 (9.49 文件数/参观) 574.38 M字节 (16.44 K字节/参观)
非浏览器流量 *     180110 2558206 2.84 G字节

文章(简单php+mysql)

  参观者 参观人次 网页数 文件数 字节
浏览器流量 * 23168   29433 (1.27 参观人次/参观者) 135918 (4.61 网页数/参观) 475899 (16.16 文件数/参观) 1.17 G字节 (41.81 K字节/参观)
非浏览器流量 *     16498 20887 87.61 M字节

discuz6(php+mysql)

  参观者 参观人次 网页数 文件数 字节
浏览器流量 * 81182   118632 (1.46 参观人次/参观者) 2568752 (21.65 网页数/参观) 10408084 (87.73 文件数/参观) 26.48 G字节 (234.05 K字节/参观)
非浏览器流量 *     189089 209570 5.89 G字节

一般复杂php+mysql

  参观者 参观人次 网页数 文件数 字节
浏览器流量 * 2908   3455 (1.18 参观人次/参观者) 11183 (3.23 网页数/参观) 30527 (8.83 文件数/参观) 52.70 M字节 (15.61 K字节/参观)
非浏览器流量 *     1645 1663 3.24 M字节

商店(简单php+mysql)

  参观者 参观人次 网页数 文件数 字节
浏览器流量 * 2286   2612 (1.14 参观人次/参观者) 7829 (2.99 网页数/参观) 78226 (29.94 文件数/参观) 859.63 M字节 (337 K字节/参观)
非浏览器流量 *     437 477 1.38 M字节

软件 os:as4 app:nginx 0.62+php5.26(fcgi)+mysql5.16+xcache+postfix nginx:4

keepalive_timeout 60

phpcgi:50 mysql:

key_buffer_size = 160M
query_cache_size = 64M
query_cache_limit = 2M #default=1M
query_cache_min_res_unit = 2k #default=4K

max_allowed_packet = 16M
table_cache = 768

tmp_table_size = 128M #default=16M
max_heap_table_size = 128M #default=16M

read_buffer_size = 2M
read_rnd_buffer_size = 8M

sort_buffer_size = 32M
join_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 80 #default=0
thread_stack = 192K #default=192K

thread_concurrency = 8 #default=10
max_connection = 100
max_connect_errors = 100
wait_timeout = 10

硬件 cpu :2颗双核至强 1.60GHz mem:1G2 harddisk:scsi 74G1

负载 主要应用为discuz ,六十万会员,每日1.5万贴,db大小为三百多兆,其中php的javascript缓存占了大部分。 论坛平均一小时在线五千多人,高峰为七千.

nginx status
Active connections: 6845
server accepts handled requests
 14859839 14859839 56220725
Reading: 12 Writing: 15 Waiting: 6818
高峰时同时连接达八千多

top(高峰时load可达十几)

top - 14:45:37 up 35 days, 21:51,  1 user,  load average: 3.82, 3.78, 
Tasks: 202 total,   1 running, 201 sleeping,   0 stopped,   0 zombie
Cpu(s): 21.6% us,  4.1% sy,  0.0% ni, 70.5% id,  3.7% wa,  0.1% hi,  0
Mem:   2073976k total,  1985372k used,    88604k free,    83884k buffe
Swap:  2040244k total,     4336k used,  2035908k free,  1267284k cache
 
 

mysql统计

服务器已经运行了 0 天 2 小时,23 分 55 秒
连接   ø 每小时   %
max. concurrent connections  65  ---  ---
尝试失败  46  18.55  0.02%(firefox每次刷新都会加2,不明白)
中止  1,699  685.08  0.83%
统计  206 k  82.97 k  100.00%
2008-10-10
去掉广告系统。
修改expire增加到3天,来降低http连接(参考discuz.net的10天)
日志不记录图片的请求
效果:Active connections降低一半多。负载降低了四分之一左右。
论坛共 7196 人在线 - 最高记录是 110122008-10-12.
Active connections: 3195
server accepts handled requests
 495784 495784 1917665
Reading: 16 Writing: 35 Waiting: 3144
top - 10:55:43 up 39 days, 18:01,  1 user,  load average: 2.89, 3.06, 
Tasks: 174 total,   1 running, 173 sleeping,   0 stopped,   0 zombie
Cpu(s): 23.6% us,  4.2% sy,  0.0% ni, 63.7% id,  8.5% wa,  0.1% hi,  0
Mem:   2073976k total,  1958516k used,   115460k free,   117848k buffe
Swap:  2040244k total,      188k used,  2040056k free,  1313148k cache

============================== 2009-11-13 更新 目前使用两台dell R410,每日负载一千万pv左右 55042,4G2,sas15K 146*2 centos 5.2(64bit)

server a:discuz 每日四百万pv,一小时在线总计17620,最高记录23167 server b:静态页网站 每日六百万pv 同时做discuz的db

Posted in Nginx, 其它, 分析报告, 技术.

Tagged with .


linux swap大小

mem 2G, mem 8G, swap=8G

不装oracle时2Gswap就可以了

Posted in LINUX, 技术.

Tagged with , .


关闭631端口cups打印服务和8009端口ajp

用nmap扫了下服务器发现631端口是打开的。

631/tcp open ipp

//先检查下 #ps aux|grep cups

//关闭服务 #service cups stop

//查看自启动 #chkconfig –list cups cups            0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭

//关闭自启动服务 #chkconfig –level 2345 cups off

//再检查下 #chkconfig –list cups cups            0:关闭  1:关闭  2:关闭  3:关闭  4:关闭  5:关闭  6:关闭

============================我是分割线===================

8009/tcp  open     ajp13

8009端口是tomcat和apache的mod_proxy_ajp,mod_jk沟通的端口,我这里apache纯做代理所以可以关闭。

tomcatpath/conf/server.xml 中的这段注释掉  <!–         –>

重启tomcat

收工~

Posted in linux 维护优化, Tomcat, 安全, 技术.

Tagged with , , , .


nginx下j_space人才系统rewrite

系统设置为“完整格式” 如: http://www.wjob.com.cn/index.php/index.html

             location ~ .*\.php?$              {                   #fastcgi_pass  unix:/tmp/php-cgi.sock;                   fastcgi_pass  127.0.0.1:9000;                   fastcgi_index index.php;                   include fcgi.conf;                   }              location ~* ^/index.php/              {     rewrite ^/index.php/(.*) /index.php?$1 break;                   fastcgi_pass  127.0.0.1:9000;                   fastcgi_index index.php;                   include fcgi.conf;              }

Posted in Nginx, 技术.

Tagged with , , .


awstats按日产生统计报表

修改wwwroot/cgi-bin/awstats.pl 

7851行增加日期下拉框

[code]     print “<select class=\"awsformfield\” name=\”day\”>\n”;     foreach (1..31) {      my $dayix=sprintf(“%02s”,$);      print “$dayix\n”;     }     print “\n”; [/code]

7871行增加databasebreak参数

[code]     if ($DatabaseBreak) { print “\n”; } [/code]

命令行统计增加:-databasebreak=day

查看报表时地址栏需增加:&databasebreak=day&day=DD

以下为查看页代码  [code]

    var   d   =   new   Date();    d.setTime(d.setDate(d.getDate()-1));    var day=d.getDate();  

 var srv = new Array();

 srv[0]=’www.c1gstudio.com’;  srv[1]=’bbs.c1gstudio.com’;  srv[2]=’blog.c1gstudio.com’;  srv[3]=’admin.c1gstudio.com’;

 for (var i=0;i<srv.length ;i++ )  {  document.writeln('

<a href="http://admin.c1gstudio.com/cgi-bin/awstats.pl?config=’+srv[i]+’&databasebreak=day&day=’+day+'” target=”_blank”>http://admin.c1gstudio.com/cgi-bin/awstats.pl?config=’+srv[i]+'</a></p&gt;’);  }  document.writeln(‘


‘); [/code]

参考: http://blogger.org.cn/blog/more.asp?name=chenjiejacky&id=20464 http://www.chedong.com/blog/archives/001293.html#more

Posted in linux 维护优化, 技术.

Tagged with , .


apache log中的 Apache (internal dummy connection)

 

#tail logs/access_log

:1 – – [18/Sep/2008:13:56:34 +0800] “GET / HTTP/1.0” 200 843 “-” “Apache (internal dummy connection)”

:1 – – [18/Sep/2008:13:56:34 +0800] “GET / HTTP/1.0” 200 843 “-” “Apache (internal dummy connection)”
:1 – – [18/Sep/2008:13:56:34 +0800] “GET / HTTP/1.0” 200 843 “-” “Apache (internal dummy connection)”
:1 – – [18/Sep/2008:13:56:34 +0800] “GET / HTTP/1.0” 200 843 “-” “Apache (internal dummy connection)”
:1 – – [18/Sep/2008:13:56:34 +0800] “GET / HTTP/1.0” 200 843 “-” “Apache (internal dummy connection)”

修改httpd.conf

    SetEnvIf Remote_Addr “::1” dontlog     CustomLog logs/access_log combined  env=!dontlog

Posted in Apache, 技术.

Tagged with , .


editplus小技巧:正则替换 html中的标签

举例有html内容如下

abc abc abc

需将中的内容清空. 用editplus打开,shift+H. 查找内容:]* 替换内容:<td 勾上使用正则表达式 解释:查找以““的行

也可以这样 查找内容:<td(.)>(.) 替换内容:\2 解释:查找以“<td”开始,以结束,中间以”>”分成两段,最出只输出第二段。

Posted in Tools, 其它.

Tagged with , .


nginx 目录自动加斜线”/”

 

默认配置当你访问http://abc.example.com/dir 时不会加”/”

常见做法

      if (-d $request_filename){   rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;       }

更佳的替代方法

optimize_server_names off;#优化服务器名称:关 server_name_in_redirect off;#服务器名称重定向:关

http://wiki.codemongers.com/NginxHttpCoreModule#optimize_server_names

Posted in Nginx, 技术.

Tagged with , .


nginx 使用ip和密码保护你的目录

 

apache限制ip方法

documentroot “/opt/htdocs/www/” servername admin.c1gstudio.com     Options IncludesNoExec FollowSymLinks     AllowOverride None     Order deny,allow     Deny from all     Allow from 127.0.0.1 222.222.222.222 111.111.111.111

使用ngx_http_access_module限制ip访问

官方示例 http://wiki.codemongers.com/NginxHttpAccessModule#allow

location / {     deny    192.168.1.1;     allow   192.168.1.0/24;     allow   10.1.1.0/16;     deny    all; }

改成自已的

location / {     allow   127.0.0.1;     allow   222.222.222.222;#服务器ip     allow   111.111.111.111;#自已电脑的ip     deny    all; }              location ~ .*\.php?$              {                   #fastcgi_pass  unix:/tmp/php-cgi.sock;                   fastcgi_pass  127.0.0.1:9000;                   fastcgi_index index.php;                   include fcgi.conf;                   }       location ~ ^/cgi-bin/.*\.pl$ {     auth_basic “Restricted”;     auth_basic_user_file htpasswd;     gzip off; #gzip makes scripts feel slower since they have to complete before getting gzipped     include awstats.conf;       }              location ^~ /nginx {                   stub_status on;                   access_log   off;     auth_basic “NginxStatus”;     auth_basic_user_file htpasswd;              }              location ~ ^/memcached {                   access_log   off;     auth_basic “NginxStatus”;     auth_basic_user_file htpasswd;              }

结果:测试下来非定义的ip还是可以访问。

再修改下正则

location ^~ / {     allow   127.0.0.1;     allow   222.222.222.222;#服务器ip     allow   111.111.111.111;#自已电脑的ip     deny    all; }

结果:非定义的是ip不可以访问了,但php变明文显示,perl是404。

 

你可以看看 nginx 的文档里面关于 location 的说明。它的匹配方式是 正则表达式 优先级比较高。 就是说,你的 PHP 解析用的是 正则表达式进行匹配,而你要限制的目录不是用正则表达式,所以,就算是要限制的目录,因为PHP还是能被匹配到,所以,还是解析PHP了。所以,如果想解决的话,可能需要把目录也写成正则匹配,而且要放在PHP的前面,否则就会先匹配PHP     

   satisfy_any on;

http://www.freebsdchina.org/forum/viewtopic.php?t=42141

使用多级目录将保护目录放在根中

location / {     #allow   127.0.0.1;     #allow   222.222.222.222;#服务器ip     allow   111.111.111.111;#自已电脑的ip     deny    all;              location ~ .*\.php?$              {                   #fastcgi_pass  unix:/tmp/php-cgi.sock;                   fastcgi_pass  127.0.0.1:9000;                   fastcgi_index index.php;                   include fcgi.conf;                   }       location ~ ^/cgi-bin/.*\.pl$ {     auth_basic “Restricted”;     auth_basic_user_file htpasswd;     gzip off; #gzip makes scripts feel slower since they have to complete before getting gzipped     include awstats.conf;       }              location ^~ /nginx {                   stub_status on;                   access_log   off;     auth_basic “NginxStatus”;     auth_basic_user_file htpasswd;              }              location ~ ^/memcached {                   access_log   off;     auth_basic “NginxStatus”;     auth_basic_user_file htpasswd;              } }

结果:有效

整个域名需禁止访问可以写在server中

server { listion 80; server_name admin.c1gstudio.com; root /opt/htdocs/www; allow   111.111.111.111;#自已电脑的ip deny    all; auth_basic “Nginx_Panel”; auth_basic_user_file htpasswd; location ~ .*\.php?$ { …. }  location ^~ /phpmyadmin {   satisfy any;        access_log   off;        location ~ .*\.php?$        {      #fastcgi_pass  unix:/tmp/php-cgi.sock;      fastcgi_pass  127.0.0.1:9000;      fastcgi_index index.php;      include fcgi.conf;             } } location ^~ /memcached {   satisfy any;        access_log   off;        location ~ .*\.php?$        {      #fastcgi_pass  unix:/tmp/php-cgi.sock;      fastcgi_pass  127.0.0.1:9000;      fastcgi_index index.php;      include fcgi.conf;             } } }

参考:http://marc.info/?l=nginx&m=120127282911304&w=2

Posted in Apache, Nginx, 安全, 技术.

Tagged with , , , , .


静态html用js取中文参数,无乱码

 

     String.prototype.getQueryString   =   function(name)     {         var   reg   =   new   RegExp(“(^|&|\?)”+   name   +”=([^&]*)(&|$)”),   r;         if   (r=this.match(reg))   return   unescape(r[2]);   return   null;     };                var msg=window.location.href.getQueryString(“msg”);      if (msg)      {      document.write(‘

  • · ’+msg+’
  • ‘);      }      

    在ff下中文会乱码,参数传递过来时需先escape();

    function phpescape($str){     preg_match_all(“/[\x80-\xff].|[\x01-\x7f]+/”,$str,$newstr);     $ar = $newstr[0];     foreach($ar as $k=>$v){         if(ord($ar[$k])>=127){             $tmpString=bin2hex(iconv(“GBK”,”ucs-2″,$v));             if (!eregi(“WIN”,PHP_OS)){                 $tmpString = substr($tmpString,2,2).substr($tmpString,0,2);             }             $reString.=”%u”.$tmpString;         } else {             $reString.= rawurlencode($v);         }     }     return $reString; }

     

    参考:

    PHP实现Javascript的escape(),unescape()的方法

    Firefox自动对url中的中文进行编码导致乱码

    Posted in JavaScript/DOM/XML.

    Tagged with , , , , .