全部博文(150)
分类: 网络与安全
2017-11-17 11:18:54
了解每天nginx errorlog里面出现的错误类型和次数,和zabbix的报警核对,确保报警无漏报或者误报
crontab定时执行
0 10 * * * /root/total_nginx_error.sh
脚本内容
cat total_nginx_error.sh #!/bin/sh error_log=/var/log/nginx/error.log-`date +%Y%m%d` reciever="somename@likeyou.com" key1="upstream prematurely closed connection while reading upstream" get_error_upstream() { grep error $error_log |\ awk -F, '{print $1}' |\ awk -F: '{print $4,$5}' |\ awk '{for(i=2;i<=NF;i++){if(i==NF)printf "%s%1c\n" ,$i," " ;else printf "%s%1c" ,$i, " " }}' |\ awk '{name[$0]=$0;cnt[$0]++}END{for(i in name)print cnt[i],name[i]}' |sort -nr -k 1 } send_notification() { get_error_upstream |mail -s "Nginx errors checklist `date +%Y%m%d`" $reciever } send_notification
需要安装sendmail
安装略
需要有可以发邮件的邮箱,并在/etc/mail.rc 作如下类似配置
# Set smtp server of alert set bsdcompat set from=opsbot@likeyou.com #修改为自己的邮箱账户 set smtp="smtp.likeyou.com" #修改为自己的邮箱账户 set smtp-auth-user=somename@likeyou.com #修改为自己的邮箱账户 set smtp-auth-password="somewords" set smtp-auth=login
发送邮件内容示例
53 recv() failed (104 Connection reset by peer) while proxying connection 31 directory index of "/goluk/teData/" is forbidden 14 upstream prematurely closed connection while reading upstream 3 open() "/usr/share/nginx/html/robots.txt" failed (2 No such file or directory) 3 open() "/usr/share/nginx/html/cache/global/img/gs.gif" failed (2 No such file or directory) 2 open() "/goluk/teData/favicon.ico" failed (2 No such file or directory) 1 "/usr/share/nginx/html/PMA2005/index.html" is not found (2 No such file or directory) 1 upstream prematurely closed connection while reading response header from upstream 1 open() "/usr/share/nginx/html/webadmin/scripts/setup.php" failed (2 No such file or directory) 1 open() "/usr/share/nginx/html/testproxy.php" failed (2 No such file or directory) 1 open() "/usr/share/nginx/html/proxy.html" failed (2 No such file or directory) 1 open() "/usr/share/nginx/html/p/m/a/scripts/setup.php" failed (2 No such file or directory) 1 open() "/usr/share/nginx/html/phpmyadmin/scripts/setup.php" failed (2 No such file or directory) 1 open() "/usr/share/nginx/html/phpMyAdmin-2.10.0/scripts/setup.php" failed (2 No such file or directory) 1 open() "/usr/share/nginx/html/phpmanager/scripts/setup.php" failed (2 No such file or directory) 1 open() "/usr/share/nginx/html/mysqladmin/scripts/setup.php" failed (2 No such file or directory) 1 open() "/usr/share/nginx/html/mysql-admin/scripts/setup.php" failed (2 No such file or directory) 1 open() "/usr/share/nginx/html/myAdmin/scripts/setup.php" failed (2 No such file or directory) 1 open() "/usr/share/nginx/html/muieblackcat" failed (2 No such file or directory) 1 open() "/usr/share/nginx/html/manager/html" failed (2 No such file or directory) 1 open() "/usr/share/nginx/html/login.action" failed (2 No such file or directory) 1 open() "/usr/share/nginx/html/dbadmin/scripts/setup.php" failed (2 No such file or directory) 1 connect() failed (111 Connection refused) while connecting to upstream