Dimensione: 190
Commento:
|
Dimensione: 26014
Commento:
|
Le cancellazioni sono segnalate in questo modo. | Le aggiunte sono segnalate in questo modo. |
Linea 1: | Linea 1: |
#LANGUAGE it [[BR]] ||<tablestyle="float:right; font-size: 0.9em; width:30%; background:#F1F1ED; margin: 0 0 1em 1em;" style="padding:0.5em;">[[TableOfContents(1)]]|| |
|
Linea 3: | Linea 7: |
----- CategoryNuoviDocumenti CategoryInTraduzione |
* Log = registrazione - log file * Logged = registrato = Introduzione = Uno degli aspetti che rendono GNU/Linux un grande sistema operativo è che, in teoria, tutto ciò che avviene al/o dentro il sistema viene in qualche modo registrato (logged). Queste informazioni hanno un valore inestimable per utilizzare il sistema in modo cosciente, e dovrebbero essere una delle prime risorse utilizzate per la risoluzione dei problemi e la ricerca delle soluzioni. I file di log dicono tutto quello che bisogna sapere, naturalmente a patto che si abbia idea di dove guardare... Il vostro sistema Ubuntu fornisce informazioni essenziali su eventi, operazioni ed altre funzionalità attraverso la registrazione di diversi files di log. Questi "log files" tipicamente sono semplice file di testo in formato ASCII standard, e la maggior parte di essi si trova nella sottodirectory di sistema `/var/log`. La maggior parte dei log files è generata dal demone di sistema '''syslogd''', altri log files sono generati direttamente dalle applicazioni che ne salvano una propria copia direttamente nei files di log situati nella sottodirectory `/var/log`. Questa Guida descrive i principali files di log ed il loro contenuto con degli esempi. Inoltre, si descrivono alcuni esempi sul modo per estrarre delle informazioni utili da queste registrazioni, usando semplicemente gli strumenti disponibili da riga di comando, come '''grep''' e '''less'''. Questa guida, inoltre, descrive demone di registrazione del sistema, '''syslogd''', la sua configurazione ed il concetto di rotazione dei log. Ulteriori informazioni sono disponibili nella sezione Risorse di questa guida. = Destinatari della Guida = Questa Guida è destinata agli utenti che abbiano un'esperienza sufficiente nell'utilizzo di GNU/Linux ed in particolare una certa esperienza nell'utilizzo degli strumenti da riga di comando e nella modifica dei files di configurazione del sistema attraverso l'uso di un editor di testo da riga di comando. Ulteriori risorse sugli editor di testo da riga di comando e sui comandi base del sistema: * [:ComandiBase] * [:EditorDiTesto] = System Log = Questa sezione della guida si occupa dei cosiddetti log di sistema, ovvero dei file di log che hanno a che fare con il funzionamento del sistema Ubuntu e non necessariamente con le altre applicazioni aggiunte dall'Amministratore del Sistema o dagli altri Utenti. Esempi di questo tipo di logs sono quelli relativi ai meccanismi di autorizzazione, ai demoni di sistema, ai messaggi di sistema ed ai log di sistema veri e propri, detti anche syslog (da non confondere con il demone syslogd di cui ci occuperemo in seguito). == Log di Autorizzazione == Il log di Autorizzazione rintraccia l'uso dei sistemi di autorizzazione, cioè tutti i quei meccanismi di Ubuntu che permettono autorizzare gli utenti che richiamano le password dell'utente, come ad esempio il sistema del Modulo di Autenticazione Pluggable (PAM), il comando sudo, l'accesso remoto da sshd, e così via. Il log file di Autorizzazione può essere raggiunto qua `/var/log/auth.log`. Questo log è utile, per esempio, a conoscere i login dell'utente, ed usare il comando sudo sul tuo sistema Ubuntu. È possibile esaminare il log, dal punto di rotazione più recente, (se è applicabile) una pagina per lo schermo, usando il seguente comando: {{{ less /var/log/auth.log }}} Premere la BARRA '''SPAZIATRICE''' per passare alla pagina seguente, o '''INVIO''' per passare una linea alla volta. il tasto '''b''' permette di tornare indietro di una pagina intera, e il tasto '''q''' chiude il programma. Le informazioni specifiche possono essere raggiunte attraverso il log Autorizazzione usando comandi del tipo grep. Per esempio, per vedere soltanto le informazioni del log Autorizzazione pertinenti al login sshd, usare il seguente comando in un terminale: {{{ grep sshd /var/log/auth.log | less }}} === Log di Debug === Il log di Debug è presente in {{{/var/log/debug}}} e fornisce dettagli, messaggi di debug dal sistema Ubuntu, ed applicazioni che loggano {{{syslogd}}} a livello di DEBUG. Questi messaggi sono utili per controllare le edizioni con ogni cosa dai driver dell'hardware, al server daemons. È possibile esaminare il log, dal punto di rotazione più recente, (se è applicabile) una pagina per lo schermo, usando il seguente comando: {{{less /var/log/debug }}} Le informazioni specifiche possono essere raggiunte attraverso il Log Debug usando comandi come: {{{grep}}}, e {{{less}}}. Per esempio, per vedere soltanto le informzaioni del Log Debug pertinenti alla Configurazione Avanzata e alla Power Interface (ACPI), usare il seguente comando in un terminale: {{{grep ACPI /var/log/debug | less }}} === Kernel Log === Il log del kernel: {{{/var/log/kern.log}}} fornisce in dettagliato messaggi provenienti dal kernel di Ubuntu Linux. Questi messaggi possono risultare utili,per esempio, for trouble-shooting a new, o modifiche del kernel. È possibile esaminare il log, dal punto di rotazione più recente, (se è applicabile) una pagina per lo schermo, usando il seguente comando: {{{less /var/log/kern.log }}} Le informazioni specifiche possono essere raggiunte attraverso il log del Kernel usando comandi come: {{{grep}}}, e {{{less}}}. Per esempio, per vedere solo le informazione nel log del Kernel Log pertinenti alla CPU (computer's Central Processing Unit), usare il seguente comando in un terminale: {{{grep CPU /var/log/kern.log | less }}} === Kernel Ring Buffer === Il kernel ring buffer in se non è un reale file di log, ma piuttosto una zona nel kenrel corrente che può essere quirelato per i messaggi del bootup del kernel attraverso il programma {{{dmesg}}}. È possibile vedere tutti i messaggi bootup del kernel usando il seguente comando in un terminale: {{{dmesg | less }}} È possibile usare il prgramma {{{dmesg}}} anche per esaminare le informazioni specifiche dai messaggi bootup del kernel, come i messaggi Plug and Play (PNP) usando il seguente comando in un terminale: {{{dmesg | grep pnp | less }}} In relation to the Kernel Ring Buffer, the default behavior of the {{{/etc/init.d/bootmisc.sh}}} system initialization script is to use the {{{dmesg}}} command to log all bootup messages to the file {{{/var/log/dmesg}}} as well. This file may be used as any other log file for examining Kernel bootup messages via commands {{{grep}}}, {{{less}}}, and others. === Messages Log === The messages log contains informational messages from applications, and system facilities, and is available at {{{/var/log/messages}}}. This log is useful for examining message output from applications, and system facilities which log to the syslog / sysklog daemon at the INFO level. You may examine the log, from its most recent rotation point, (if applicable) one page per screen, using a command such as the following from a terminal prompt: {{{less /var/log/messages}}} Specific information may be accessed from the Messages Log by using such commands as {{{grep}}}, and {{{less}}}. For example, to see only information in the Messages Log pertaining to the Gnome Configuration Daemon ({{{gconfd}}}), you might use a command such as the following at a terminal prompt: {{{grep gconfd /var/log/messages | less}}} === System Log === The system log typically contains the greatest deal of information by default about your Ubuntu system. It is located at {{{/var/log/syslog}}}, and may contain information other logs do not. You may wish to consult the System Log when you are unable to locate the desired log information in another log. == Application Logs == In addition to the myriad of system-specific logs available on your Ubuntu system, you may also access individual logs which may be used by certain applications. If you list the contents of your {{{/var/log}}} subdirectory, you will see familiar names of applications you may have installed, such as {{{/var/log/apache2}}} representing the logs for the Apache 2 Hyper Text Transport Protocol (HTTP) server, or {{{/var/log/samba}}}, which contains the logs for the Samba Server Message Block (SMB) server. This section of the guide introduces some specific examples of application logs, and information contained within them. === Apache HTTP Server Logs === The default installation for Apache2 on Ubuntu creates a log subdirectory: {{{/var/log/apache2}}}, and within this subdirectory, are two log files with two distinct purposes: * {{{/var/log/apache2/access.log}}} : Contains records of all access to the HTTP server by clients * {{{/var/log/apache2/error.log}}} : Contains records of all error conditions reported by the HTTP server With this information in mind, and a command of the tools {{{grep}}}, and {{{less}}} basic information gathering from these logs becomes possible. For example, and in terms of access, if you wished to see log records for every recorded access to your Apache2 server from the client IP address ''82.211.81.166'', and display the results as one page per screen, you would simply use a command such as the following at a terminal prompt: {{{grep "82.211.81.166" /var/log/apache2/access.log | less}}} Or, if you wished to determine if any clients using your Apache2 server were using Mac OS X, a simple command such as the following, typed into a terminal window would suffice: {{{grep "Mac OS X" /var/log/apache2/access.log | less}}} On the other side of the coin, suppose you wished to see information from the {{{/var/log/apache2/error.log}}}. This log can be used to search for instances of the Apache2 server being shut down, by using a command such as the following from a terminal prompt: {{{grep "shutting down" /var/log/apache2/error.log | less}}} You may also see all log entries which are considered errors by Apache2 with a command such as the following entered at a terminal prompt: {{{grep error /var/log/apache2/error.log | less}}} === CUPS Print System Logs === The Common Unix Printing System (CUPS) uses the default log file {{{/var/log/cups/error_log}}} to store informational and error messages. If you need to solve a printing issue in Ubuntu, then this log may be a good place to start. You may examine the log, from its most recent rotation point, (if applicable) one page per screen, using a command such as the following from a terminal prompt: {{{less /var/log/cups/error_log}}} Specific information may be accessed from the CUPS Log by using such commands as {{{grep}}}, and {{{less}}}. For example, to see only information in the CUPS Log pertaining to Full reloads, you might use a command such as the following at a terminal prompt: {{{grep reload /var/log/cups/error_log | less}}} === Rootkit Hunter Log === The Rootkit Hunter utility ({{{rkhunter}}}) checks your Ubuntu system for backdoors, sniffers, and so-called "rootkits", which are all signs of compromise of your system. The log which rkhunter uses is located at {{{/var/log/rkhunter.log}}} You may examine the log, from its most recent rotation point, (if applicable) one page per screen, using a command such as the following from a terminal prompt: {{{less /var/log/rkhunter.log}}} Specific information may be accessed from the Rootkit Hunter Log by using such commands as {{{grep}}}, and {{{less}}}. For example, to see only information in the Rootkit Hunter Log pertaining to Warnings, you might use a command such as the following at a terminal prompt: {{{grep WARNING /var/log/rkhunter.log | less}}} === Samba SMB Server Logs === The Server Message Block Protocol (SMB) server, Samba is popularly used for sharing files from your Ubuntu computer to other computers which support the SMB protocol. Samba keeps three distinct types of logs in the subdirectory {{{/var/log/samba}}}: * {{{log.nmbd}}} : Logs all messages related to Samba's NETBIOS over IP functionality (the network stuff) * {{{log.smbd}}} : Logs all messages related to Samba's SMB/CIFS functionality (the file, print, etc. sharing stuff) * {{{log.[IP_ADDRESS]}}} : Logs messages related to requests for services from the IP address contained in the log file name, for example, {{{log.192.168.1.1}}}. To view all information related to Samba's networking, you could use a command such as the following at a terminal prompt: {{{less /var/log/samba/log.nmbd}}} If you wanted only to see information logged about Master Browsers, then you might use a command like this at a terminal prompt: {{{grep "master browser" /var/log/samba/log.nmbd | less}}} If you would like to see details related to the SMB functionality of Samba, you can view the appropriate log in its entirety with a command similar to the following at a terminal prompt: {{{less /var/log/samba/log.smbd}}} To see only messages related to the start up of the Samba server, a command like the following at a terminal prompt may be used: {{{grep started /var/log/samba/log.smbd | less}}} To view all the details on connections from the client system with IP address ''192.168.99.99'' you could use a command such as the following at a terminal prompt: {{{less /var/log/samba/log.192.168.99.99}}} === X11 Server Log === The default X11 Windowing Server in use with Ubuntu is the Xorg X11 server, and assuming your computer has but one display defined, it stores log messages in the file {{{/var/log/Xorg.0.log}}}. This log is helpful for diagnosing issues with your X11 environment. You may examine the log, from its most recent rotation point, (if applicable) one page per screen, using a command such as the following from a terminal prompt: {{{less /var/log/Xorg.0.log}}} Specific information may be accessed from the Xorg Log by using such commands as {{{grep}}}, and {{{less}}}. For example, to see only information in the Xorg Log pertaining to the freetype font engine, you might use a command such as the following at a terminal prompt: {{{grep freetype /var/log/Xorg.0.log | less}}} == Non-Human-Readable Logs == Some log files found in the {{{/var/log}}} subdirectory are designed to be readable by applications, and not necessarily by humans. Some examples of such log files which appear in {{{/var/log}}} follow. === Login Failures Log === The login failures log located at {{{/var/log/faillog}}} is actually designed to be parsed, and output by the {{{faillog}}} command. For example, to print recent login failures using the {{{faillog}}} command, simply enter the following at a terminal prompt: {{{faillog}}} === Last Logins Log === The last logins log at {{{/var/log/lastlog}}} should not typically be parsed, and examined by humans, but rather should be used in conjunction with the {{{lastlog}}} command. For example to see a listing of logins with the {{{lastlog}}} command, displayed one page per screen with the {{{less}}} command, use the following command at a terminal prompt: {{{lastlog | less}}} === Login Records Log === The file {{{/var/log/wtmp}}} contains login records, but unlike {{{/var/log/lastlog}}} above, {{{/var/log/wtmp}}} is not used to show a list of recent logins, but is instead used by other utilities such as the {{{who}}} command to present a listed of currently logged in users. For example, if you wish to see who is currently logged in on the machine you are currently using, issue the following at a terminal prompt: {{{who}}} == System Logging Daemon (syslogd) == The system logging daemon, or {{{syslogd}}} (also known as {{{sysklogd}}}) is a system daemon, or special application which executes silently, in the background and does good things for your system. Specifically, {{{syslogd}}} awaits logging messages from numerous system, and application sources, and routes the messages to their proper target, be it a standard log file, a First In First Out (FIFO) pipe for use by a log analyzation application, or even across the network to another system's {{{syslogd}}}. Messages logged to {{{syslogd}}} usually contain important common elements, such as system hostnames, and time-stamps in addition to the specific log information from a system source, the Linux kernel, or a user application. === Configuration of syslogd === The detailed configuration of {{{syslogd}}} is beyond the scope of this guide, and the reader is encouraged to seek additional information via the '''Resources''' section of this guide for information on correctly configuring, and modifying the configuration of {{{syslogd}}}. The file which configures the behavior of the {{{syslogd}}} daemon is {{{/etc/syslog.conf}}} and consists primarily of two fields, the selector, and the action. The selector field consists of a facility, to be logged, such as for example the '''auth''' facility which deals with authorization, and a priority, or level to log such information at, such as '''info''', or '''warning''' priorities, which would log all messages at the informational priority and higher, or only at the warning level and higher respectively. The action field consists of a target for the log information, such as a standard log file (i.e. {{{/var/log/syslog}}}), or the hostname of a remote computer to send the log information to (e.g. @myotherubuntu). The configuration file is very flexible, and powerful in nature, allowing a seemingly infinite combination of logging to take place to fit the particular requirements your installation may have. === Echoing Messages to syslogd With Logger === A neat utility exists in the {{{logger}}} tool, which allows one to place messages into the System Log (i.e. {{{/var/log/syslog}}}) arbitrarily. This is a powerful tool, which you may use in Administrative scripts, such as Perl, or shell scripts to provide them with standard logging capabilities, or you may use it just to place things in the system log as needed. For example, assume your user name is {{{buddha}}}, and you would like to enter a message into the syslog about a particularly delicious pizza you're eating, you could use a command such as the following at a terminal prompt: {{{logger This Pizza from Vinnys Gourmet Rocks}}} and you would find a line in the {{{/var/log/syslog}}} file such as this afterward: {{{ Jan 12 23:17:02 localhost buddha: This Pizza from Vinnys Gourmet Rocks }}} Used in a little more professional manner in shell scripts, you can even specify a tag the messages come from, and redirect the output standard error too. This lets you have excellent error logging in a script, such as in this example snippet: {{{ #!/bin/bash # # sample logger error jive # logmsg="/usr/bin/logger -s -t MyScript " # announce what this script is, even to the log $logmsg "Directory Checker FooScript Jive 1.0" # test for the existence of Fred's home dir on this machine if [ -d /home/fred ]; then $logmsg "I. Fred's Home Directory Found" else $logmsg "E. Fred's Home Directory was NOT Found. Boo Hoo." exit 1 fi }}} Executing this script as {{{chkdir.sh}}} on the machine {{{butters}}} where Fred does not have a home directory, {{{/home/fred}}}, gives the following results: {{{ bumpy@butters:~$./chkdir.sh MyScript: Directory Checker FooScript Jive 1.0 MyScript: E. Fred's Home Directory was NOT Found. Boo Hoo. bumpy@butters:~$tail -n 2 /var/log/syslog Jan 12 23:23:11 localhost MyScript: Directory Checker FooScript Jive 1.0 Jan 12 23:23:11 localhost MyScript: E. Fred's Home Directory was NOT Found. Boo Hoo. }}} So, as you can see, we received the messages both via standard error, at the terminal prompt, and they also appear in our syslog! === Log Rotation === When viewing directory listings in {{{/var/log}}} or any of its subdirectories, you may encounter log files with names such as {{{daemon.log.0}}}, {{{daemon.log.1.gz}}}, and so on. What are these log files? They are 'rotated' log files. That is, they have automatically been renamed after a predefined time-frame, and a new original log started. After even more time the log files are compressed with the {{{gzip}}} utility as in the case of the example {{{daemon.log.1.gz}}}. The purpose of log rotation is to archive and compress old logs so that they consume less disk space, but are still available for inspection as needed. What handles this functionality? Why, the {{{logrotate}}} command of course! Typically, logrotate is called from the system-wide cron script {{{/etc/cron.daily/logrotate}}}, and further defined by the configuration file {{{/etc/logrotate.conf}}}. This guide will not cover the myriad of ways logrotate may be configured to handle the automatic rotation of any log file on your Ubuntu system, but rather the reader is encouraged to use the '''Resources''' section of this guide, and study the requisite manual pages to determine how to configure logrotate for a particular log file, and needs. attachment:IconsPage/IconNote.png '''NOTE:''' You may also rotate system log files via the {{{cron.daily}}} script {{{/etc/cron.daily/sysklogd}}} instead of using logrotate. Actually, the utility {{{savelog}}} may produce unexpected results on log rotation which configuring {{{logrotate}}} seems to have no effect on. In those cases, you should check the cron.daily {{{sysklogd}}} script in {{{/etc/cron.daily/sysklogd}}} and read the {{{savelog}}} manual page to see if {{{savelog}}} is not in fact doing the rotation in a way that is not what you are specifying with {{{logrotate}}}. == Additional Tips == Some additional tips for quickly viewing logs manually, (i.e. without a log file analyzer application) which may help you expediently locate the information you require. === Just the Beginning === You may look at just the beginning of any log file by using the {{{head}}} command. by default, {{{head}}} shows the first ten lines of any text file, so for example, if you wished to see the oldest entries in your Authorization Log file, a command such as the following could be used at a terminal prompt: {{{head /var/log/auth.log}}} If ten lines is not enough, and you need to see the first twenty-five (25) lines, then use {{{head}}} with the {{{-n}}} switch as such: {{{head -n 25 /var/log/auth.log}}} === Just the End === The compliment to {{{head}}} of course is none other than the {{{tail}}} command. Can you guess what {{{tail}}} allows you to do? Say you need the last ten lines of the Kernel log for important messages from the kernel of late. A command such as the following entered into a terminal prompt should do: {{{tail /var/log/kern.log}}} Again, and as with {{{head}}}, you may get more than the default ten lines of output with {{{tail}}} by specifying the {{{-n}}} switch as such: {{{tail -n 30 /var/log/kern.log}}} to see the last thirty (30) lines of the Kernel log instead. ==== Real-Time Tail ==== Another neat use for the {{{tail}}} command is to use it for watching a log in 'real-time' by specifying the {{{-f}}} switch. For example, if you wished to watch in real-time as clients access your Apache2 server, issuing a command such as this from a terminal prompt would allow you to do so: {{{tail -f /var/log/apache2/access.log}}} You will see the log spit out, then stop, and as the Apache2 server is accessed, log entries will fly by in real-time! If you have a very busy server, they will fly by too fast for you to read them! You can use the {{{-f}}} switch to view any log file in this manner. == Resources == Additional information on system, and application logs, and syslogd is available via the following resources: === Local System Resources === ||<style="background:#F1F1ED;">{{{man dmesg}}}|| System manual page for the {{{dmesg}}} kernel ring buffer utility|| ||<style="background:#F1F1ED;">{{{man faillog}}}|| System manual page for the {{{faillog}}} command (and also the faillog configuration file via {{{man 5 faillog}}})|| ||<style="background:#F1F1ED;">{{{man grep}}}|| System manual page for the {{{grep}}} pattern searching utility|| ||<style="background:#F1F1ED;">{{{man head}}}|| System manual page for the {{{head}}} utility|| ||<style="background:#F1F1ED;">{{{man klogd}}}|| System manual page for the kernel log daemon ({{{klogd}}})|| ||<style="background:#F1F1ED;">{{{man last}}}|| System manual for the {{{last}}} command which shows last logged in users|| ||<style="background:#F1F1ED;">{{{man less}}}|| System manual page for the {{{less}}} paging utility|| ||<style="background:#F1F1ED;">{{{man logger}}}|| System manual page for the {{{logger}}} command-line interface to syslog utility|| ||<style="background:#F1F1ED;">{{{man logrotate}}}|| System manual page for the the {{{logrotate}}} utility|| ||<style="background:#F1F1ED;">{{{man savelog}}}|| System manual page for the {{{savelog}}} log file saving utility|| ||<style="background:#F1F1ED;">{{{man syslogd}}}|| System manual page for the system log daemon ({{{syslogd}}})|| ||<style="background:#F1F1ED;">{{{man syslog.conf}}}|| System manual page for the {{{syslogd}}} configuration file|| ||<style="background:#F1F1ED;">{{{man tail}}}|| System manual page for the {{{tail}}} utility|| === WWW Resources === [http://www.samag.com/documents/s=1146/sam0109m/0109m.htm Checking Your System Logs with awk] [http://www.linuxvoodoo.com/resources/howtos/syslog/ Syslog - Watching Your Logs] [http://www-128.ibm.com/developerworks/linux/library/l-roadmap5/ Windows-to-Linux roadmap: Part 5. Linux logging (IBM)] [http://www.linuxsecurity.com/content/view/116430/151/ Sawing Linux Logs With Simple Tools] ---- CategoryDaRevisionare |
Traduzione di https://help.ubuntu.com/community/LinuxLogFiles?highlight=%28log%29
- Log = registrazione - log file
- Logged = registrato
Introduzione
Uno degli aspetti che rendono GNU/Linux un grande sistema operativo è che, in teoria, tutto ciò che avviene al/o dentro il sistema viene in qualche modo registrato (logged). Queste informazioni hanno un valore inestimable per utilizzare il sistema in modo cosciente, e dovrebbero essere una delle prime risorse utilizzate per la risoluzione dei problemi e la ricerca delle soluzioni. I file di log dicono tutto quello che bisogna sapere, naturalmente a patto che si abbia idea di dove guardare...
Il vostro sistema Ubuntu fornisce informazioni essenziali su eventi, operazioni ed altre funzionalità attraverso la registrazione di diversi files di log.
Questi "log files" tipicamente sono semplice file di testo in formato ASCII standard, e la maggior parte di essi si trova nella sottodirectory di sistema /var/log.
La maggior parte dei log files è generata dal demone di sistema syslogd, altri log files sono generati direttamente dalle applicazioni che ne salvano una propria copia direttamente nei files di log situati nella sottodirectory /var/log.
Questa Guida descrive i principali files di log ed il loro contenuto con degli esempi. Inoltre, si descrivono alcuni esempi sul modo per estrarre delle informazioni utili da queste registrazioni, usando semplicemente gli strumenti disponibili da riga di comando, come grep e less.
Questa guida, inoltre, descrive demone di registrazione del sistema, syslogd, la sua configurazione ed il concetto di rotazione dei log. Ulteriori informazioni sono disponibili nella sezione Risorse di questa guida.
Destinatari della Guida
Questa Guida è destinata agli utenti che abbiano un'esperienza sufficiente nell'utilizzo di GNU/Linux ed in particolare una certa esperienza nell'utilizzo degli strumenti da riga di comando e nella modifica dei files di configurazione del sistema attraverso l'uso di un editor di testo da riga di comando. Ulteriori risorse sugli editor di testo da riga di comando e sui comandi base del sistema:
[:ComandiBase]
System Log
Questa sezione della guida si occupa dei cosiddetti log di sistema, ovvero dei file di log che hanno a che fare con il funzionamento del sistema Ubuntu e non necessariamente con le altre applicazioni aggiunte dall'Amministratore del Sistema o dagli altri Utenti.
Esempi di questo tipo di logs sono quelli relativi ai meccanismi di autorizzazione, ai demoni di sistema, ai messaggi di sistema ed ai log di sistema veri e propri, detti anche syslog (da non confondere con il demone syslogd di cui ci occuperemo in seguito).
Log di Autorizzazione
Il log di Autorizzazione rintraccia l'uso dei sistemi di autorizzazione, cioè tutti i quei meccanismi di Ubuntu che permettono autorizzare gli utenti che richiamano le password dell'utente, come ad esempio il sistema del Modulo di Autenticazione Pluggable (PAM), il comando sudo, l'accesso remoto da sshd, e così via. Il log file di Autorizzazione può essere raggiunto qua /var/log/auth.log. Questo log è utile, per esempio, a conoscere i login dell'utente, ed usare il comando sudo sul tuo sistema Ubuntu.
È possibile esaminare il log, dal punto di rotazione più recente, (se è applicabile) una pagina per lo schermo, usando il seguente comando:
less /var/log/auth.log
Premere la BARRA SPAZIATRICE per passare alla pagina seguente, o INVIO per passare una linea alla volta. il tasto b permette di tornare indietro di una pagina intera, e il tasto q chiude il programma.
Le informazioni specifiche possono essere raggiunte attraverso il log Autorizazzione usando comandi del tipo grep. Per esempio, per vedere soltanto le informazioni del log Autorizzazione pertinenti al login sshd, usare il seguente comando in un terminale:
grep sshd /var/log/auth.log | less
Log di Debug
Il log di Debug è presente in /var/log/debug e fornisce dettagli, messaggi di debug dal sistema Ubuntu, ed applicazioni che loggano syslogd a livello di DEBUG. Questi messaggi sono utili per controllare le edizioni con ogni cosa dai driver dell'hardware, al server daemons.
È possibile esaminare il log, dal punto di rotazione più recente, (se è applicabile) una pagina per lo schermo, usando il seguente comando:
{{{less /var/log/debug }}}
Le informazioni specifiche possono essere raggiunte attraverso il Log Debug usando comandi come: grep, e less. Per esempio, per vedere soltanto le informzaioni del Log Debug pertinenti alla Configurazione Avanzata e alla Power Interface (ACPI), usare il seguente comando in un terminale:
{{{grep ACPI /var/log/debug | less }}}
Kernel Log
Il log del kernel: /var/log/kern.log fornisce in dettagliato messaggi provenienti dal kernel di Ubuntu Linux. Questi messaggi possono risultare utili,per esempio, for trouble-shooting a new, o modifiche del kernel.
È possibile esaminare il log, dal punto di rotazione più recente, (se è applicabile) una pagina per lo schermo, usando il seguente comando:
{{{less /var/log/kern.log }}}
Le informazioni specifiche possono essere raggiunte attraverso il log del Kernel usando comandi come: grep, e less. Per esempio, per vedere solo le informazione nel log del Kernel Log pertinenti alla CPU (computer's Central Processing Unit), usare il seguente comando in un terminale:
{{{grep CPU /var/log/kern.log | less }}}
Kernel Ring Buffer
Il kernel ring buffer in se non è un reale file di log, ma piuttosto una zona nel kenrel corrente che può essere quirelato per i messaggi del bootup del kernel attraverso il programma dmesg. È possibile vedere tutti i messaggi bootup del kernel usando il seguente comando in un terminale:
{{{dmesg | less }}}
È possibile usare il prgramma dmesg anche per esaminare le informazioni specifiche dai messaggi bootup del kernel, come i messaggi Plug and Play (PNP) usando il seguente comando in un terminale:
{{{dmesg | grep pnp | less }}}
In relation to the Kernel Ring Buffer, the default behavior of the /etc/init.d/bootmisc.sh system initialization script is to use the dmesg command to log all bootup messages to the file /var/log/dmesg as well. This file may be used as any other log file for examining Kernel bootup messages via commands grep, less, and others.
Messages Log
The messages log contains informational messages from applications, and system facilities, and is available at /var/log/messages. This log is useful for examining message output from applications, and system facilities which log to the syslog / sysklog daemon at the INFO level.
You may examine the log, from its most recent rotation point, (if applicable) one page per screen, using a command such as the following from a terminal prompt:
less /var/log/messages
Specific information may be accessed from the Messages Log by using such commands as grep, and less. For example, to see only information in the Messages Log pertaining to the Gnome Configuration Daemon (gconfd), you might use a command such as the following at a terminal prompt:
grep gconfd /var/log/messages | less
System Log
The system log typically contains the greatest deal of information by default about your Ubuntu system. It is located at /var/log/syslog, and may contain information other logs do not. You may wish to consult the System Log when you are unable to locate the desired log information in another log.
Application Logs
In addition to the myriad of system-specific logs available on your Ubuntu system, you may also access individual logs which may be used by certain applications. If you list the contents of your /var/log subdirectory, you will see familiar names of applications you may have installed, such as /var/log/apache2 representing the logs for the Apache 2 Hyper Text Transport Protocol (HTTP) server, or /var/log/samba, which contains the logs for the Samba Server Message Block (SMB) server. This section of the guide introduces some specific examples of application logs, and information contained within them.
Apache HTTP Server Logs
The default installation for Apache2 on Ubuntu creates a log subdirectory: /var/log/apache2, and within this subdirectory, are two log files with two distinct purposes:
/var/log/apache2/access.log : Contains records of all access to the HTTP server by clients
/var/log/apache2/error.log : Contains records of all error conditions reported by the HTTP server
With this information in mind, and a command of the tools grep, and less basic information gathering from these logs becomes possible.
For example, and in terms of access, if you wished to see log records for every recorded access to your Apache2 server from the client IP address 82.211.81.166, and display the results as one page per screen, you would simply use a command such as the following at a terminal prompt:
grep "82.211.81.166" /var/log/apache2/access.log | less
Or, if you wished to determine if any clients using your Apache2 server were using Mac OS X, a simple command such as the following, typed into a terminal window would suffice:
grep "Mac OS X" /var/log/apache2/access.log | less
On the other side of the coin, suppose you wished to see information from the /var/log/apache2/error.log. This log can be used to search for instances of the Apache2 server being shut down, by using a command such as the following from a terminal prompt:
grep "shutting down" /var/log/apache2/error.log | less
You may also see all log entries which are considered errors by Apache2 with a command such as the following entered at a terminal prompt:
grep error /var/log/apache2/error.log | less
CUPS Print System Logs
The Common Unix Printing System (CUPS) uses the default log file /var/log/cups/error_log to store informational and error messages. If you need to solve a printing issue in Ubuntu, then this log may be a good place to start. You may examine the log, from its most recent rotation point, (if applicable) one page per screen, using a command such as the following from a terminal prompt:
less /var/log/cups/error_log
Specific information may be accessed from the CUPS Log by using such commands as grep, and less. For example, to see only information in the CUPS Log pertaining to Full reloads, you might use a command such as the following at a terminal prompt:
grep reload /var/log/cups/error_log | less
Rootkit Hunter Log
The Rootkit Hunter utility (rkhunter) checks your Ubuntu system for backdoors, sniffers, and so-called "rootkits", which are all signs of compromise of your system. The log which rkhunter uses is located at /var/log/rkhunter.log You may examine the log, from its most recent rotation point, (if applicable) one page per screen, using a command such as the following from a terminal prompt:
less /var/log/rkhunter.log
Specific information may be accessed from the Rootkit Hunter Log by using such commands as grep, and less. For example, to see only information in the Rootkit Hunter Log pertaining to Warnings, you might use a command such as the following at a terminal prompt:
grep WARNING /var/log/rkhunter.log | less
Samba SMB Server Logs
The Server Message Block Protocol (SMB) server, Samba is popularly used for sharing files from your Ubuntu computer to other computers which support the SMB protocol. Samba keeps three distinct types of logs in the subdirectory /var/log/samba:
log.nmbd : Logs all messages related to Samba's NETBIOS over IP functionality (the network stuff)
log.smbd : Logs all messages related to Samba's SMB/CIFS functionality (the file, print, etc. sharing stuff)
log.[IP_ADDRESS] : Logs messages related to requests for services from the IP address contained in the log file name, for example, log.192.168.1.1.
To view all information related to Samba's networking, you could use a command such as the following at a terminal prompt:
less /var/log/samba/log.nmbd
If you wanted only to see information logged about Master Browsers, then you might use a command like this at a terminal prompt:
grep "master browser" /var/log/samba/log.nmbd | less
If you would like to see details related to the SMB functionality of Samba, you can view the appropriate log in its entirety with a command similar to the following at a terminal prompt:
less /var/log/samba/log.smbd
To see only messages related to the start up of the Samba server, a command like the following at a terminal prompt may be used:
grep started /var/log/samba/log.smbd | less
To view all the details on connections from the client system with IP address 192.168.99.99 you could use a command such as the following at a terminal prompt:
less /var/log/samba/log.192.168.99.99
X11 Server Log
The default X11 Windowing Server in use with Ubuntu is the Xorg X11 server, and assuming your computer has but one display defined, it stores log messages in the file /var/log/Xorg.0.log. This log is helpful for diagnosing issues with your X11 environment. You may examine the log, from its most recent rotation point, (if applicable) one page per screen, using a command such as the following from a terminal prompt:
less /var/log/Xorg.0.log
Specific information may be accessed from the Xorg Log by using such commands as grep, and less. For example, to see only information in the Xorg Log pertaining to the freetype font engine, you might use a command such as the following at a terminal prompt:
grep freetype /var/log/Xorg.0.log | less
Non-Human-Readable Logs
Some log files found in the /var/log subdirectory are designed to be readable by applications, and not necessarily by humans. Some examples of such log files which appear in /var/log follow.
Login Failures Log
The login failures log located at /var/log/faillog is actually designed to be parsed, and output by the faillog command. For example, to print recent login failures using the faillog command, simply enter the following at a terminal prompt:
faillog
Last Logins Log
The last logins log at /var/log/lastlog should not typically be parsed, and examined by humans, but rather should be used in conjunction with the lastlog command. For example to see a listing of logins with the lastlog command, displayed one page per screen with the less command, use the following command at a terminal prompt:
lastlog | less
Login Records Log
The file /var/log/wtmp contains login records, but unlike /var/log/lastlog above, /var/log/wtmp is not used to show a list of recent logins, but is instead used by other utilities such as the who command to present a listed of currently logged in users. For example, if you wish to see who is currently logged in on the machine you are currently using, issue the following at a terminal prompt:
who
System Logging Daemon (syslogd)
The system logging daemon, or syslogd (also known as sysklogd) is a system daemon, or special application which executes silently, in the background and does good things for your system. Specifically, syslogd awaits logging messages from numerous system, and application sources, and routes the messages to their proper target, be it a standard log file, a First In First Out (FIFO) pipe for use by a log analyzation application, or even across the network to another system's syslogd.
Messages logged to syslogd usually contain important common elements, such as system hostnames, and time-stamps in addition to the specific log information from a system source, the Linux kernel, or a user application.
Configuration of syslogd
The detailed configuration of syslogd is beyond the scope of this guide, and the reader is encouraged to seek additional information via the Resources section of this guide for information on correctly configuring, and modifying the configuration of syslogd. The file which configures the behavior of the syslogd daemon is /etc/syslog.conf and consists primarily of two fields, the selector, and the action. The selector field consists of a facility, to be logged, such as for example the auth facility which deals with authorization, and a priority, or level to log such information at, such as info, or warning priorities, which would log all messages at the informational priority and higher, or only at the warning level and higher respectively. The action field consists of a target for the log information, such as a standard log file (i.e. /var/log/syslog), or the hostname of a remote computer to send the log information to (e.g. @myotherubuntu).
The configuration file is very flexible, and powerful in nature, allowing a seemingly infinite combination of logging to take place to fit the particular requirements your installation may have.
Echoing Messages to syslogd With Logger
A neat utility exists in the logger tool, which allows one to place messages into the System Log (i.e. /var/log/syslog) arbitrarily. This is a powerful tool, which you may use in Administrative scripts, such as Perl, or shell scripts to provide them with standard logging capabilities, or you may use it just to place things in the system log as needed. For example, assume your user name is buddha, and you would like to enter a message into the syslog about a particularly delicious pizza you're eating, you could use a command such as the following at a terminal prompt:
logger This Pizza from Vinnys Gourmet Rocks
and you would find a line in the /var/log/syslog file such as this afterward:
Jan 12 23:17:02 localhost buddha: This Pizza from Vinnys Gourmet Rocks
Used in a little more professional manner in shell scripts, you can even specify a tag the messages come from, and redirect the output standard error too. This lets you have excellent error logging in a script, such as in this example snippet:
# # sample logger error jive # logmsg="/usr/bin/logger -s -t MyScript " # announce what this script is, even to the log $logmsg "Directory Checker FooScript Jive 1.0" # test for the existence of Fred's home dir on this machine if [ -d /home/fred ]; then $logmsg "I. Fred's Home Directory Found" else $logmsg "E. Fred's Home Directory was NOT Found. Boo Hoo." exit 1 fi
Executing this script as chkdir.sh on the machine butters where Fred does not have a home directory, /home/fred, gives the following results:
bumpy@butters:~$./chkdir.sh MyScript: Directory Checker FooScript Jive 1.0 MyScript: E. Fred's Home Directory was NOT Found. Boo Hoo. bumpy@butters:~$tail -n 2 /var/log/syslog Jan 12 23:23:11 localhost MyScript: Directory Checker FooScript Jive 1.0 Jan 12 23:23:11 localhost MyScript: E. Fred's Home Directory was NOT Found. Boo Hoo.
So, as you can see, we received the messages both via standard error, at the terminal prompt, and they also appear in our syslog!
Log Rotation
When viewing directory listings in /var/log or any of its subdirectories, you may encounter log files with names such as daemon.log.0, daemon.log.1.gz, and so on. What are these log files? They are 'rotated' log files. That is, they have automatically been renamed after a predefined time-frame, and a new original log started. After even more time the log files are compressed with the gzip utility as in the case of the example daemon.log.1.gz. The purpose of log rotation is to archive and compress old logs so that they consume less disk space, but are still available for inspection as needed. What handles this functionality? Why, the logrotate command of course! Typically, logrotate is called from the system-wide cron script /etc/cron.daily/logrotate, and further defined by the configuration file /etc/logrotate.conf.
This guide will not cover the myriad of ways logrotate may be configured to handle the automatic rotation of any log file on your Ubuntu system, but rather the reader is encouraged to use the Resources section of this guide, and study the requisite manual pages to determine how to configure logrotate for a particular log file, and needs.
attachment:IconsPage/IconNote.png NOTE: You may also rotate system log files via the cron.daily script /etc/cron.daily/sysklogd instead of using logrotate. Actually, the utility savelog may produce unexpected results on log rotation which configuring logrotate seems to have no effect on. In those cases, you should check the cron.daily sysklogd script in /etc/cron.daily/sysklogd and read the savelog manual page to see if savelog is not in fact doing the rotation in a way that is not what you are specifying with logrotate.
Additional Tips
Some additional tips for quickly viewing logs manually, (i.e. without a log file analyzer application) which may help you expediently locate the information you require.
Just the Beginning
You may look at just the beginning of any log file by using the head command. by default, head shows the first ten lines of any text file, so for example, if you wished to see the oldest entries in your Authorization Log file, a command such as the following could be used at a terminal prompt:
head /var/log/auth.log
If ten lines is not enough, and you need to see the first twenty-five (25) lines, then use head with the -n switch as such:
head -n 25 /var/log/auth.log
Just the End
The compliment to head of course is none other than the tail command. Can you guess what tail allows you to do? Say you need the last ten lines of the Kernel log for important messages from the kernel of late. A command such as the following entered into a terminal prompt should do:
tail /var/log/kern.log
Again, and as with head, you may get more than the default ten lines of output with tail by specifying the -n switch as such:
tail -n 30 /var/log/kern.log
to see the last thirty (30) lines of the Kernel log instead.
Real-Time Tail
Another neat use for the tail command is to use it for watching a log in 'real-time' by specifying the -f switch. For example, if you wished to watch in real-time as clients access your Apache2 server, issuing a command such as this from a terminal prompt would allow you to do so:
tail -f /var/log/apache2/access.log
You will see the log spit out, then stop, and as the Apache2 server is accessed, log entries will fly by in real-time! If you have a very busy server, they will fly by too fast for you to read them! You can use the -f switch to view any log file in this manner.
Resources
Additional information on system, and application logs, and syslogd is available via the following resources:
Local System Resources
man dmesg |
System manual page for the dmesg kernel ring buffer utility |
man faillog |
System manual page for the faillog command (and also the faillog configuration file via man 5 faillog) |
man grep |
System manual page for the grep pattern searching utility |
man head |
System manual page for the head utility |
man klogd |
System manual page for the kernel log daemon (klogd) |
man last |
System manual for the last command which shows last logged in users |
man less |
System manual page for the less paging utility |
man logger |
System manual page for the logger command-line interface to syslog utility |
man logrotate |
System manual page for the the logrotate utility |
man savelog |
System manual page for the savelog log file saving utility |
man syslogd |
System manual page for the system log daemon (syslogd) |
man syslog.conf |
System manual page for the syslogd configuration file |
man tail |
System manual page for the tail utility |
WWW Resources
[http://www.samag.com/documents/s=1146/sam0109m/0109m.htm Checking Your System Logs with awk]
[http://www.linuxvoodoo.com/resources/howtos/syslog/ Syslog - Watching Your Logs]
[http://www-128.ibm.com/developerworks/linux/library/l-roadmap5/ Windows-to-Linux roadmap: Part 5. Linux logging (IBM)]
[http://www.linuxsecurity.com/content/view/116430/151/ Sawing Linux Logs With Simple Tools]