일. 8월 3rd, 2025

Log files are the nervous system of Linux systems, recording critical events, errors, and user activities. Without proper management, they can consume resources, obscure crucial insights, or become security liabilities. This guide details proven strategies for efficient log handling.

1. Key Log Locations & Files

  • System Logs: /var/log/syslog, messages (generic events)
  • Authentication: /var/log/auth.log (Debian) or /var/log/secure (RHEL)
  • Kernel: /var/log/kern.log
  • Applications: Apache (/var/log/apache2/), Nginx (/var/log/nginx/)
  • Boot Process: /var/log/boot.log

2. Log Rotation: Preventing Overload

Linux uses logrotate to automate rotation/compression/deletion.
Sample Configuration (/etc/logrotate.d/custom):

/var/log/myapp.log {
    daily             # Rotate daily
    rotate 30         # Keep 30 backups
    compress          # Gzip archives
    delaycompress     # Compress previous file only
    missingok         # Ignore missing logs
    notifempty        # Skip rotation if empty
    create 0640 root adm  # Set permissions on new log
}

Run manually: logrotate -f /etc/logrotate.conf

3. Centralized Logging

Aggregate logs from multiple servers using:

  • Rsyslog: Forward logs to a central server. Configure in /etc/rsyslog.conf:
    *.* @192.168.1.100:514  # UDP forwarding to central IP
  • ELK Stack (Elasticsearch, Logstash, Kibana): For searchable visualizations.
  • Graylog/Fluentd: Alternative centralized collectors.

4. Archiving for Compliance & Forensics

  • Retention Policies:
    • Short-term: Keep compressed logs for 30–90 days on disk.
    • Long-term: Move archives to cheap storage (e.g., AWS S3 Glacier, NAS) for years.
  • Automated Archiving Script:
    # Archive /var/log/oldlogs to S3 monthly
    tar -czf /backups/logs-$(date +%Y-%m).tar.gz /var/log/oldlogs
    aws s3 cp /backups/logs-*.tar.gz s3://your-bucket/log-archives/
    find /backups -name "logs-*.tar.gz" -mtime +180 -delete

5. Security & Integrity

  • Permissions: Restrict access:
    chown root:adm /var/log/sensitive.log
    chmod 640 /var/log/sensitive.log
  • Tamper Protection:
    • Use auditd to monitor log directories.
    • Generate hashes: sha256sum /var/log/important.log > /secure/loghash.txt.
  • Write-Once Media: Burn logs to DVD-R for forensic immutability.

6. Best Practices

  • Automate Alerts: Use logwatch or custom scripts to email critical errors (e.g., FAILED SU in auth.log).
  • Regular Audits: Check retention compliance quarterly.
  • Test Restores: Validate archive integrity annually.
  • Minimize Sensitive Data: Avoid logging passwords/PII (edit app configs).

Conclusion

Proactive log management prevents chaos. Rotate aggressively, centralize visibility, archive strategically, and enforce security. Master these steps, and your logs will transform from cryptic noise into your most powerful troubleshooting and auditing asset.

> Further Reading: man logrotate, Rsyslog Documentation, ELK Stack Guide.

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다