Logrotate ilə log fayllarının idarəsi | Bilgi Bankası

Logrotate ilə log fayllarının idarəsi

Loglar üzünüzü görmür

Web server, MySQL, tətbiq - hamısı log yazır. Bir neçə həftə sonra logs/ qovluğu 50 GB ola bilər. Disk dolanda hər şey çökər. Logrotate avtomatik sıxır, köhnəni silir.

Logrotate quraşdırılmış mı?

which logrotate    # /usr/sbin/logrotate
ls /etc/logrotate.d/

Default-da Ubuntu/Debian-da quraşdırılıb. Yoxdursa: sudo apt install logrotate.

Konfiq strukturu

/etc/logrotate.conf       # əsas
/etc/logrotate.d/         # hər xidmət üçün ayrı fayl

Custom log üçün konfiq

Tutaq ki, /var/log/myapp/app.log böyüyür. Yarat /etc/logrotate.d/myapp:

/var/log/myapp/*.log {
    daily
    rotate 14
    compress
    delaycompress
    missingok
    notifempty
    create 644 www-data www-data
    sharedscripts
    postrotate
        systemctl reload myapp > /dev/null 2>&1 || true
    endscript
}

Açıqlama

  • daily - gündəlik döndür
  • rotate 14 - 14 köhnə nüsxə saxla, sonra sil
  • compress - gzip ilə sıx
  • delaycompress - yeni dönmüş faylı dərhal sıxma (bir gün gözlə)
  • missingok - log yoxdursa səhv vermə
  • notifempty - boş fayl döndərmə
  • create - yeni log faylının icazələri
  • postrotate - döndükdən sonra icra et (xidmət reload)

Test

sudo logrotate -d /etc/logrotate.d/myapp   # dry run
sudo logrotate -f /etc/logrotate.d/myapp   # zorla icra

Status

cat /var/lib/logrotate/status

Hansı log nə zaman dönüb göstərir.

Real nümunə: Nginx

/var/log/nginx/*.log {
    weekly
    rotate 52
    compress
    delaycompress
    missingok
    notifempty
    create 0640 www-data adm
    sharedscripts
    postrotate
        [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
    endscript
}

Axtardığınız məlumatı tapa bilmirsiniz?

Bilik bazasını nəzərdən keçirmisiniz, amma lazım olan cavabı tapmamısınızsa,

bizə dəstək sorğusu yazın.
Bu məqalə faydalı oldu?
Rəyiniz üçün təşəkkür edirik.
Təəssüf edirik. Məqaləni daha yaxşı hala gətirəcəyik.
Siz artıq səs vermisiniz.
(54 dəfə oxunub, 0 nəfər faydalı sayıb)