nginx 自动筛选出访问量过大的ip进行屏避#!/bin/bashnginx_home=/etc/nginxlog_path=/var/log/nginxtail -n10000 $log_path/access.log|awk '{print $1,$12}'|grep -i -v -E "google|yahoo|baidu|msnbot|FeedSky|sogou"| grep -v '223.223.198.231'|awk '{print $1}'|sort|uniq -c|sort -rn|awk '{if($1>50)print "deny "$2";"}' >>./blockips.confsort ./blockips.conf |uniq -u>./blockips_new.confmv ./blockips.conf ./blockips_old.confmv ./blockips_new.conf ./blockips.confcat ./blockips.conf#service nginxreload
监控各网站首页#!/bin/shRED='33[0;31m'GREEN='33[0;32m'NC='33[0m' # No Colorfunction test_domain {local domain=$1status=`curl -s -o /dev/null -I -w "%{http_code}" $domain`if [ $status -eq '404' ]thenprintf "${domain}${RED}${status}${NC}n"elseprintf "$domain$GREEN$status$NCn"fi}domain_list=$'bixuebihui.cnnwww.bixuebihui.cnndev.bixuebihui.cnnblog.bixuebihui.cnnbixuebihui.comnwww.bixuebihui.com'while read -r domain; do#echo "... $domain ..."test_domain "http://$domain"test_domain "https://$domain"done <<< "$domain_list"
从mysql日志里过滤慢sql#!/usr/bin/perl## Nathanial Hendler# http://retards.org/## 2001-06-26 v1.0## This perl script parses a MySQL slow_queries log file# ignoring all queries less than $min_time and prints# out how many times a query was greater than $min_time# with the seconds it took each time to run.The queries# are sorted by number of times it took; the most often# query Appearing at the bottom of the output.## Usage: mysql_slow_log_parser logfile## ------------------------# SOMETHING TO THINK ABOUT (aka: how to read output)# ------------------------## Also, it does to regex substitutions to normalize# the queries...##$query_string =~ s/d+/XXX/g;#$query_string =~ s/(['"]).+?(['"])/$1XXX$2/g;## These replace numbers with XXX and strings found in# quotes with XXX so that the same select statement# with different WHERE clauses will be considered# as the same query.## so these...##SELECT * FROM offices WHERE office_id = 3;#SELECT * FROM offices WHERE office_id = 19;## become...##SELECT * FROM offices WHERE office_id = XXX;### And these...##SELECT * FROM photos WHERE camera_model LIKE 'Nikon%';#SELECT * FROM photos WHERE camera_model LIKE '%Olympus';## become...##SELECT * FROM photos WHERE camera_model LIKE 'XXX';### ---------------------# THIS MAY BE IMPORTANT (aka: Probably Not)# ---------------------## *SO* if you use numbers in your table names, or column# names, you might get some oddities, but I doubt it.# I mean, how different should the following queries be# considered?##SELECT car1 FROM autos_10;#SELECT car54 FROM autos_11;## I don't think so.#$min_time= 0;# Skip queries less than $min_time$min_rows= 0;$max_display= 10;# Truncate display if more than $max_display occurances of a queryprint "n Starting... n";$query_string= '';$time= 0;$new_sql= 0;############################################### Loop Through The Logfile##############################################while (<>) {# Skip Bogus Linesnext if ( m|/.*mysqld, Version:.+ started with:| );next if ( m|Tcp port: d+Unix socket: .*mysql.sock| );next if ( m|Times+Ids+Commands+Argument| );next if ( m|administrators+command:| );# print $_;# if ( /Query_time:s+(.*)s+Lock_time:s+(.*)s/ ) {#if ( /Query_time:s+(.*)s+Lock_time:s+(.*)s+Rows_examined:s+(d+)/ ) {if ( /Query_time:s+(.*)s+Lock_time:s+(.*)s+Rows_examined:s+(.*)/ ) {$time= $1;$rows= $3;$new_sql = 1;# print "found $1 $3n";next;}if ( /^#/ && $query_string ) {if (($time > $min_time) && ($rows >= $min_rows)) {$orig_query = $query_string;$query_string =~ s/d+/XXX/g;$query_string =~ s/'([^'\]*(\.[^'\]*)*)'/'XXX'/g;$query_string =~ s/"([^"\]*(\.[^"\]*)*)"/"XXX"/g;#$query_string =~ s/(['"]).+?(['"])/$1XXX$2/g;#$query_string =~ s/s+/ /g;#$query_string =~ s/n+/n/g;push @{$queries{$query_string}}, $time;push @{$queries_rows{$query_string}}, $rows;$queries_tot{$query_string} += $time;$queries_orig{$query_string} = $orig_query;$query_string = '';}} else {if ($new_sql) {$query_string = $_;$new_sql = 0;} else {$query_string .= $_;}}}############################################### Display Output##############################################foreach my $query ( sort { $queries_tot{$b} <=> $queries_tot{$a} } keys %queries_tot ){my $total = 0;my $cnt = 0;my @seconds = sort { $a <=> $b } @{$queries{$query}};my @rows= sort { $a <=> $b } @{$queries_rows{$query}};($total+=$_) for @seconds;($cnt++) for @seconds;print "### " . @{$queries{$query}} . " Quer" . ((@{$queries{$query}} > 1)?"ies ":"y ") . "n";print "### Total time: " . $total .", Average time: ".($total/$cnt)."n";print "### Taking ";print @seconds > $max_display ? "$seconds[0] to $seconds[-1]" : sec_joiner(@seconds);print " seconds to completen";print "### Rows analyzed ";print @rows > $max_display ? "$rows[0] - $rows[-1]": sec_joiner(@rows);print "n";print "$queryn";print $queries_orig{$query}."nn";}sub sec_joiner {my ($seconds) = @_;$string = join(", ", @{$seconds});$string =~ s/, (d+)$/ and $1/;return $string;}exit(0);
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Linux-玩转系统提示符PS1
- Linux系统 交换分区swap的管理
- 对淘宝产品定价的方法有哪些 淘宝开店常用的定价方法
- 常用茶叶水洗脸的好处,茶叶水洗脸有什么好处
- MySQL数据库运维的基本命令
- PSK 在Linux中生成高强度预共享密钥的4种方法
- 运维必看:日志标准化必须面对的 4 类问题
- 茶叶最常用包装,茶叶去黑眼圈方法
- 茶具的材质介绍,常用茶具介绍
- Linux 命令正确的退出方式:exit 0