Skip to content


ncache试用

NCACHE 是基于 NGINX 的 WEB 服务器模型构件起来的缓存系统, 是SINA公司的开源产品.

起初的目的是为了提升缓存响应速度而开发的,因为SQUID实在比较慢, 而NGINX的优势就在于网络服务上,所以NCACHE计划也就诞生了.

NCACHE最早的时候是作为NGINX的一个HTTP模块进行开发的,因为当时希望做到更好的兼容性和可扩展性,作为独立模块,可以被更好的推广和使用,安装也会很方便.但后来发现随着代码量的增加,功能的扩充,NGINX的原有模块框架已经不能很好的满足我们了,因此,我们提取了NGINX的内核代码,并把CACHE部分欠入其中,形成了今天的NCACHE

NCACHE本身功能并不强大,且不具备像SQUID般完善的功能和开发框架,甚至不能支持RFC中关于CACHE部分的描述. NCACHE完全是一套定制化的产品,可以满足像我们一样需要快速部署,简单易用,大并发量,大存储量的朋友们的需求,它不需要复杂的配置,不需要冗余的复杂代码,并使用最先进的技术组合.

NCACHE 2.0版本,是作为一个完整的NGINX 模块进行发布和使用的,从原有的NCACHE内核中进行了剥离,更方便开发者的安装和配置

http://code.google.com/p/ncache/

下载后重新编译nginx

配制文件检查无错; 生成cache目录; nginx在80,使用apache在8080做后台; 产生max-age;

time_count:1583 request_count:29 shoot_count:0 disk_writes:4 store_files:10 upstream_count:2 free_index:16777215

Posted in Nginx, 技术.

Tagged with , .


让nginx的expires和防盗链都有效

expires有效,防盗链失效  <code>    
             location ~* ^.+\.(jpg|jpeg|gif|png|css|js|swf)$ {
             access_log   off;
             root /opt/htdocs/career;
     expires 1h;
     #break;
     }

     location ~* ^.+\.(jpg|jpeg|gif|png|swf|rar|zip)$ {
    valid_referers none blocked *.c1gstudio.com;
    if ($invalid_referer) {
        rewrite ^/ http://leech.c1gstudio.com/leech.gif;
        return 412;
    }
     }

只有js和css的expire有效,防盗链有效 location ~<em> ^.+.(jpg|jpeg|gif|png|swf|rar|zip)$ { valid_referers none blocked </em>.c1gstudio.com; if ($invalid_referer) { rewrite ^/ <a href="http://leech.c1gstudio.com/leech.gif">http://leech.c1gstudio.com/leech.gif</a>; return 412; } } location ~* ^.+.(jpg|jpeg|gif|png|css|js|swf)$ { access_log off; root /opt/htdocs/career; expires 1h; #break; }</p> <p>

让expire和防盗链都有效 <br /> location ~<em> ^.+.(jpg|jpeg|gif|png|swf|rar|zip|css|js)$ { valid_referers none blocked </em>.c1gstudio.com; if ($invalid_referer) { rewrite ^/ <a href="http://leech.c1gstudio.com/leech.gif">http://leech.c1gstudio.com/leech.gif</a>; return 412; } access_log off; root /opt/htdocs/career; expires 1h; break;</p> <pre><code> }

Posted in Nginx, 技术.

Tagged with , , .


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 , .