使用多个字符为域分隔符:
awk -F[:/] '{print $1,$NF}' /etc/passwd #使用:和/为分隔符
Awk默认空格为分隔符,如果使用空格加字符为分隔符呢?这个问题困扰我很久了,试了很多方法,下面这个方法勉强算可以吧。
iostat 2 2|grep ^dm-|awk -F"[ ]+|[-]" '{print $2,$NF}' #使用空格和-为分隔符
发布时间:April 23, 2012 // 分类:Shell // No Comments
使用多个字符为域分隔符:
awk -F[:/] '{print $1,$NF}' /etc/passwd #使用:和/为分隔符
Awk默认空格为分隔符,如果使用空格加字符为分隔符呢?这个问题困扰我很久了,试了很多方法,下面这个方法勉强算可以吧。
iostat 2 2|grep ^dm-|awk -F"[ ]+|[-]" '{print $2,$NF}' #使用空格和-为分隔符
发布时间:April 23, 2012 // 分类:网络安全 // No Comments
有的网站被恶意放上UDP发包工具攻击别人,导致流量大量流失,一般服务器只有DNS使用udp协议,其它则可禁用UDP数据包外出。
为此写了个脚本只允许目标DNS服务器的UDP数据包外出,其它UDP数据包全部拒绝,本方法仅能做到防止恶意UDP数据包发出,服务器本身做好安全设置防止被恶意放马才是王道。
#/bin/bash
#Createdby https://www.haiyun.me
#DROP UDP Flood
list=`grep nameserver /etc/resolv.conf |awk '{print $NF}'`
for i in $list
do
iptables -A OUTPUT -p udp -d $i --dport 53 -j ACCEPT
done
iptables -A OUTPUT -p udp -j DROP
service iptables save
发布时间:April 23, 2012 // 分类:伪静态 // No Comments
2.0版本:
location / {
rewrite ^/vod-(.*)\.html$ /index.php?s=/Home-vod-$1 last;
rewrite ^/news-(.*)$ /index.php?s=/Home-news-$1 last;
rewrite ^special-(.*)$ /index.php?s=/Home-special-$1 last;
rewrite ^/tag-(.*)$ /index.php?s=/Home-tag-$1 last;
rewrite ^/gb-(.*)$ /index.php?s=/Home-gb-$1 last;
rewrite ^/cm-(.*)$ /index.php?s=/Home-cm-$1 last;
rewrite ^/map-(.*)$ /index.php?s=/Home-map-$1 last;
rewrite ^/my-(.*)$ /index.php?s=/Home-my-$1 last;
rewrite ^/Tpl/(.*)/Home/(.*).html$ /index.php last;
}
1.9版本:
rewrite ^/vod-(.*)\.html$ /index.php?s=/Home-vod-$1;
rewrite ^/news-(.*)$ /index.php?s=/Home-news-$1;
rewrite ^/ajax-(.*)$ /index.php?s=/Home-ajax-$1;
rewrite ^/tag-(.*)$ /index.php?s=/Home-tag-$1;
rewrite ^/gb-(.*)$ /index.php?s=/Home-gb-$1;
rewrite ^/cm-(.*)$ /index.php?s=/Home-cm-$1;
发布时间:April 23, 2012 // 分类:Cacti // 2 Comments
之前有介绍Cacti中文版安装与配置,这篇文章记录如何添加监控服务器及监控内容。
被监控服务器安装配置SNMP服务:
yum -y install net-snmp #snmp服务
yum -y install net-snmp-utils #使用snmpwalk需要
添加或修改SNMP配置:
vim /etc/snmp/snmpd.conf
com2sec notConfigUser default public #public为验证字符,可自定义修改,后cacti配置会用到
access notConfigGroup "" any noauth exact systemview none none #systemview修改为all
view all included .1 80 #添加此行
然后登录Cacti界面添加被监控服务器,点击设备——右上角添加,输入被监控服务器IP或域名,设置模板,SNMP验证字符、端口。
添加成功会出现此画面:
然后点击为此设备生成图像,选择相应的监控内容。
点击创建,如果成功会提示:
到此就算添加监控服务器完成了,过几分钟在查看图像处就可看到监控生成的图像了。
发布时间:April 22, 2012 // 分类:Nginx // No Comments
substitutions_filter是Nginx的一个扩展模块,用来搜索并替换应答内容中的文本,配合nginx的反向代理有妙用哦。
添加此模块需重新编译Nginx,LNMP编译升级请参考:LNMP平滑升级。
首先获取substitutions_filter:
yum -y install subversion
svn checkout http://substitutions4nginx.googlecode.com/svn/trunk/ substitutions4nginx-read-only
编译Nginx时添加:
./configure --add-module=/path/substitutions4nginx-read-only
使用语法:
subs_filter 源字符 目标字符 [gior]
#g:替换全部
#o:替换首个
#i:不区分大小写
#r:使用正则替换
使用范例:
location / {
subs_filter_types text/html text/css text/xml; #替换的文件类型
subs_filter st(\d*).onovps $1.www.haiyun.me ir; #
subs_filter www.haiyun.me www.haiyun.me;
}
注意:开启GZIP后不能替换,需关闭:
proxy_set_header Accept-Encoding "";