리자

Logrotate

· 18년 전 · 2183

1 logrotate

sysklogd 가 제어하지 않는 로그를 뱅글뱅글 돌리자.

1.1 emerge

emerge logrotate 

1.2 cron

하루에 한번 cron 에 의해 실행되도록 한다.
mkdir /etc/logrotate.d 
vi /etc/cron.daily/logrotatesh 
#!/bin/sh 
/usr/sbin/logrotate /etc/logrotate.d 
:wq 
chmod 700 /etc/cron.daily/logrotatesh 

1.3 setting

  • 실제 실행될 설정파일. 요점은 로테이트 시킬 로그파일 지정과 로그를 돌린 후 서버의 재시동이다.
  • /etc/logrotate.d 에 root.root 600 의 파일로 만든다.
  • 예문에 나온것들은 로그용량이 50MB 를 넘기면 교체하도록 되어있다.
  • 로그는 10개까지 생성된다.
로그가 도는 모습 예
cd /var/log/apache2 
ls -al 
-rw-r--r-- 1 root root 910 2003-06-09 03:00 access_log 
-rw-r--r-- 1 root root 51034152 2003-06-09 03:00 access_log.1 
-rw-r--r-- 1 root root 64837231 2003-06-08 03:00 access_log.2 
-rw-r--r-- 1 root root 57362834 2003-06-07 03:00 access_log.3 
-rw-r--r-- 1 root root 58374943 2003-06-06 03:01 access_log.4 
-rw-r--r-- 1 root root 79382834 2003-06-05 03:00 access_log.5 
-rw-r--r-- 1 root root 56384926 2003-06-03 03:01 access_log.6 
-rw-r--r-- 1 root root 53823232 2003-06-01 03:00 access_log.7 
-rw-r--r-- 1 root root 52344223 2003-05-26 03:00 access_log.8 
-rw-r--r-- 1 root root 54392345 2003-05-19 03:00 access_log.9 
apache2
/var/log/apache2/access_log /var/log/apache2/error_log /var/log/apache2/ssl_access_log /var/log/apache2/ssl_error_log /var/log/apache2/ssl_request_log { 
  size=50000k 
  rotate 10 
  missingok 
  notifempty 
  postrotate 
  /usr/sbin/apache2ctl graceful compress 
              Old versions of log files are compressed with gzip by default. 
              See also nocompress. 
  
  endscript 
} 
mysql
/var/log/mysql/mysql.log /var/log/mysql/mysql.err { 
  size=50000k 
  rotate 10 
  missingok 
  notifempty 
  postrotate 
  /usr/bin/mysqladmin refresh -uroot -pmysqlpassword 
  endscript 
} 
qmail
/var/log/qmail/qmail-smtpd/current /var/log/qmail/qmail-send/current { 
  size=50000k 
  rotate 10 
  missingok 
  notifempty 
  postrotate 
  /usr/bin/svc -t /service/qmail-s* 
  endscript 
} 

2 응용

매일같이 DB를 백업하되 열흘분만 남긴다.
mysql_db_backup
/yourmysqldbbackupdirectory/all_databases.sql { 
  size=1 
  rotate 10 
  missingok 
  notifempty 
  postrotate 
  /usr/bin/mysqldump --all-databases > /yourmysqldbbackupdirectory/all_databases.sql 
  endscript 
} 

3 질문과 답변

4 잡담

  • 압축만 되면 더이상 바랄게 없습니다. -송효진
    옵션중에 compress 란것이 있습니다. logrotate(8) 페이지를 참고. -- mithrandir
 
 

[펌] http://gentoo.or.kr/wiki/moin.cgi/Logrotate

[이 게시물은 관리자님에 의해 2011-10-31 17:32:05 Linux에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
18년 전 조회 3,134
18년 전 조회 2,451
18년 전 조회 3,467
18년 전 조회 3,110
18년 전 조회 3,042
18년 전 조회 5,837
18년 전 조회 2,488
18년 전 조회 3,630
18년 전 조회 3,526
18년 전 조회 3,908
18년 전 조회 3,462
18년 전 조회 2,651
18년 전 조회 2,309
18년 전 조회 2,747
18년 전 조회 6,318
18년 전 조회 2,953
18년 전 조회 4,762
18년 전 조회 2,229
18년 전 조회 1만
18년 전 조회 2,690
18년 전 조회 1,747
18년 전 조회 3,188
18년 전 조회 3,131
18년 전 조회 3,022
18년 전 조회 2,344
18년 전 조회 2,528
18년 전 조회 3,077
18년 전 조회 3,161
18년 전 조회 4,327
18년 전 조회 6,307
18년 전 조회 2,272
18년 전 조회 2,376
18년 전 조회 2,082
18년 전 조회 1,824
18년 전 조회 2,832
18년 전 조회 1,871
18년 전 조회 1,741
18년 전 조회 4,931
18년 전 조회 1,976
18년 전 조회 2,025
18년 전 조회 2,035
18년 전 조회 2,162
18년 전 조회 3,815
18년 전 조회 1,838
18년 전 조회 1,711
18년 전 조회 1,536
18년 전 조회 2,039
18년 전 조회 2,081
18년 전 조회 3,848
18년 전 조회 2,184
18년 전 조회 3,326
18년 전 조회 4,936
18년 전 조회 3,073
18년 전 조회 8,242
18년 전 조회 4,257
18년 전 조회 2,952
18년 전 조회 1,716
18년 전 조회 2,824
18년 전 조회 5,234
18년 전 조회 5,411
18년 전 조회 2,286
18년 전 조회 4,543
18년 전 조회 4,291
18년 전 조회 4,332
18년 전 조회 2,461
18년 전 조회 4,388
18년 전 조회 2,373
18년 전 조회 3,474
18년 전 조회 5,125
18년 전 조회 2,138
18년 전 조회 3,600
18년 전 조회 1,826
18년 전 조회 2,923
18년 전 조회 1,880
18년 전 조회 2,916
18년 전 조회 2,744
18년 전 조회 1,764
18년 전 조회 1,701
18년 전 조회 1,949
18년 전 조회 2,449
18년 전 조회 2,238
18년 전 조회 2,579
18년 전 조회 5,102
18년 전 조회 2,000
18년 전 조회 1,438
18년 전 조회 1,557
18년 전 조회 1,532
18년 전 조회 1,255
18년 전 조회 1,255
18년 전 조회 1,599
18년 전 조회 1,551
18년 전 조회 2,549
18년 전 조회 1,421
18년 전 조회 1,801
18년 전 조회 2,278
18년 전 조회 1,465
18년 전 조회 3,034
18년 전 조회 1,468
18년 전 조회 1,836
18년 전 조회 1,686