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).


Il comando logger permette di scrivere manualemente messaggi a syslog.
# logger hello world
# cat /var/log/messages


Per scirvere i messaggi con priorità "notice" eseguire il comando
# logger --help
# logger -p notice hello2


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


# Save boot messages also to boot.log
local7.*                                 /var/log/boot.log

Questa linea è usata da tutti i servizi che non hanno una loro facility.


Creare una entry in rsyslog che scriva tutti i messaggi con una severity di error o più alta sotto /var/log/error.
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.

Usare error o err nella entry
Editare il file di configurazione
# 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
}

Redirecting logging to central log host

Aggiungere al file /etc/rsyslog.conf

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 rsyslog

È possibile utilizzare il comando "logger" per generare manualmente un messaggio di registro e vedere se il server syslog remoto lo riceve correttamente.

On 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

Post popolari in questo blog

Create e Drop Pluggable Database

ORA-12154: TNS: il listener non è attualmente a conoscenza del servizio richiesto nel descrittore di connessione