由于网站的访问量越来越大,用户播放视频,都要从web服务器拿文件,而且又是动态连接,要调用一个php-cgi进程,这样的话很浪费资源,所以要加缓存服务器。但是问题来了,squid 默认是不缓存动态页面的,google 了半天,发现很多人的文章没有一个说到正点上的。最后自己不停的做测试,看squid.conf.documented,把问题解决了,所以就记录下来,以便以后大家遇到同样的问题。好解决。
列子:
http://www.nginxs.com/nginx/Grec.php?id=eric&b.php?=aaa
首选用 curl 抓 head头。
nginx $> curl -I http://www.nginxs.com/nginx/Grec.php
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 27 Aug 2010 06:49:43 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Vary: Accept-Encoding
X-Powered-By: PHP/5.2.13
Set-Cookie: PHPSESSID=2d4523a7c6a5a54dbb20f64f3bc04be3; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
看红字部分,然后在看 squid.conf.documented 对应的部分
# options: override-expire
# override-lastmod
# reload-into-ims
# ignore-reload
# ignore-no-cache
# ignore-no-store
# ignore-must-revalidate
# ignore-private
# ignore-auth
# refresh-ims
#
把 Cache-Control 的信息,squid对应有违规则 那么我们修改 squid.conf
PNP,我们安装好了,有很多监控服务,都是使用的默认模版,而且有三条数据的,都不在同一图上显示,会出三个图,所以默认模版不可取,而且也难看。那么我就来添加新的模版替换掉默认模版。 添加模版呢,记得要与commands.cfg里的 check_cpu 名字相同。 比如我的 commands.cfg 里的 check_memory 我添加一个模版。 nagios $> cd /usr/local/pnp4nagios/share/templates nagios $> vim check_memory.php < ?php # # Copyright (c) 2006-2010 Joerg Linge (http://www.pnp4nagios.org) # Plugin: check_load # $opt[1] = “–vertical-label MEMORY -l0 –title \”NGINX_MEMORY for $hostname / $servicedesc\” “; # # # $def[1] = rrd::def(“var1″, $RRDFILE[1], $DS[1], “AVERAGE”); //第一条数据 变量1 $def[1] [...]
nagios 安装完了,只有数字输出监控内容是不是不炫丽呢?是不是想像CACTI 一样出炫丽的图呢?那你可以选择PNP,他可以满足你的需求,只要你的脚本符合perfdata规则,那么rrdtool就可以出数据,PNP就可以用图给你画出来。
1.下载安装 pnp4nagios-0.6.6.tar.gz
nagios $> wget http://cdnetworks-kr-1.dl.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios-0.6.6.tar.gz
nagios $> apt-get install rrdtool librrds-perl
nagios $> tar zxvf pnp4nagios-0.6.6.tar.gz
nagios $> cd pnp4nagios-0.6.6
nagios $> ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd
nagios $> make all
nagios $> make install
nagios $> make install-webconf
nagios $> make install-config
nagios $> make install-init
2.创建配置文件
nagios $> cd /usr/local/pnp4nagios/etc
nagios $> mv misccommands.cfg-sample misccommands.cfg
nagios $> mv nagios.cfg-sample nagios.cfg
nagios $> mv npcd.cfg-sample npcd.cfg
nagios $> mv process_perfdata.cfg-sample process_perfdata.cfg
nagios $> mv rra.cfg-sample rra.cfg
nagios $> cd pages
nagios $> mv web_traffic.cfg-sample web_traffic.cfg
nagios $> cd ../check_commands
nagios $> mv check_all_local_disks.cfg-sample check_all_local_disks.cfg
nagios $> mv check_nrpe.cfg-sample check_nrpe.cfg
nagios $> mv check_nwstat.cfg-sample check_nwstat.cfg
今天在http://code.google.com/p/pytool/ 逛的时候,发现pyfetion又有些更新,支持配置文件,同时也支持命令方式给朋友发信。同时增加了pyDes 模块,用来加密的吧,
首先 安装 pyDes 模块
nagios $> wget http://cdnetworks-kr-2.dl.sourceforge.net/project/pydes/pydes/2.0.1/pyDes-2.0.1.zip
nagios $> unzip pyDes-2.0.1.zip
nagios $> cd pyDes-2.0.1
nagios $> python setup.py install
pyfetion登录方式
第一种load配置文件
nagios$> ./fetion.py
Get config error!
[Errno 2] No such file or directory: ‘./fetion.conf’
手机号/飞信号:1361103XXXX
口 令:xxxxx
———>
————————基于PyFetion的一个CLI飞信客户端————————
命令不区分大小写中括号里为命令的缩写
help[?] 显示本帮助信息
ls[l] 列出好友列表
status[st] 改变飞信状态 参数[0隐身 1离开 2忙碌 3在线]
参数为空显示自己的状态
msg[m] 发送消息 参数为序号或手机号 使用quit退出
sms[s] 发送短信 参数为序号或手机号 使用quit退出
参数为空给自己发短信
find[f] 查看好友是否隐身 参数为序号或手机号
add[a] 添加好友 参数为手机号或飞信号
del[d] 删除好友 参数为手机号或飞信号
cls[c] 清屏
save 保存当前登录用户和密码
quit[q] 退出对话状态
exit[x] 退出飞信
##输入 save 保存当前登录用户和密码
PyFetion:save
保存配置成功
PyFetion:exit
退出输入状态
停止接收消息
停止发送心跳
飞信退出
由于公司网站的项目要用到用户上传20M左右的文件,经过测试发现,上传的时候php-fpm单个进程占用CPU利用率大而长,上传速度也不是很理想,如果是多个人上传,效果就会更糟糕。在看nginx官网网站的时候。看到nginx支持POST,原理是这样的,POST到nginx的产生一个临时文件,nginx接受到数据在转移到FastCGI,这样多了一次复制过程和内存开销,比较浪费。但是对于上传大文件来说速度有明显改善。但是光nginx支持不够,还需要php-fpm的支持。 添加这个功能需要修改nginx配置文件: http { ……. 添加如下: client_body_in_file_only clean; client_body_temp_path /dev/shm 1 2; fastcgi_param REQUEST_BODY_FILE $request_body_file; … } 最好使用内存文件系统 /dev/shm 这样减少对磁盘的读写,减少了 磁盘 I/O,这样大大的优化了NGINX上传速度。
nagios利用移动飞信报警,可是移动飞信总是经常换协议,导致我们这些利用飞信报警的工程师很恼火,可是没有办法,许多用飞信的朋友,在2010年7月25号后,飞信又是不能发信息了,因为飞信的协议又有些变化:
飞信2010在7月25日未升级之前支持通过下面的URL为完成SSI认证:
https://uid.fetion.com.cn/ssiportal/SSIAppSignIn.aspx?mobileno=13888888888&pwd=PASSWORD
这里的PASSWORD为明文密码
移动系统切换以后这种方式不再支持,新的认证采用下面的方式:
https://uid.fetion.com.cn/ssiportal/SSIAppSignInV2.aspx?mobileno=13888888888&digest=PASSWORD
我以前写的文章:
nagios msn 飞信PHP类API 报警
http://deidara.blog.51cto.com/400447/159290
这种方法已经不能在报警了,于是我就想到了pyfetion,下载后发现,它是以文本框模式登fetion,如
果想配合nagios来报警,必须要修改脚本。下载tanjelly修改版本
http://code.google.com/p/pytool/issues/detail?id=18#c6
http://pytool.googlecode.com/issues/attachment?aid=9026163495408742977&name=PyFetion_v0.3.zip&token=74d6c28998e6b7720875a300151f4cb3
下载后得到两个文件:
fetion.py
PyFetion.py
今天在nagios插件网上下载了一个check_uptime.pl 插件,来监测nginx服务器的运行天数,服务器的运行时间·下载下来在服务器上执行能得到数据,但是在nagios服务器上,在commands.cfg 加了配置文件,然后在services.cfg 加了监测服务,在nagios 页面上显示 null. 在网上查找了好久原因都没找到问题的所在,想好了久,既然执行命令能输出内容,为什么在nagios上不能输出内容呢,发现是这个插件的输出内容格式与 nagios 的内容格式不符所导致的。
报警信息为:
***** Nagios *****
Notification Type: PROBLEM
Service: fms_uptime1
Host: fms-server
Address: 219.232.237.166
State: CRITICAL
Date/Time: Mon Aug 2 13:39:17 CST 2010
Additional Info:
(null)
下载的 check_uptime.pl 输出内容:
nagios $> ./check_uptime.pl -H -L
OK :UPTIME on fms – current uptime: 23 days
正确格式应该为:
OK – UPTIME on fms – current uptime: 23 days
状态 后面要跟 – 不能为冒号 :
从新搭建的 Nagios 服务器,该监控的业务服务都添加了内存,磁盘I/O,nginx 连接的监控,今天测试了一下邮件报警,居然不报警,查看 nagios.log 日志 有这样的错误:
[1279598130] SERVICE NOTIFICATION: eric;fms;int_net;UNKNOWN;notify-service-by-email;ERROR: Description table : The requested table is empty or does not exist.
[1279598130] Warning: Attempting to execute the command “/usr/bin/printf “%b” “***** Nagios *****\n\nNotification Type: PROBLEM\n\nService: int_net\nHost: fms-server\nAddress: 219.232.237.166\nState: UNKNOWN\n\nDate/Time: Tue Jul 20 11:55:30 CST 2010\n\nAdditional Info:\n\nERROR: Description table : The requested table is empty or does not exist.” | /bin/mail -s “** PROBLEM Service Alert: fms-server/int_net is UNKNOWN **” eric@nginxs.com” resulted in a return code of 127. Make sure the script or binary you are trying to execute actually exists…
“Make sure the script or binary you are trying to execute actually exists…” 提示的 mail 命令不存在
nagios $> whereis mail
mail: /usr/bin/mail /etc/mail.rc /usr/share/man/man1/mail.1.gz
路径果然 不是 /bin/mail
昨天给nagios添加了check_snmp_int 插件,通过SNMP 来统计服务器的流量,今天来了打开nagios 发现了奇怪的问题,监控机器出现 eth0:UP No usable data on file (201 rows)
1 UP): UNKNOWN ,随后登录 nagios 服务器 检查日志有大量的错误:
[1279555311] SERVICE ALERT: web;int_net;UNKNOWN;SOFT;1;eth0:UP No usable data on file (201 rows)
1 UP): UNKNOWN
[1279555371] SERVICE ALERT: web;int_net;OK;SOFT;2;eth0:UP (2.0Kbps/1.1Kbps):1 UP: OK
[1279555551] SERVICE ALERT: web;int_net;UNKNOWN;SOFT;1;eth0:UP No usable data on file (201 rows)
1 UP): UNKNOWN
[1279555611] SERVICE ALERT: web;int_net;OK;SOFT;2;eth0:UP (2.0Kbps/1.0Kbps):1 UP: OK
[1279555791] SERVICE ALERT: web;int_net;UNKNOWN;SOFT;1;eth0:UP No usable data on file (201 rows)
1 UP): UNKNOWN
在 google 上搜索了一下,几乎没有解决问题的文章。为什么会有这个问题呢?错误提示没有数据在 201行位置。打开 /tmp/tmp_Nagios_int.xx.xxx.xxx.eth0 临时文件没有 201行数据。那他为什么会读取 201行呢?因为插件check_snmp_int是用perl 写的,可以用Vi 打开看,用vim 打开插件明明定义的最多保持 200行数据。
看到这两行
my $o_base_dir=”/tmp/tmp_Nagios_int.”;
my $file_history=200; # number of data to keep in files.
你的站点是不是图片、视频比较多,本身流量就很大,再有大量的盗链,很容易就把服务器击垮的,所以web站点防盗链很重要的。nginx referer_module 模块可以简单来防止盗链。
模块说明:
This module makes it possible to block access to the site with the incorrect values of line “Referer” in the request header.
Keep in mind that it is easy to spoof this header; therefore, the purpose of using of this module consists not in 100% blocking of these requests, but in the blocking of the mass flow of requests, made from typical browsers. Also, consider that the typical browser does not always provide a “Referer” header, even for correct requests.
Example
location /photos/ {
valid_referers none blocked www.mydomain.com mydomain.com;
if ($invalid_referer) {
return 403;
}
}
近期评论