关于使用keepalived后nginx日志中的健康日志清除方法
近期在ESX上部署了小站,使用lvs+keepalived负载均衡,发现nginx服务的日志里有大量的信息,看日志时很是痛苦,在nginx上想让方法不让它记录,结是我是没有找到。问了煮酒哥后,使用 sed来删除它,于是乎在日志切割的脚本中使用它。呵,sed不是很熟,各位熟sed的欢迎拍砖!
[root@svr1 20110827]# tail 20110827.access.log
10.1.1.20 - - [27/Aug/2011:23:59:32 +0800] "-" 400 0 "-" "-" -
10.1.1.10 - - [27/Aug/2011:23:59:33 +0800] "-" 400 0 "-" "-" -
10.1.1.20 - - [27/Aug/2011:23:59:38 +0800] "-" 400 0 "-" "-" -
10.1.1.10 - - [27/Aug/2011:23:59:39 +0800] "-" 400 0 "-" "-" -
10.1.1.20 - - [27/Aug/2011:23:59:44 +0800] "-" 400 0 "-" "-" -
10.1.1.10 - - [27/Aug/2011:23:59:45 +0800] "-" 400 0 "-" "-" -
10.1.1.20 - - [27/Aug/2011:23:59:50 +0800] "-" 400 0 "-" "-" -
#!/bin/bash
#made by cheng
#blog:myhat.blog.51cto.com
#last_time=2011/08/16
#your logs store
log_path=/data1/backup_log
nginx_pid=/usr/local/webserver/nginx/nginx.pid
nginx_log=/data1/logs
yesterday=`date -d "yesterday" +%Y%m%d`
host=`ls -l $nginx_log/*.access.log | awk -F " " '{print $9}' | awk -F ".access" '{print $1}' | awk -F "$nginx_log/" '{print $2}'`
for i in $host
do
if [ ! -d $log_path/$i/$yesterday ];then
mkdir -p $log_path/$i/$yesterday
fi
if [ ! -f $log_path/$i/$yesterday/$yesterday.access.log ];then
mv $nginx_log/$i.access.log $log_path/$i/$yesterday/$yesterday.access.log
kill -USR1 `cat $nginx_pid`
else
mv -bf $nginx_log/$i.access.log $log_path/$i/$yesterday/
sed -e '/^10.1.1/g' $log_path/$i/$yesterday/$i.access.log > $log_path/$i/$yesterday/1.access.log
sed '/^$/d' $log_path/$i/$yesterday/1.access.log > $log_path/$i/$yesterday/$yesterday.access.log
rm -rf $log_path/$i/$yesterday/$i.access.log
rm -rf $log_path/$i/$yesterday/1.access.log
相关新闻>>
- 发表评论
-
- 最新评论 更多>>