Log Rotate

Link: http://www.cyberciti.biz/faq/how-do-i-rotate-log-files/

Jak obracać pliki dziennika?


Q. How do I rotate log files under Linux operating system? Pyt.: Jak mogę obracać pliki dziennika w systemie operacyjnym Linux?

A. You need use tool called logrotate, which is designed to ease administration of systems that generate large numbers of log files. A. Należy użyć narzędzia o nazwie logrotate, który został zaprojektowany w celu ułatwienia zarządzania systemami, które generują duże ilości plików dziennika. It allows automatic rotation, compression, removal, and mailing of log files. Umożliwia automatyczne obracanie, ściskanie, usuwanie i wysyłanie plików dziennika.

Each log file may be handled daily, weekly, monthly, or when it grows too large. Każdy plik dziennika może być traktowane dzienne, tygodniowe, miesięczne, lub gdy stanie się zbyt duży. With this tool you keep logs longer with less disk space. Za pomocą tego narzędzia można przechowywać logi już mniej miejsca na dysku.
Default configuration file Domyślny plik konfiguracyjny

The default configuration file is /etc/logrotate.conf: Domyślny plik konfiguracyjny to / etc / logrotate.conf:
# see "man logrotate" for details
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# uncomment this if you want your log files compressed
#compress
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
rotate 1
} # see "man logrotate" for details
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# uncomment this if you want your log files compressed
#compress
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
rotate 1
} Service or server specific configurations stored in /etc/logrotate.d directory, for example here is sample apache logrotate configuration file: # cat /etc/logrotate.d/httpd Output: # see "man logrotate" for details
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# uncomment this if you want your log files compressed
#compress
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
rotate 1
} Usługi lub serwera specyficznych ustawień zapisanych w pliku / etc / logrotate.d katalogu, na przykład tutaj jest apache logrotate przykładowy plik konfiguracyjny: # cat /etc/logrotate.d/httpd Wyjście:

/var/log/httpd/*.log { / var / log / httpd / *. log (
weekly tygodniowo
rotate 52 obracać 52
compress kompres
missingok missingok
notifempty notifempty
sharedscripts sharedscripts
postrotate postrotate
/bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true endscript / bin / kill-HUP `cat / var / run / httpd.pid 2> / dev / null` 2> / dev / null | | true endscript
} )

Where, Gdzie,

* weekly : Log files are rotated if the current weekday is less then the weekday of the last rotation or if more then a week has passed since the last rotation. pobrań: Pliki dziennika są obracane, jeśli dzień tygodnia jest mniejsza niż w dni powszednie od ostatniego obrotu lub jeżeli ponad tydzień minął od ostatnich rotacji.
* rotate 52 : Log files are rotated 52 times before being removed or mailed to the address specified in a mail directive. obracać 52: Pliki dziennika są obracane 52 razy, zanim zostanie usunięty lub pocztą na adres podany w dyrektywie mail. If count is 0, old versions are removed rather then rotated. Jeśli licznik jest 0, stare wersje są usuwane, a następnie obracać.
* compress : Old versions of log files are compressed with gzip to save disk space. kompresji: Stare wersje plików dziennika są skompresowane gzip-em w celu zaoszczędzenia miejsca na dysku.
* missingok : If the log file is missing, go on to the next one without issuing an error message. missingok: Jeżeli plik dziennika brakuje, przejdź do następnej bez wydawania komunikatu o błędzie.
* notifempty : Do not rotate the log if it is empty notifempty: nie obracać dziennika, jeśli jest ono puste
* sharedscripts : Normally, prerotate and postrotate scripts are run for each log which is rotated, meaning that a single script may be run multiple times for log file entries which match multiple files. sharedscripts: Zazwyczaj prerotate i postrotate skrypty są uruchamiane dla każdego dziennika, który obraca się, co oznacza, że pojedynczy skrypt można uruchomić kilka razy wpisy pliku dziennika, który odpowiada wielu plików. If sharedscript is specified, the scripts are only run once, no matter how many logs match the wildcarded pattern. Jeśli sharedscript jest określony, skrypty są uruchamiane tylko raz, bez względu na to, jak wiele dzienników meczu symbolu wieloznacznego wzorca. However, if none of the logs in the pattern require rotating, the scripts will not be run at all. Jednakże, jeżeli żaden z dzienników w strukturze wymagają obracania, skrypty nie będą uruchamiane na wszystkich.
* postrotate postrotate
/bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true / bin / kill-HUP `cat / var / run / httpd.pid 2> / dev / null` 2> / dev / null | | true
endscript : The lines between postrotate and endscript (both of which must appear on lines by themselves) are executed after the log file is rotated. endscript: linie pomiędzy postrotate i endscript (obie te muszą znajdować się na linii przez siebie) są realizowane po pliku dziennika jest obracany. These directives may only appear inside a log file definition. Dyrektywy te mogą się pojawić wewnątrz definicji pliku dziennika.

See complete working example: How to rotating logs with logrotate for Lighttpd web server. Zobacz cały przykład pracy: Jak do rotacji logów z logrotate dla Lighttpd serwer WWW.

Brak komentarzy:

Prześlij komentarz

LinkWithin-4

Related Posts Plugin for WordPress, Blogger...