前段时间弄了mrtg的监控和AWStats 的日志处理,并和nginx状态、xcache状态、mysql管理等整合到了一起,通过status.k12zy.com来访问。
因为nginx状态是文字的没什么直观性,看到有弄成图形化的统计很直观,试着做了下,效果还不错。
首先下载pl文件,rrd_nginx.pl.txt,将其txt扩展名去掉修改如下部分。
#!/usr/bin/perl
use RRDs;
use LWP::UserAgent;
# define location of rrdtool databases
my $rrd = ‘/opt/rrd';
# define location of images
my $img = ‘/opt/rrd/html';
# define your nginx stats URL
my $URL = http://your-domain.com/nginx_status;
另外安装rrdtool,我在centos里通过三方的yum安装的rrdtool,和perl的rrd的模块。
然后定义cron自动运行,其实这个pl里面有两个内容一个是获取nginx的文本状态信息并存到rrd的数据,然后生成图片,所以可以把这两个内容分开比如每5分钟获取一次数据,一个小时生成一次图片节省系统资源,但是实际运行看来差别不大。
下面是效果图。 阅读全文…
billy linux, 我的网站 nginx, perl, rrdtool
原来是用的 NginxHttpAccessKeyModule 这个nginx的插件,效果可以,但是对下载控制有些吃力,比如下载次数或之前的下载减分等都不太好做,近来发现了个方法,还是延续之前通过动态程序读取文件内容再转发给用的的方法,但是读取文件内容的工作就从动态程序转到的web服务器,对动态程序的性能是一个极大的解放。
很多服务器都有这个功能,apache可以通过外部mod来实现。
lighttpd X-Sendfile
nginx X-Accel-Redirect
我用的是nginx具体实现方法
nginx conf
location /down{
internal;
alias /www/down;
}
internal为允许nginx读取文件内容,但是外部无法访问
php内
< ?php
// Get requested file name
$path = $_GET[“path”];
//所有你需要在下载前做的东西
header(“X-Accel-Redirect: /down/” . $path);
?>
参考:http://blog.kovyrin.net/2006/11/01/nginx-x-accel-redirect-php-rails/lang/en/
billy linux, 我的网站 nginx
AWStats 以前用过,因为现在用了nginx服务器,nginx对perl支持不是太好用不想多开个apache来浪费资源,后来觉得直接在每天更新时生成静态页然后nginx里直接建个目录浏览就好了。也是一个解决办法。
awstats_buildstaticpages.pl 文件在awstats内的tools文件夹内。
/var/www/cgi-bin/awstats_buildstaticpages.pl -update -config=down -dir=/www/status/awstats/down/ -awstatsprog=/var/www/cgi-bin/awstats.pl -lang=cn
命令行统计增加: -databasebreak=day
报表输出时增加: &databasebreak=day&day=DD
即可按天进行统计, 解决按月统计,归档数据过大导致统计过慢/失败的问题。
在配置文件内加上搜索引擎的具体抓取页面–引自车东的blog
http://www.chedong.com/blog/archives/001200.html 阅读全文…
billy linux, 计算技术 awstats, nginx
nginx
定义错误页面 error_page 404 http://www.k12zy.com;
限速 limit_rate 20k;
虚拟目录 alias /export/file/cn/;
linux
mount windows共享服务: mount -t cifs -o username=***,password=*** //192.168.16.10/e$ /export/ss/
lftp mirror: mirror -c –parallel=5 cn /export/file/
mirror [OPTS] [remote [local]]
下載整個目錄(樓上的 get 只能用來抓檔案)
-c 續傳
-e 這個要小心一些, 比較遠端和本地端的檔案, 假如遠端沒有的, 就將本地端的檔案刪除, 也就是將本地端和遠端資料同步。
-R 上傳整個目錄
-n 只下載較新的檔案
-r 不用遞迴到目錄中
–parallel=n 同時下載 n 個檔案(預設一次只下載一個)
samba中文乱码
vi /etc/samba/smb.conf
根据locales的设置,修改该文件:
1. 如果locale是zh_CN.UTF-8,做如下设置:
display charset = UTF-8
unix charset = UTF-8
dos charset = UTF-8
2. 如果locale是zh_CN.GBK或zh_CN.gb2312,做如下设置:
display charset = cp936
unix charset = cp936
dos charset = cp936
重启samba:
service samba restart
则无论从windows的网上邻居,还是直接用securecrt登陆,均可显示正常中文。
批量改文件名
在当前目录下执行 find . -name “*.zip” | while read file; do mv $file $(echo $file|sed s/zip$/rar/g); done
billy 备忘录 linux, mysql, nginx
按照官方配置安装后都会出现错误,看了半天源码又在网上转了一圈找到了一个补丁,又出现编译错误,修改了源码才完成编译,试了一下功能很好用。
http://www.ieesee.net:8080/~uingei/nginx-accesskey-2.0.3.diff.bz2
下载上面的补丁文件,进入nginx的目录然后执行:
bzcat ../nginx-accesskey-2.0.3.diff.bz2 | patch -p1
/configure –with-http_accesskey_module …
make
make install
我使用的是centos,编译时提示有未使用的变量 clcf,打开源码将 ngx_http_core_loc_conf_t *clcf; 这句删掉,然后编译通过。
我配置的0.6.33 也没有问题
billy 我的网站 nginx
安装后我进行了测试以下为测试结果
分别开启关闭xcache 运行两次ab -n 1000 http://bbs.k12zy.com/forum-19-1.html
Server Software: nginx/0.6.33
Server Hostname: bbs.k12zy.com
Server Port: 80
Document Path: /forum-19-1.html
Document Length: 32118 bytes
Time taken for tests: 38.976547 seconds
Requests per second: 25.66 [#/sec] (mean)
Time per request: 38.977 [ms] (mean)
Time per request: 38.977 [ms] (mean, across all concurrent requests)
Transfer rate: 814.16 [Kbytes/sec] received
Time taken for tests: 17.326479 seconds
Requests per second: 57.72 [#/sec] (mean)
Time per request: 17.326 [ms] (mean)
Time per request: 17.326 [ms] (mean, across all concurrent requests)
Transfer rate: 1831.47 [Kbytes/sec] received
那么apache服务器的效果如何呢,又做了测试
Server Software: Apache/2.2.3
Server Hostname: 121.250.15.4
Server Port: 80
Document Path: /forum-19-1.html
Document Length: 32116 bytes
Time taken for tests: 32.138246 seconds
Requests per second: 31.12 [#/sec] (mean)
Time per request: 32.138 [ms] (mean)
Time per request: 32.138 [ms] (mean, across all concurrent requests)
Transfer rate: 988.04 [Kbytes/sec] received
Time taken for tests: 20.6633 seconds
Requests per second: 49.98 [#/sec] (mean)
Time per request: 20.007 [ms] (mean)
Time per request: 20.007 [ms] (mean, across all concurrent requests)
Transfer rate: 1587.17 [Kbytes/sec] received
其中红色为开启xcache的值
结果来看开启xcache肯定要快,至于apache和nginx的fastcgi来比较缺让人看的不清楚, 只能解释由于第一次测试的是nginx不开xcache可能在数据库端使其变慢,都以一次测试的值也不能算作科学统计,仅做为自己的测试吧。
billy linux, 我的网站 apache, linux, nginx, php, xcache
加入了php的支持,nginx使用的是fastcgi。
我使用的是centos5.2系统,其中已经通过yum安装了php,因为不想再自己重新编译了就采用spawn-fcgi的方式来做fastcgi,spawn-fcgi包含在lighttpd,
wget lighttpd
./configure;
make;
cp src/spawn-fcgi /usr/bin/spawn-fcgi
spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u nobody -g nobody -f /usr/bin/php-cgi
加入开机启动
nginx 配置
加入了rewrite来做永久链接
server {
listen 222.132.76.204:80;
server_name www.wangjian.info;
access_log /export/hd1/weblog/gpsview.access.log main;
location / {
root /export/hd1/web/blog/;
index index.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /export/hd1/web/blog$fastcgi_script_name;
include fastcgi_params;
}
}
}
OK了,经过感觉,速度好像是快了点。继续测试中。
billy linux, 我的网站 install, linux, nginx, php