apache切割工具: cronlog 和rotare等日誌切割工具
nginx切割工具有: nginx cron+x scripts
1
2
3
4
5
6
[root@web01 ~]
# mkdir -p /server/scripts
[root@web01 ~]
# cd /server/scripts/
[root@web01 scripts]
# vim cut_nginx_log.sh #vim輸入如下內容
cd
/bin/mv
access.log access_$(
date
+%f).log
-s reload
1
2
3
4
5
6
7
8
9
[root@web01 logs]
# /bin/sh /server/scripts/cut_nginx_log.sh
[root@web01 scripts]
access.log error.log nginx.pid access_2017-08-21.log
[root@web01 scripts]
# date -s "2016/05/14" #設定現在時間為20160514
sat may 14 00:00:00 cst 2016
[root@web01 scripts]
# /bin/sh /server/scripts/cut_nginx_log.sh
[root@web01 scripts]
access_2016-05-14.log access.log nginx.pid
access_2017-08-21.log error.log www_access_2017-08-21.log
繼續優化切割指令碼
1
2
3
4
5
6
7
8
[root@web01 scripts]
# vim cut_nginx_log.sh
cd
/bin/mv
access.log access_$(
date
+%f).log
-s reload
#
rsync
.....to backup server
#del date before 7 day
find
...
設定定時任務:每天00:00切換日誌
1
2
3
4
5
6
7
8
[root@web01 scripts]
# crontab -e
[root@web01 scripts]
# crontab -l
#time sync by oldboy at 2010-2-1
*
/5
* * * *
/usr/sbin/ntpdate
time
.nist.gov >
/dev/null
2>&1
#backup
00 00 * * *
/bin/bash
/server/scripts/backup
.sh &>
/dev/null
######cut_nginx_log#####
00 00 * * *
/bin/sh
/server/scripts/cut_nginx_log
.sh>
/dev/null
2>&1
##這個就是切割日誌
上述指令碼時間可以寫成access_$(date %f -d '-1day').log ##就是當前日誌-1天意思
sandshell
Nginx 訪問日誌輪詢切割
預設情況下 nginx 會把所有的訪問日誌生成到乙個指定的訪問日誌檔案 access.log 裡,但這樣一來,時間長了就會導致日誌個頭很大,不利於日誌的分析和處理,因此,有必要對 nginx 日誌,按天或按小時進行切割,使其分成不同的檔案儲存。這裡使用按天切割的方法。bin bash this sc...
nginx日誌切割
web 訪問日誌 access log 記錄了所有外部客戶端對web伺服器的訪問行為,包含了客戶端ip,訪問日期,訪問的url資源,伺服器返回的http狀態碼等重要資訊。一條典型的web訪問日誌如下 規劃 1 要解決問題 2 nignx沒有自動分開檔案儲存日誌的機制。由於nginx它不會幫你自動分檔...
nginx 日誌切割
直接在nginx配置檔案中,配置日誌迴圈,而不需使用logrotate或配置cron任務。需要使用到 time iso8601 內嵌變數來獲取時間。time iso8601格式如下 2015 08 07t18 12 02 02 00。然後使用正規表示式來獲取所需時間的資料。使用下面的 塊 1 2 3...