Rsyslog
Rsyslog è un servizio sempre attivo che normalmente scrive i messaggi di log sotto /va/log/.
Per funzionare deve essere attivo il servizio rsyslogd che è configurato in /etc/rsyslog.conf
Un file di configurazione contiene tre oggetti:
- facility: cioè il nome del servizio\struttura che deve loggare (esempio kern, cron, authpriv)
- severity: la severità dei log, come verbose o emergency
- destination: è il nome del file che contiene i log (normalmente sotto /var/log).
# logger hello world
# cat /var/log/messages
Se via UDP porta 8517
*.* @loghost.example.com:8517
# cat /var/log/messages
# logger --help
# logger -p notice hello2
# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none /var/log/messages
Questa linea dice che tutto quello che ha severità info o più alta, ad eccezione dei messaggi mail, autenticazioni private e crontab viene scritto sotto /var/log/messages
# The authpriv file has restricted access.
authpriv.* /var/log/secure
Questa linea dice che gli accessi (privati) al server vengono scritte sotto /var/log/secure
# Log all the mail messages in one place.
mail.* -/var/log/maillog
Creare una entry in rsyslog che scriva tutti i messaggi con una severity di error o più alta sotto /var/log/error.
Usare error o err nella entry
Redirecting logging to central log host
Il file /etc/rsyslog.conf contiene sotto la riga RULES , cosa deve essere loggato e qual'è il file di log.
#### RULES ##### Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none /var/log/messages
Questa linea dice che tutto quello che ha severità info o più alta, ad eccezione dei messaggi mail, autenticazioni private e crontab viene scritto sotto /var/log/messages
# The authpriv file has restricted access.
authpriv.* /var/log/secure
Questa linea dice che gli accessi (privati) al server vengono scritte sotto /var/log/secure
# Log all the mail messages in one place.
mail.* -/var/log/maillog
Questa linea dice che i log delle email vengono scritte sotto /var/log/maillog. Il segno '-' indica che i messaggi vengono scritti in un buffer e cancellati.
# Log cron stuff
cron.* /var/log/cron
Questa linea è usata da tutti i servizi che non hanno una loro facility.
# Log cron stuff
cron.* /var/log/cron
# Save boot messages also to boot.log
local7.* /var/log/boot.log
Cercare la nomenclatura di error
# man 5 rsyslog.conf
Cercare severity
The priority is one of the following keywords, in ascending order: debug, info, notice, warning, warn (same
as warning), err, error (same as err), crit, alert, emerg, panic (same as emerg). The keywords error, warn
and panic are deprecated and should not be used anymore. The priority defines the severity of the message.
Editare il file di configurazione
# vi /etc/rsyslog.conf
# vi /etc/rsyslog.conf
# Save boot messages also to boot.log
local7.* /var/log/boot.log
*.error /var/log/error
# systemctl restart rsyslog
Assicurasri che /var/log/error è ruotato mensilmente e che il 12 log sia salvato prima della nuova rotazione.
Creare il file seguente:
# vi /etc/logrotate.d/error
/var/log/error
{
montly
rotate 12
create
}
Aggiungere al file /etc/rsyslog.conf
se via TCP, use the following line, a porta di default è 514
se via TCP, use the following line, a porta di default è 514
*.* @loghost.example.com
Se via UDP porta 8517
*.* @loghost.example.com:8517
Riavviare il servizio rsyslog
# systemctl restart rsyslogOn the client server:
# logger "Test message from the system <hostname>"
On the Centralized rsyslog server:
# tail /var/log/messages
......... geeklab root: Test message from the system hostname