通知设置 新通知
常用Linux系统Debug命令
Geek小A 发表了文章 0 个评论 3283 次浏览 2016-07-09 13:06
netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn
netstat -n | awk '/^tcp/ {++S[$NF]};END {for(a in S) print a, S[a]}'
netstat -n | awk '/^tcp/ {++state[$NF]}; END {for(key in state) print key,"\t",state[key]}'
netstat -n | awk '/^tcp/ {++arr[$NF]};END {for(k in arr) print k,"\t",arr[k]}'
netstat -n |awk '/^tcp/ {print $NF}'|sort|uniq -c|sort -rn
netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c
netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn
netstat -n | awk '/^tcp/ {++S[$NF]};END {for(a in S) print a, S[a]}'
netstat -n | awk '/^tcp/ {++state[$NF]}; END {for(key in state) print key,"\t",state[key]}'
netstat -n | awk '/^tcp/ {++arr[$NF]};END {for(k in arr) print k,"\t",arr[k]}'
netstat -n |awk '/^tcp/ {print $NF}'|sort|uniq -c|sort -rn
netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c
2、查找请求80端口最多的20个IP连接
netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n20
netstat -ant |awk '/:80/{split($5,ip,":");++A[ip[1]]}END{for(i in A) print A,i}' |sort -rn|head -n20
tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -n 20
3、查找较多time_wait连接
netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20
4、找查较多的SYN连接
netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | more
5、根据端口列进程
netstat -ntlp | grep 80 | awk '{print $7}' | cut -d/ -f1
6、获取Web访问前10位的ip地址
cat access.log|awk '{print $1}'|sort|uniq -c|sort -nr|head -n 10
cat access.log|awk '{counts[$(11)]+=1}; END {for(url in counts) print counts[url], url}'
7、访问次数最多的文件或页面,取前20
cat access.log|awk '{print $11}'|sort|uniq -c|sort -nr|head -n 20
8、列出传输最大的几个rar文件
cat access.log|awk '{print $11}'|sort|uniq -c|sort -nr|head -n 20
9、列出输出大于200000byte(约200kb)的rar文件以及对应文件发生次数
cat access.log |awk '($10 > 200000 && $7~/\.rar/){print $7}'|sort -n|uniq -c|sort -nr|head -n 100
10、如果日志最后一列记录的是页面文件传输时间,则有列出到客户端最耗时的页面
cat access.log |awk '($7~/\.php/){print $NF " " $1 " " $4 " " $7}'|sort -nr|head -n 100
cat access.log |awk '($7~/\.php/){print $NF " " $1 " " $4 " " $7}'|sort -nr|head -n 100
11、列出最最耗时的页面(超过60秒的)的以及对应页面发生次数
cat access.log |awk '($NF > 60 && $7~/\.php/){print $7}'|sort -n|uniq -c|sort -nr|head -n 100
12、列出传输时间超过 30 秒的文件
cat access.log |awk '($NF > 30){print $7}'|sort -n|uniq -c|sort -nr|head -n 20
13、统计网站流量(G)
cat access.log |awk '{sum+=$10} END {print sum/1024/1024/1024}'
14、统计404的连接
awk '($9 ~/404/)' access.log | awk '{print $9,$7}' | sort
15、统计http status
cat access.log |awk '{counts[$(9)]+=1}; END {for(code in counts) print code, counts[code]}'
cat access.log |awk '{print $9}'|sort|uniq -c|sort -rn
16、查看是哪些爬虫在抓取内容
tcpdump -i eth0 -l -s 0 -w - dst port 80 | strings | grep -i user-agent | grep -i -E 'bot|crawler|slurp|spider'
17、查看数据库执行的sql语句
tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings | egrep -i 'SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER|CALL'
18、按域统计流量
zcat squid_access.log.tar.gz| awk '{print $10,$7}' |awk 'BEGIN{FS="[ /]"}{trfc[$4]+=$1}END{for(domain in trfc){printf "%s\t%d\n",domain,trfc[domain]}}'
19、调试命令
strace -p pid
20、磁盘性能
iostat -x 1 10
解决Apache child pid 22404 exit signal Segmentation fault (11)错误
Ansible 发表了文章 0 个评论 6745 次浏览 2016-07-07 22:31
[Wed Jul 07 11:36:03 2016] [notice] child pid 22404 exit signal Segmentation fault (11)
[Wed Jul 07 11:36:03 2016] [notice] child pid 22424 exit signal Segmentation fault (11)
[Wed Jul 07 11:36:03 2016] [notice] child pid 22404 exit signal Segmentation fault (11)
[Wed Jul 07 11:36:03 2016] [notice] child pid 22424 exit signal Segmentation fault (11)
为了解决这个问题,网上搜了几个方法都无法解决,然后网上有人说是Apache的一个bug,是内存问题,最后我只能写个脚本处理。
1、检查服务器
[root@uweb1 atom]# cat /etc/issue
CentOS release 6.5 (Final)
Kernel \r on an \m
[root@uweb1 atom]# uname -r
2.6.32-573.22.1.el6.x86_64
[root@uweb1 atom]# slabtop
Active / Total Objects (% used) : 262463 / 284128 (92.4%)
Active / Total Slabs (% used) : 18670 / 18670 (100.0%)
Active / Total Caches (% used) : 92 / 172 (53.5%)
Active / Total Size (% used) : 74471.91K / 77331.03K (96.3%)
Minimum / Average / Maximum Object : 0.02K / 0.27K / 4096.00K
OBJS ACTIVE USE OBJ SIZE SLABS OBJ/SLAB CACHE SIZE NAME
103452 103431 99% 0.10K 2796 37 11184K buffer_head
34000 33764 99% 0.98K 8500 4 34000K ext4_inode_cache
33240 33240 100% 0.19K 1662 20 6648K dentry
17024 16889 99% 0.03K 152 112 608K size-32
15323 7993 52% 0.05K 199 77 796K anon_vma_chain
13148 8203 62% 0.20K 692 19 2768K vm_area_struct
11151 9723 87% 0.06K 189 59 756K size-64
7616 7071 92% 0.55K 1088 7 4352K radix_tree_node
7261 7251 99% 0.07K 137 53 548K selinux_inode_security
6767 3720 54% 0.05K 101 67 404K anon_vma
6534 6527 99% 0.14K 242 27 968K sysfs_dir_cache
4404 4404 100% 0.58K 734 6 2936K inode_cache
3816 3767 98% 0.07K 72 53 288K Acpi-Operand
2580 1833 71% 0.12K 86 30 344K size-128
2400 1523 63% 0.25K 160 15 640K filp
2208 2199 99% 0.04K 24 92 96K Acpi-Namespace
2080 2008 96% 0.19K 104 20 416K size-192
1782 1782 100% 0.64K 297 6 1188K proc_inode_cache
756 744 98% 1.00K 189 4 756K size-1024
其实apache报[notice] child pid 1421 exit signal Segmentation fault (11),绝大部分是内存泄露的问题,网上的禁止proxy和cache模块,经过我试验没有效果,修改php内存也一样。
2、解决内存泄露脚本
#!/bin/bash
time=`date`
echo $time > /tmp/clear_cached.txt
echo "total/used/free/shared/buffers/cached" >> /tmp/clear_cached.txt
echo "Cleart Before" >> /tmp/clear_cached.txt
free -m|grep Mem: >> /tmp/clear_cached.txt
sync;
echo 2 > /proc/sys/vm/drop_caches;
echo 0 > /proc/sys/vm/drop_caches;
echo "Clear After" >> /tmp/clear_cached.txt
free -m|grep Mem: >> /tmp/clear_cached.txt
Linux下iptables允许指定IP访问某应用端口
being 发表了文章 0 个评论 11443 次浏览 2016-07-03 22:15
开启网段10.0.0.0/8可以访问80端口,和允许公网IP123.125.65.82可以访问80端口
# iptables -I INPUT -p tcp --dport 80 -j DROP以上示例的意思是我先把所有请求80端口的tcp链接都drop掉,然后在插入你想针对开放访问的网段和IP地址。
# iptables -I INPUT -s 10.0.0.0/8 -p tcp --dport 80 -j ACCEPT
# iptables -I INPUT -s 123.125.65.82 -p tcp --dport 80 -j ACCEPT
如果开启NAT转发的话,如下设置:
iptables -I FORWARD -p tcp --dport 80 -j DROP
iptables -I FORWARD -s 10.0.0.0/8 -p tcp --dport 80 -j ACCEPT
下面我再介绍一些常用的iptables规则
1、邮件系统设置,只能收发邮件,其他的都DROP。
iptables -I Filter -m mac --mac-source 00:0F:wc:35:31:57 -j DROP通过MAC地址控制。
iptables -I Filter -m mac --mac-source 00:0F:wc:35:31:57 -p udp --dport 53 -j ACCEPT
iptables -I Filter -m mac --mac-source 00:0F:wc:35:31:57 -p tcp --dport 25 -j ACCEPT
iptables -I Filter -m mac --mac-source 00:0F:wc:35:31:57 -p tcp --dport 110 -j ACCEPT
IPSEC NAT 策略
iptables -I PFWanPriv -d 192.168.100.2 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 80 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:80
iptables -t nat -A PREROUTING -p tcp --dport 1723 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:1723
iptables -t nat -A PREROUTING -p udp --dport 1723 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:1723
iptables -t nat -A PREROUTING -p udp --dport 500 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:500
iptables -t nat -A PREROUTING -p udp --dport 4500 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:4500
FTP服务器的NAT
iptables -I PFWanPriv -p tcp --dport 21 -d 192.168.100.200 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 21 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.200:21
只允许访问指定网址
iptables -A Filter -p udp --dport 53 -j ACCEPT
iptables -A Filter -p tcp --dport 53 -j ACCEPT
iptables -A Filter -d www.3322.org -j ACCEPT
iptables -A Filter -d img.cn99.com -j ACCEPT
iptables -A Filter -j DROP
开放一个IP的一些端口,其它都封闭
iptables -A Filter -p tcp --dport 80 -s 192.168.100.200 -d www.pconline.com.cn -j ACCEPT
iptables -A Filter -p tcp --dport 25 -s 192.168.100.200 -j ACCEPT
iptables -A Filter -p tcp --dport 109 -s 192.168.100.200 -j ACCEPT
iptables -A Filter -p tcp --dport 110 -s 192.168.100.200 -j ACCEPT
iptables -A Filter -p tcp --dport 53 -j ACCEPT
iptables -A Filter -p udp --dport 53 -j ACCEPT
iptables -A Filter -j DROP
多个端口
iptables -A Filter -p tcp -m multiport --destination-port 22,53,80,110 -s 192.168.20.3 -j REJECT
连续端口
iptables -A Filter -p tcp -m multiport --source-port 22,53,80,110 -s 192.168.20.3 -j REJECT iptables -A Filter -p tcp --source-port 2:80 -s 192.168.20.3 -j REJECT
指定时间上网
iptables -A Filter -s 10.10.10.253 -m time --timestart 6:00 --timestop 11:00 --days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j DROP
iptables -A Filter -m time --timestart 12:00 --timestop 13:00 --days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j ACCEPT
iptables -A Filter -m time --timestart 17:30 --timestop 8:30 --days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j ACCEPT
禁止多个端口服务
iptables -A Filter -m multiport -p tcp --dport 21,23,80 -j ACCEPT
将WAN 口NAT到PC
iptables -t nat -A PREROUTING -i $INTERNET_IF -d $INTERNET_ADDR -j DNAT --to-destination 192.168.0.1
将WAN口8000端口NAT到192.168.100.200的80端口
iptables -t nat -A PREROUTING -p tcp --dport 8000 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.200:80
MAIL服务器要转的端口
iptables -t nat -A PREROUTING -p tcp --dport 110 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.200:110
iptables -t nat -A PREROUTING -p tcp --dport 25 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.200:25
基于MAC,只能收发邮件,其它都拒绝
iptables -I Filter -m mac --mac-source 00:0A:EB:97:79:A1 -j DROP
iptables -I Filter -m mac --mac-source 00:0A:EB:97:79:A1 -p tcp --dport 25 -j ACCEPT
iptables -I Filter -m mac --mac-source 00:0A:EB:97:79:A1 -p tcp --dport 110 -j ACCEPT
只允许PING 202.96.134.133 其它公网IP都不许PING
iptables -A Filter -p icmp -s 192.168.100.200 -d 202.96.134.133 -j ACCEPT
iptables -A Filter -p icmp -j DROP
禁止某个MAC地址访问internet:
iptables -I Filter -m mac --mac-source 00:20:18:8F:72:F8 -j DROP参考:http://cnzhx.net/blog/common-iptables-cli/#11
Apache Struts 远程代码执行漏洞安全预警(CVE-2016-0785/CVE-2016-4438)
Geek小A 发表了文章 0 个评论 3724 次浏览 2016-07-01 23:14
近日struts2官方发布了多个安全漏洞,其中S2-036,S2-037分别为2个远程代码执行漏洞(CVE-2016-0785,CVE-2016-4438),被攻击者利用可获取Struts程序的权限远程执行任意命令。
影响版本:
Struts 2.3.20 - Struts 2.3.28.1
漏洞描述:
S2-036漏洞:该漏洞与前期爆发的S2-029类似,在开启强制OGNL double evaluation的情况下,攻击者用可以将构造的特定代码放入标签属性,从而达到远程代码执行的目的。(由于需要开发者使用了特定的代码写法才会导致漏洞,因此官方将该漏洞风险等级调整为中级)
漏洞详情:https://cwiki.apache.org/confluence/display/WW/S2-036
S2-037漏洞:该漏洞被官方定级为高危,若服务端使用到REST插件,攻击者可远程传递一个恶意的表达式实现远程代码执行攻击。
漏洞详情:https://cwiki.apache.org/confluence/display/WW/S2-037
漏洞验证:
检查您当前的struts2版本,若版本在受影响版本范围,且使用到REST插件,说明存在漏洞。
修复方案:
如果您使用了Struts2并在受影响版本内,我们建议您尽快按照如下方案进行修复:
1、在使用的标签属性中对每一个传入的参数值进行适当的验证;
2、定期定日备份数据以及源代码,在被攻击第一时间恢复和还原;
3、目前官方已经推出了Struts 2.3.29和Struts 2.5.1修复这几个问题,大家可以针对自己所使用的版本进行升级(推荐)
下载地址:https://github.com/apache/struts/releases/
Struts2作为广泛应用的Web框架,安全问题一直层出不穷。为了保证安全,建议您在业务处理中不应信任用户提交上来的任何数据,做好安全过滤。最好能在Ognl的执行入口加入过滤黑名单,并及时将Struts更新到最新版本。
Bitly运维团队的10个监控教训
Geek小A 发表了文章 0 个评论 3068 次浏览 2016-06-29 23:01
我们总是会监控很多指标(比如硬盘利用率、内存利用率、负载、ping等等)。除了这些,我们还从运营自家产品系统的过程中吸取了很多经验教训,这些经验教训帮助我们扩充了在bitly的监控范围。
下面是我最喜欢的推特之一,来自@DevOps_Borat
开发者的墨菲定律:如果一件事情可能会出现错误,那么这就意味着它已经出错了,只不过你还没有发现罢了。
下面是一个我们运营bitly时的监控清单,这些例子的背后故事,有时甚至可以称为痛苦的经历,帮助了bitly的成长。
1.叉率 | Fork Rate
我们曾经遇到过这样一个问题:通过设置options ipv6 disable=1和在/etc/modprobe.conf中的alias ipv6 off,将一台服务器的IPv6关闭。不过这可给我们找了一个大麻烦:每次创建一个新的curl对象,modprobe都会被调用,并通过检查net-pf-10来确定IPv6的状态。这可给服务器带来了很大的负担,最终我们发现了/proc/stat下的进程计数器会以每秒数以百计的速度增长,进而发现了上面说到的那些现象的原因。通常你会希望在一台流量稳定的机器上的叉率保持在1-10/s。
#!/bin/bash
# Copyright bitly, Aug 2011
# written by Jehiah Czebotar
DATAFILE="/var/tmp/nagios_check_forkrate.dat"
VALID_INTERVAL=600
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=-1
function usage()
{
echo "usage: $0 --warn=--critical= "
echo "this script checks the rate processes are created"
echo "and alerts when it goes above a certain threshold"
echo "it saves the value from each run in $DATAFILE"
echo "and computes a delta on the next run. It will ignore"
echo "any values that are older than --valid-interval=$VALID_INTERVAL (seconds)"
echo "warn and critical values are in # of new processes per second"
}
while [ "$1" != "" ]; do
PARAM=`echo $1 | awk -F= '{print $1}'`
VALUE=`echo $1 | awk -F= '{print $2}'`
case $PARAM in
-w | --warn)
WARN_THRESHOLD=$VALUE
;;
-c | --critical)
CRITICAL_THRESHOLD=$VALUE
;;
--valid-interval)
VALID_INTERVAL=$VALUE
;;
-h | --help)
usage
exit 0;
;;
esac
shift
done
if [ -z "$WARN_THRESHOLD" ] || [ -z "$CRITICAL_THRESHOLD" ]; then
echo "error: --warn and --critical parameters are required"
exit $UNKNOWN
fi
if [[ $WARN_THRESHOLD -ge $CRITICAL_THRESHOLD ]]; then
echo "error: --warn ($WARN_THRESHOLD) can't be greater than --critical ($CRITICAL_THRESHOLD)"
exit $UNKNOWN
fi
NOW=`date +%s`
min_valid_ts=$(($NOW - $VALID_INTERVAL))
current_process_count=`awk '/processes/ {print $2}' /proc/stat`
if [ ! -f $DATAFILE ]; then
mkdir -p $(dirname $DATAFILE)
echo -e "$NOW\t$current_process_count" > $DATAFILE
echo "Missing $DATAFILE; creating"
exit $UNKNOWN
fi
# now compare this to previous
mv $DATAFILE{,.previous}
while read ts process_count; do
if [[ $ts -lt $min_valid_ts ]]; then
continue
fi
if [[ $ts -ge $NOW ]]; then
# we can't use data from the same second
continue
fi
# calculate the rate
process_delta=$(($current_process_count - $process_count))
ts_delta=$(($NOW - $ts))
current_fork_rate=`echo "$process_delta / $ts_delta" | bc`
echo -e "$ts\t$process_count" >> $DATAFILE
done < $DATAFILE.previous
echo -e "$NOW\t$current_process_count" >> $DATAFILE
echo "fork rate is $current_fork_rate processes/second (based on the last $ts_delta seconds)"
if [[ $current_fork_rate -ge $CRITICAL_THRESHOLD ]]; then
exit $CRITICAL
fi
if [[ $current_fork_rate -ge $WARN_THRESHOLD ]]; then
exit $WARNING
fi
exit $OK
2.流控制包
参考网卡控制 如果你的网络设置中包括流控制包,并且你没有设置禁止它们,那么它们有时可能会引起流量丢失。(如果你觉得这听起来还不够严重,那你也许该检查下你的脑袋里都装了些什么了)。
$ /usr/sbin/ethtool -S eth0 | grep flow_control注:阅读这个来更加详细的了解当你使用某些博通网卡时,这些流控制帧是如何和链接的损耗联系在一起的。
rx_flow_control_xon: 0
rx_flow_control_xoff: 0
tx_flow_control_xon: 0
tx_flow_control_xoff: 0
3.交换输入/输出速率
人们通常会检查超过某一阈值的交换使用率。不过即便你仅仅只有一小部分内存被交换,实际上影响性能的却是交换输入/输出的速率,而不是数量。检查交换输入/输出速率会更直观。
#!/bin/bash
# Show the rate of swapping (in number of pages) between executions
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=-1
EXITFLAG=$OK
WARN_THRESHOLD=1
CRITICAL_THRESHOLD=100
IN_DATAFILE="/var/tmp/nagios_check_swap_pages_in.dat"
OUT_DATAFILE="/var/tmp/nagios_check_swap_pages_out.dat"
VALID_INTERVAL=600
function usage()
{
echo "usage: $0 --warn=--critical= "
echo "Script checks for any swap usage"
}
while [ "$1" != "" ]; do
PARAM=`echo $1 | awk -F= '{print $1}'`
VALUE=`echo $1 | awk -F= '{print $2}'`
case $PARAM in
--warn)
WARN_THRESHOLD=$VALUE
;;
--critical)
CRITICAL_THRESHOLD=$VALUE
;;
-h | --help)
usage
exit 0;
;;
esac
shift
done
NOW=`date +%s`
min_valid_ts=$(($NOW - $VALID_INTERVAL))
CURRENT_PAGES_SWAPPED_IN=`vmstat -s | grep 'pages swapped in' | awk '{print $1}'`
CURRENT_PAGES_SWAPPED_OUT=`vmstat -s | grep 'pages swapped out' | awk '{print $1}'`
mkdir -p $(dirname $IN_DATAFILE)
if [ ! -f $IN_DATAFILE ]; then
echo -e "$NOW\t$CURRENT_PAGES_SWAPPED_IN" > $IN_DATAFILE
echo "Missing $IN_DATAFILE; creating"
EXITFLAG=$UNKNOWN
fi
if [ ! -f $OUT_DATAFILE ]; then
echo -e "$NOW\t$CURRENT_PAGES_SWAPPED_OUT" > $OUT_DATAFILE
echo "Missing $OUT_DATAFILE; creating"
EXITFLAG=$UNKNOWN
fi
if [ $EXITFLAG != $OK ]; then
exit $EXITFLAG
fi
function swap_rate() {
local file=$1
local current=$2
local rate=0
mv $file ${file}.previous
while read ts swap_count; do
if [[ $ts -lt $min_valid_ts ]]; then
continue
fi
if [[ $ts -ge $NOW ]]; then
# we can't use data from the same second
continue
fi
# calculate the rate
swap_delta=$(($current - $swap_count))
ts_delta=$(($NOW - $ts))
rate=`echo "$swap_delta / $ts_delta" | bc`
echo -e "$ts\t$swap_count" >> $file
done < ${file}.previous
echo -e "$NOW\t$current" >> $file
echo $rate
}
in_rate=`swap_rate $IN_DATAFILE $CURRENT_PAGES_SWAPPED_IN`
out_rate=`swap_rate $OUT_DATAFILE $CURRENT_PAGES_SWAPPED_OUT`
echo "swap in/out is $in_rate/$out_rate per second"
if [[ $in_rate -ge $CRITICAL_THRESHOLD ]] || [[ $out_rate -ge $CRITICAL_THRESHOLD ]]; then
exit $CRITICAL
fi
if [[ $in_rate -ge $WARN_THRESHOLD ]] || [[ $out_rate -ge $WARN_THRESHOLD ]]; then
exit $WARNING
fi
exit $OK
4.服务器启动通知
意外的重启是生活的一部分。你知道你的服务器何时重启了吗?很多人都不知道。这里我们会使用一个当系统重启时会发送邮件通知的简单的初始化脚本。当添加新服务器的时候,这会很有用。同时,当服务器出现异常时,能优雅的使人了解服务器状态的变化,而不是只提供一个报警。
#!/bin/bash
#
# *************************************************
# chkconfig: 2345 99 99
# description: notify email address on system boot.
# *************************************************
# Installing:
# 1) save as /etc/rc.d/init.d/notify
# 2) set the desired email address in "MAILADD" variable
# 3) chmod a+w /etc/rc.d/init.d/notify
# 4) /sbin/chkconfig --level 2345 notify on
PATH=/bin:/usr/sbin:/usr/bin
SERVER=`hostname`
case $1 in
start)
PUBLIC_IP=`curl --connect-timeout 5 -s icanhazip.com`
PUBLIC_IPV6=`curl -6 --connect-timeout 5 -s icanhazip.com`
MAILADD=your@email.example
mail -s " Boot of $SERVER" $MAILADD <From: $0
To: $MAILADD
$SERVER has booted up.
public ip $PUBLIC_IP $PUBLIC_IPV6
If this is news to you, please investigate.
`date -u`
EOF
;;
esac
exit 0
5.NTP的时钟偏移
如果这货不被检测,是的,你的某台服务器也许已经挂了。如果你从未考虑过时钟偏离,那么你甚至可能没有在你的服务器上跑过ntpd命令。通常来说,有三点可以作为检查的切入点。
- []ntpd是否在运行。[/][]你的资料中心内的时钟脉冲相位差。[/][]你的主时间服务器和外部之间的时钟脉冲相位差。[/]
我们使用naginx check_ntp_time Plugin 做检查。
6.DNS决议
内部DNS-这是一个你会依赖却常被忽略掉的、你的构架的隐藏部分。检查它的切入点如下:
1)每个服务器的本地决议。
2)如果你的数据中心有本地DNS服务器,那么你应该检查决议,和查询的数量。
3)检查你用的每个上行DNS解析器是否可用。
外部DNS-最好能核实你的外部域名解析能正确的和你已经发布的外部域名服务器对应上。在bitly我们也依靠一些CC顶级域名,而且我们也直接监测这些认证服务器。(是的,这发生在所有的顶级域名服务器离线的时候。)
7.SSL过期
因为这种情况发生的如此之少,以至于很多人都忘记了它。修复很简单,试试更新一下SSL证书吧。
define command{
command_name check_ssl_expire
command_line $USER1$/check_http --ssl -C 14 -H $ARG1$
}
define service{
host_name virtual
service_description bitly_com_ssl_expiration
use generic-service
check_command check_ssl_expire!bitly.com
contact_groups email_only
normal_check_interval 720
retry_check_interval 10
notification_interval 720
}
8.DELL服务器管理器(OMSA)
我们将bitly分别部署在两个数据中心,一个在DELL的设备上,另一个是亚马逊EC2。对于我们的DELL设备而言,监测OMSA的输出是十分重要的。它会让我们留意磁盘阵列的状态,坏掉的磁盘(可预见性的硬件故障),内存问题,能源供应状态等等。
9.连接限制
你可能在连接限制的情况下运行过例如memcached和mysql这样的东西,但是当你向外扩展应用程序层的时候,你真的监测过你离那些限制到底有多接近吗?
与此相关的是解决遇到文件修饰符限制的进程的问题。在实际操作中,我们经常在启动脚本中加入ulimit -n 65535来启动服务以最小化连接限制带来的影响。我们也可以通过 worker_rlimit_nofile来设置Nginx。
10.负载均衡器的状态
我们可以设置负载均衡器的健康检查(health check),这样我们就可以轻松的将某台服务器从轮转中剔除。(假设一个服务器挂掉了,负载均衡器将会探测到同时停止向这台服务器发送信息—译者注)我们发现健康检查的可视化十分重要,于是我们基于相同的健康检查来监控、报警。(如果你使用EC2负载均衡器,你可以通过亚马逊的API来监测ELB的状态)
一些碎碎念(这些东西也要监测)
Nginx错误日志,服务重启(假设遇到错误时,会重启),numa统计,新进程核心转储。
结语
以上仅仅是我们保证bitly稳定运营的一些皮毛,如果打动了你,那么请戳这。
中文原文:http://blog.jobbole.com/62783/
英文原文:http://word.bitly.com/post/74839060954/ten-things-to-monitor
Apache Module加载问题记录
koyo 发表了文章 0 个评论 6203 次浏览 2016-06-19 22:04
Invalid command 'Order', perhaps misspelled or defined by a module not included in the server configuration解决方法:
LoadModule authz_host_module modules/mod_authz_host.so问题2:
Invalid command 'CustomLog', perhaps misspelled or defined by a module not included in the server configuration解决方法:
LoadModule log_config_module modules/mod_log_config.so问题3:
设置了DirectoryIndex index.html index.php 却仍然不能默认访问: index.php解决方法:
LoadModule dir_module modules/mod_dir.so问题4:
Invalid command ‘Require’, perhaps misspelled or defined by a module not included in the server configuration解决方法:
LoadModule authz_core_module modules/mod_authz_core.so问题5:
Invalid command ‘DirectoryIndex’, perhaps misspelled or defined by a module not included in the server configuration解决方法:
LoadModule dir_module modules/mod_dir.so问题6:
Unknown Authz provider: all解决方法:
LoadModule authz_host_module modules/mod_authz_host.so问题7:
Invalid command ‘Alias’, perhaps misspelled or defined by a module not included in the server configuration解决方法:
LoadModule alias_module modules/mod_alias.so问题8:
Invalid command ‘Allow’, perhaps misspelled or defined by a module not included in the server configuration解决方法:
LoadModule authn_core_module modules/mod_authn_core.so问题9:
Invalid command ‘AddHandler’, perhaps misspelled or defined by a module not included in the server configuration解决方法:
LoadModule mime_module modules/mod_mime.so问题10:
Invalid command ‘AuthType’, perhaps misspelled or defined by a module not included in the server configuration解决方法:
LoadModule authn_core_module modules/mod_authn_core.so问题11:
Invalid command ‘AuthUserFile’, perhaps misspelled or defined by a module not included in the server configuration解决方法:
LoadModule authn_file_module modules/mod_authn_file.so问题12:
Unknown Authz provider: valid-user解决方法:
LoadModule authz_user_module modules/mod_authz_user.so问题13:
Server MUST relinquish startup privileges before accepting connections. Please ensure mod_unixd or other system security module is loaded.解决方法:
LoadModule unixd_module modules/mod_unixd.so
AWK计算操作实践笔记
chris 发表了文章 0 个评论 2582 次浏览 2016-06-17 18:00
127809一、求和
16813
551646
18858
18977
29369
23563
56302
11823
20212
149427
146515
awk '{sum+=$1} END {print "Sum = ", sum}'
二、求平均
awk '{sum+=$1} END {print "Average = ", sum/NR}'如果有浮点的话还需要 .2%之类格式支持
三、求最大值
awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print "Max=", max}'
四、求最小值(min的初始值设置一个超大数即可)
awk 'BEGIN {min = 2000000000} {if ($1
五、案例分析
部分原始数据如下:09:14:00.500 3279.20 5 3279.80 29 3279.80 73 28715第一步已经实现了对原始数据每分钟最大值、最小值、平均值的统计。我把第一次统计后的数据列出来:
09:15:00.500 3279.00 14 3279.80 9 3279.80 134 28723
09:15:01.0 3279.00 11 3279.20 24 3279.20 155 28721
09:15:01.500 3279.00 3 3279.20 15 3279.20 172 28715
09:15:02.0 3278.20 7 3278.80 7 3279.20 190 28719
09:15:02.500 3278.20 2 3278.60 1 3278.80 205 28721
09:15:03.0 3278.40 1 3278.60 25 3278.60 215 28727
09:15:03.500 3278.00 88 3278.60 13 3278.60 236 28729
09:15:04.0 3278.00 88 3278.40 12 3278.20 239 28728
09:15:04.500 3278.20 2 3278.40 12 3278.20 255 28724
09:15:05.0 3278.00 78 3278.20 1 3278.00 268 28724
09:15:05.500 3278.00 71 3278.40 10 3278.20 279 28726
09:15:06.0 3278.00 65 3278.20 14 3278.00 288 28726
09:15:06.500 3278.00 58 3278.20 16 3278.00 295 28722
09:15:07.0 3278.00 48 3278.20 5 3278.20 317 28728
09:15:07.500 3278.00 44 3278.40 8 3278.00 337 28733
09:15:08.0 3278.00 39 3278.40 8 3278.00 344 28727
09:15:08.500 3278.20 1 3278.40 7 3278.20 351 28729
09:15:09.0 3278.20 1 3278.40 5 3278.20 361 28726
09:15:09.500 3278.00 29 3278.40 4 3278.20 368 2872609:19 3297.80 3296.00 3296.8$1: 时间, $2: 分钟最大值, $3: 分钟最小值, $4: 分钟平均值
09:20 3299.00 3296.60 3297.8
09:21 3298.40 3296.20 3296.9
09:22 3299.80 3297.20 3298.4
09:23 3299.20 3296.20 3298.3
09:24 3299.00 3297.20 3298.1
以上数据通过如下方式实现的:#!/bin/sh说明:把以上数据做个累计最大值和累计最小值统计。
srcpath=./src/
despath=./des/
for file in $(ls -1 -F ${srcpath} | grep -v [/$]);do
# 第一步:处理原始数据
# 通过substr来截取时间字段的[小时:分钟]
# 处理后的数据格式为 time max min arg ;共4个字段
# 最后把统计后的数据保存至目标临时文件
# 使用了三元运算符
awk '{
time=substr($1,1,5)
count[time]++
max[time]=$6>max[time]?$6:max[time]
min[time]=(!length(min[time])||$6[time])?$6:min[time]
sum[time]+=$6
}
END{
for(i in count) {
print i,max,min,sum/count
}
}' ${srcpath}${file}|sort> ${despath}${file}_tmp
done
初始化统计的时候,累计最值和每分钟最值是一样的.
要求输出如下格式数据:09:19 3297.80 3296.00 3296.8 3297.80 3296.00
09:20 3299.00 3296.60 3297.8 3299.00 3296.00
09:21 3298.40 3296.20 3296.9 3299.00 3296.00
09:22 3299.80 3297.20 3298.4 3299.80 3296.00
09:23 3299.20 3296.20 3298.3 3299.80 3296.00
09:24 3299.00 3297.20 3298.1 3299.80 3296.00
Chrome浏览器怎么清除favicon的缓存信息?
Ansible 回复了问题 2 人关注 1 个回复 5550 次浏览 2016-06-13 17:12