This shows you the differences between two versions of the page.
saisp:labs:03:contents:02 [2014/03/09 14:05] mihai.carabas [02. Lorem ipsum] |
saisp:labs:03:contents:02 [2014/03/10 04:16] (current) mihai.carabas [02. Remote logging] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ==== 02. Remote logging ==== | + | ==== 02. [10p] Remote logging ==== |
- | * Remote logging - tutorial | + | O soluție simplă pentru monitorizarea centralizată o reprezintă jurnalizarea la distanță (remote). Toate echipamentele din rețea vor trimite mesajele de jurnalizare (logging) către un server central. |
- | * logare in syslog-ul Linuxului | + | |
- | * activare pe un switch | + | |
- | * Remote logging - exercitiu | + | În Linux, daemon-ul ce asigură jurnalizarea este ''rsyslogd''. Acesta este deja instalat pe majoritatea sistemelor Linux. |
- | * logare in syslog-ul Linuxului | + | În mod implicit, ''rsyslogd'' nu acceptă conexiuni din exterior. Pentru a activa această opțiune, trebuie editat fișierul de configurare ''/etc/rsyslog.conf'' și decomentate liniile ce activează recepționarea de mesaje UDP sau TCP. |
- | * activare pe celelalte switch-uri | + | |
+ | Vom realiza acest lucru pe statia ''monitor'': | ||
+ | |||
+ | <code bash> | ||
+ | # provides UDP syslog reception | ||
+ | $ModLoad imudp | ||
+ | $UDPServerRun 514 | ||
+ | |||
+ | # provides TCP syslog reception | ||
+ | $ModLoad imtcp | ||
+ | $InputTCPServerRun 514 | ||
+ | </code> | ||
+ | |||
+ | După ce am decomentat liniile trebuie să resetăm serviciul ''rsyslog'':<code bash> | ||
+ | root@monitor:~# /etc/init.d/rsyslog restart | ||
+ | [ ok ] Stopping enhanced syslogd: rsyslogd. | ||
+ | [ ok ] Starting enhanced syslogd: rsyslogd. | ||
+ | </code> | ||
+ | |||
+ | Pentru ca un router Cisco sa trimită mesaje de jurnalizare (logging) către un server extern, adresa acestui server trebuie configurată în modul global. În cazul nostru, vom configura adresa IP a stației ''monitor'' pe ruterul ''R1'':<code bash> | ||
+ | R1(config)# logging 192.168.1.4 | ||
+ | </code> | ||
+ | De asemenea, se poate specifica și nivelul de logging. Vor fi trimise doar mesajele cu un nivel cel puțin la fel de //grav// ca nivelul specificat:<code bash> | ||
+ | R1(config)# logging trap debugging | ||
+ | </code> | ||
+ | |||
+ | Pentru a verifica funcționalitatea, activați debugging-ul protocolului ICMP pe ruterul ''R1'' și executați comanda ''ping'':<code> | ||
+ | R1#debug ip icmp | ||
+ | ICMP packet debugging is on | ||
+ | R1#ping google.ro | ||
+ | |||
+ | Translating "google.ro"...domain server (8.8.8.8) [OK] | ||
+ | |||
+ | Type escape sequence to abort. | ||
+ | Sending 5, 100-byte ICMP Echos to 173.194.70.94, timeout is 2 seconds: | ||
+ | !!!!! | ||
+ | Success rate is 100 percent (5/5), round-trip min/avg/max = 40/40/40 ms | ||
+ | </code> | ||
+ | După cum se observă nu a apărut în consola ruterului nici un mesaj de debug. Vom verifica fișierul ''/var/log/syslog'' de pe stația ''monitor'':<code bash> | ||
+ | root@monitor:~# cat /var/log/syslog | ||
+ | Mar 9 15:56:57 192.168.1.1 19: Mar 9 13:56:56.524: ICMP: echo reply rcvd, src 173.194.70.94, dst 192.168.1.1 | ||
+ | Mar 9 15:56:57 192.168.1.1 20: Mar 9 13:56:56.564: ICMP: echo reply rcvd, src 173.194.70.94, dst 192.168.1.1 | ||
+ | Mar 9 15:56:57 192.168.1.1 21: Mar 9 13:56:56.608: ICMP: echo reply rcvd, src 173.194.70.94, dst 192.168.1.1 | ||
+ | </code> | ||
+ | Opriți debugging-ul protocolului ICMP:<code bash> | ||
+ | R1#no debug ip icmp | ||
+ | ICMP packet debugging is off | ||
+ | </code> | ||
+ | |||
+ | Configurați pe ruterul R2 jurnalizarea remote și testați funcționalitatea:<solution -hidden> | ||
+ | <code bash> | ||
+ | R2(config)#logging 192.168.1.4 | ||
+ | R2(config)#logging trap debugging | ||
+ | R2(config)#exit | ||
+ | R2#debug ip icmp | ||
+ | ICMP packet debugging is on | ||
+ | R2#ping google.ro | ||
+ | |||
+ | Translating "google.ro"...domain server (8.8.8.8) [OK] | ||
+ | |||
+ | Type escape sequence to abort. | ||
+ | Sending 5, 100-byte ICMP Echos to 173.194.70.94, timeout is 2 seconds: | ||
+ | !!!!! | ||
+ | Success rate is 100 percent (5/5), round-trip min/avg/max = 40/40/40 ms | ||
+ | |||
+ | |||
+ | root@monitor:~# cat /var/log/syslog | ||
+ | Mar 9 16:02:47 192.168.1.2 33: Mar 9 14:02:46.434: ICMP: echo reply rcvd, src 173.194.70.94, dst 192.168.1.2 | ||
+ | Mar 9 16:02:47 192.168.1.2 34: Mar 9 14:02:46.474: ICMP: echo reply rcvd, src 173.194.70.94, dst 192.168.1.2 | ||
+ | </code> | ||
+ | </solution> | ||
+ | |||
+ | Soluția prezentată până acum are dezavantajul că toate mesajele sunt stocate în același fișier. Dacă dorim ca mesajele de la un anumit ruter să fie stocate într-un fișier separat, vom folosi opțiunea ''facility'' ce ne permite clasificarea mesajelor de logging. Pe ruter R1 se configurează ''logging facility'' diferit:<code bash> | ||
+ | R1(config)# logging facility local1 | ||
+ | </code> | ||
+ | |||
+ | Pe statia ''monitor'', în ''/etc/rsyslog.conf'' vom specifica un fișier destinație pentru tipul de logging ''local1'', după care vom reseta serviciul:<code bash> | ||
+ | root@monitor:~# cat /etc/rsyslog.conf |grep -B 2 R1 | ||
+ | #### RULES #### | ||
+ | ############### | ||
+ | local1.* /var/log/R1.log | ||
+ | root@monitor:~# /etc/init.d/rsyslog restart | ||
+ | </code> | ||
+ | |||
+ | <note> | ||
+ | Tipurile de logging (''local1'') sunt predefinite și NU pot fi înlocuite cu orice șir de caracter. Caracterul ''.'' plasat după tipul de logging (''local1'') este urmat nivelul de logging pentru care se va face scrierea în fișier. În acest caz caracterul ''*'' semnifică orice nivel de logging al mesajelor. | ||
+ | </note> | ||
+ | |||
+ | Pentru testare:<code bash> | ||
+ | R1#debug ip icmp | ||
+ | ICMP packet debugging is on | ||
+ | R1#ping acs.pub.ro | ||
+ | |||
+ | Translating "acs.pub.ro"...domain server (8.8.8.8) [OK] | ||
+ | |||
+ | Type escape sequence to abort. | ||
+ | Sending 5, 100-byte ICMP Echos to 141.85.227.151, timeout is 2 seconds: | ||
+ | !!!!! | ||
+ | Success rate is 100 percent (5/5), round-trip min/avg/max = 4/20/32 ms | ||
+ | |||
+ | root@monitor:~# cat /var/log/R1.log | ||
+ | Mar 9 16:11:16 192.168.1.1 45: Mar 9 14:11:15.651: ICMP: echo reply rcvd, src 141.85.227.151, dst 192.168.1.1 | ||
+ | Mar 9 16:11:16 192.168.1.1 46: Mar 9 14:11:15.655: ICMP: echo reply rcvd, src 141.85.227.151, dst 192.168.1.1 | ||
+ | Mar 9 16:11:16 192.168.1.1 47: Mar 9 14:11:15.687: ICMP: echo reply rcvd, src 141.85.227.151, dst 192.168.1.1 | ||
+ | </code> | ||
+ | |||
+ | Configurați un fișier separat de logging și pentru ruterul ''R2''. | ||
+ | <solution -hidden> | ||
+ | <code> | ||
+ | R2(config)#logging facility local2 | ||
+ | |||
+ | root@monitor:~# cat /etc/rsyslog.conf |grep -B3 R2 | ||
+ | #### RULES #### | ||
+ | ############### | ||
+ | local1.* /var/log/R1.log | ||
+ | local2.* /var/log/R2.log | ||
+ | root@monitor:~# /etc/init.d/rsyslog restart | ||
+ | [ ok ] Stopping enhanced syslogd: rsyslogd. | ||
+ | [ ok ] Starting enhanced syslogd: rsyslogd. | ||
+ | |||
+ | R2#debug ip icmp | ||
+ | ICMP packet debugging is on | ||
+ | R2#ping acs.pub.ro | ||
+ | |||
+ | Translating "acs.pub.ro"...domain server (8.8.8.8) [OK] | ||
+ | |||
+ | Type escape sequence to abort. | ||
+ | Sending 5, 100-byte ICMP Echos to 141.85.227.151, timeout is 2 seconds: | ||
+ | !!!!! | ||
+ | Success rate is 100 percent (5/5), round-trip min/avg/max = 4/14/28 ms | ||
+ | |||
+ | root@monitor:~# cat /var/log/R2.log | ||
+ | Mar 9 16:15:54 192.168.1.2 84: Mar 9 14:15:53.151: ICMP: echo reply rcvd, src 141.85.227.151, dst 192.168.1.2 | ||
+ | Mar 9 16:15:54 192.168.1.2 85: Mar 9 14:15:53.183: ICMP: echo reply rcvd, src 141.85.227.151, dst 192.168.1.2 | ||
+ | </code> | ||
+ | </solution> | ||