Log centralizzato e fault tolerant con rsyslog

From RVM Wiki
Jump to navigation Jump to search
  • Con rsyslog, è possibile far loggare un client verso un server centrale. In caso di indisponibilità del server centrale, tramite il modulo relp, il logging verrà conservato in locale, ed alla riconnessione, verrà scritto.


Server

  • Installare rsyslog ed il pacchetto relp
sudo apt-get install rsyslog rsyslog-relp 
  • Impostare relp sulla porta 20154
cat | sudo tee /etc/rsyslog.d/relpserver.conf <<'EOFile'
$ModLoad imrelp # Load the input module ('im') 'relp'
$InputRELPServerRun 20514 # Set the port to 20514
EOFile
  • Riavviare rsyslog
sudo invoke-rc.d rsyslog restart
  • Controlalre che il modulo sia in ascolto
sudo netstat -anp | grep 20514
tcp        0      0 0.0.0.0:20514           0.0.0.0:*               LISTEN      15701/rsyslogd  
tcp6       0      0 :::20514                :::*                    LISTEN      15701/rsyslogd  
  • Verificare di poter accedere anche da remoto
telnet server.example.com 20514
Trying ::1...
Connected to localhost.
Escape character is '^]'.

0 serverclose 0
Connection closed by foreign host.
  • Se si vuole che gli host remoti vengano loggati separatamente dal log di sistema, inserire questa regole, che deve essere la PRIMA caricata (ordine alfabetico in /etc/rsyslog.d):
cat | sudo tee /etc/rsyslog.d/00remotes.conf <<'EOFile
$template RemoteHost,"/var/log/remote-hosts/%HOSTNAME%/syslog"

#if rule to call RemoteHost template
if ($hostname != 'galstorage01') then ?RemoteHost
& ~
EOFile
  • Riavviare rsyslog
sudo invoke-rc.d rsyslog restart
  • ATTENZIONE: è possibile che la directory remotes-hosts ed i file di log remoti vengano creati con un certo ritardo

Riferimenti

Client

  • Installare i pacchetti
sudo apt-get install  rsyslog rsyslog-relp 
  • Configurare il modulo, IMPOSTANDO IL NOME DEL SERVER RSYSLOG':
cat | sudo tee /etc/rsyslog.d/relpclient.conf <<'EOFile'
$ModLoad omrelp
$ActionQueueType LinkedList # use asynchronous processing
$ActionQueueFileName srvrfwd # set file name, also enables disk mode
$ActionResumeRetryCount -1 # infinite retries on insert failure
$ActionQueueSaveOnShutdown on # save in-memory data if rsyslog shuts down
*.* :omrelp:server.example.com:20514;RSYSLOG_ForwardFormat
EOFile
  • Riavviare rsyslog:
sudo invoke-rc.d rsyslog restart
  • Testare:
logger This is a Catalog test


Riferimenti