砍敺 IT_man 2016-11-3 21:24 蝺刻摩 ) z" o5 k- ^ g& f5 j
3 m2 O: ?3 ]" ]CentOS銝nginxlog瑼曉/var/log/nginx,雿亦餅鋡怨芸脖蒂憯蝮.
4 W7 {$ s! Y3 P7 ^, G$ k曆google潛曉靘蝻箏鈭/etc/logrotate.d/nginx瑼,抒摰鋆nginx閰脫芸Y甇斗,箔銝芸Y,航賣臬鋆箔撌桅.
4 P4 @9 V. \- U潭臭敺亙酒erver銴鋆賡靘,摰.0 @- e; h1 K% E. J6 x
% T( _* c2 k& s3 n2 }7 X
, l) S9 r4 P5 A4 n) D1 D
$ P# g* ^ F6 Y/ N% a隞乩隤芣亥蝞∠logrotate雿:; s4 U6 G6 A$ @8 _) h
s& p+ l) c+ V2 V
. F: _9 X; y. A1 D" a: @! n
摸ginx典鋆乩銝logrotate隞餃: /etc/logrotate.d/nginx ! z! m. O f4 y, }7 s% g2 S; z
/var/log/nginx/*.log {
( m9 S- v2 d: P+ U% N: e2 K daily 2 m2 E! C% a: n" V5 T* g4 O( b
missingok - D/ i! D7 k5 `# k3 Z6 ~* \3 @
rotate 52 9 y6 `" ^- |2 w Y9 i- f
compress
1 P# i& k3 T5 C I! { delaycompress
J) s8 T" ^; I7 n. `) v notifempty
/ k5 Q9 m& y" Z) j; z- ] create 640 nginx adm
. M9 C$ t" ~6 U' Z/ I$ t sharedscripts - a3 H3 f) a% a& }! N
postrotate & P$ Y: E8 h d+ r3 W* c5 y3 u/ a$ E F
[ -f /var/run /nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid` ( k3 ^3 C) j& a0 ]* C0 L; q
endscript 1 o6 B2 r5 W) |8 w4 t, S# X
} 1 `- Z3 I, ~! I
Linux亥蝞∠logrotate摰霈閰脫隞,寞閮剔蔭亥憭批憭拇詨芷/甇豢亥,撱箇唳亥.
) [. \$ X, ^" A* t2 `% H8 Y
8 r" \, I) N, b) p; F' Z' r
- \. ?4 u. z4 Q. |, Z( V8 `9 y8 F蝵株牧:
. D) P s$ B( A7 hdaily:亥隞嗆憭拚脰皛曉 ; p" s2 v, j/ R4 G+ |
missingok:憒曆圈log瑼獢,撠勗蕭仿
# T5 P( ~! R. F" y# B" Z6 ]rotate:靽餈52甈⊥遝亥 , W( d" l' b& h$ L( D0 X
compress:gzip憯蝮株脖誑敺亥 / C6 m# t" |; W% c, F
delaycompress:compress銝韏瑚蝙冽,頧脩亥隞嗅唬銝甈∟脫憯蝮
& X2 \1 X) r) d3 L Lnotifempty憒舐征隞嗥閰,銝頧
# S1 F5 f3 P# W, W6 N- Qcreate mode owner group:頧脫隞,雿輻冽摰隞嗆芋撘撱箇啁亥隞 ' }! R. P, Y' U4 o! ~
sharedscripts:銵postrotate單(閰脰單砌函箄nginx啁亥隞)
' N& w" T) Q" u; H$ p' lpostrotate/endscript:刻脖誑敺閬瑁賭誘臭誑曉仿餈啣鋆,拙萄敹桃冽銵 8 F% _! E+ `8 {! z+ o
6 t- ]$ b- a6 M9 Llogrotate閮剛◤亙軏ron/etc/cron.daily銝凋箸乩遙瑁,蝵桀蝢拙:
8 y8 T5 x% D t2 L/etc/cron.daily/logrotate+ n" i) K" ~/ V# N; Z/ J
3 N; c2 M0 o+ q: I/ r& G; ]閬皜祈岫撖怠末閮剖瑼臭誑其誑銝賭誘嚗
) ^8 b( m8 ?" X; M- H4 h# _sudo logrotate -vf /etc/logrotate.d/your-conf-file
* e& i# f* r* [3 r& G2 i+ w: f; h, j7 n8 d& @! d( I, a
8 h' O, `7 A3 F. k* T
" U# h7 r* F0 q _' `8 z+ R1 k閮:
' x6 f9 I9 A; i/ f# M: https://blog.toright.com/posts/4 ... AD%B8%E6%AA%94.html# |! n- |4 w N9 s7 X
8 l( g: K+ T9 m
|
|