GNU/Linux >> Linux Esercitazione >  >> Linux

Utilizzo di diari di sistema per la risoluzione di problemi temporanei

La determinazione dei problemi può essere tanto un'arte quanto una scienza e, a volte, sembra che anche un po' di magia possa essere utile. Tutti hanno riscontrato situazioni in cui non è stato possibile riprodurre un errore segnalato, il che è sempre frustrante sia per l'utente che per l'amministratore di sistema. Anche gli elettrodomestici e le automobili possono essere ostinati e rifiutarsi di fallire quando si presenta la persona di servizio.

Antropomorfismo a parte, gli amministratori di sistema hanno alcuni strumenti che possono mostrare cosa è successo nei loro computer Linux con vari gradi di granularità. Ci sono strumenti, come top, htop, sguardi, sar, iotop, tcpdump, traceroute, mtr, iptraf-ng, df, du e molti altri, che possono visualizzare lo stato corrente di un host e molti dei quali possono produrre log di vari livelli di dettaglio.

Sebbene questi strumenti possano essere utilizzati per trovare problemi in corso, non sono particolarmente utili per problemi transitori o senza sintomi direttamente osservabili, almeno non osservabili fino a quando non si verifica un problema grave e possibilmente catastrofico.

Uno strumento importante che utilizzo per la determinazione dei problemi sono i registri di sistema e, con systemd, i giornali di sistema. Il diario di sistema è sempre uno dei primi strumenti a cui mi rivolgo quando risolvo un problema, in particolare i problemi che sembrano non verificarsi quando lo guardo. Mi ci è voluto molto tempo all'inizio della mia carriera di amministratore di sistema per realizzare la ricchezza di informazioni nei file di registro e questa scoperta ha notevolmente migliorato la mia velocità nella risoluzione dei problemi.

Hai già visto alcuni usi di journalctl comando in molti dei precedenti articoli di questa serie. In questo articolo, esplorerò alcuni dettagli sul diario systemd, su come funziona e su come usare journalctl per individuare e identificare i problemi.

Informazioni sui giornali

Lo scopo di qualsiasi registro o diario è mantenere una cronologia sequenziale delle normali attività dei servizi e dei programmi eseguiti su un host e registrare eventuali errori o messaggi di avviso che si verificano. I messaggi di registro venivano mantenuti in file separati in /var/log , di solito un file per il kernel e file separati per la maggior parte dei servizi in esecuzione sull'host. Sfortunatamente, l'elevato numero di file di registro potrebbe diffondere le informazioni necessarie e ritardare l'individuazione della causa principale di un problema. Ciò potrebbe richiedere particolarmente tempo quando stai cercando di determinare cosa stava succedendo in un sistema quando si è verificato un errore.

Il vecchio /var/log/dmesg file veniva solitamente utilizzato per il kernel, ma quel file è stato interrotto diversi anni fa a favore dell'utilizzo di dmesg comando per visualizzare le stesse informazioni e integrare quei messaggi (e altro) nel /var/log/messages file. Questa fusione di altri accessi ai messages file aiutava a velocizzare la determinazione dei problemi conservando gran parte dei dati in un file, ma c'erano ancora molti servizi i cui registri non erano integrati nei messages più centrali file.

Il diario systemd è progettato per raccogliere tutti i messaggi in un'unica struttura unificata in grado di mostrare un quadro completo di tutto ciò che è accaduto in un sistema in un momento o evento specifico e intorno a esso. Poiché gli eventi, indipendentemente dalla fonte, si trovano in un luogo e in una sequenza temporale, è possibile vedere a colpo d'occhio tutto ciò che accade in un punto o intervallo di tempo specifico. A mio parere, questo è uno dei principali vantaggi del journaling di sistema.

Informazioni sul diario systemd

Il servizio di journaling di sistema è implementato da systemd-journald demone. Secondo il systemd-journald pagina man:

systemd-journald è un servizio di sistema che raccoglie e archivia i dati di registrazione. Crea e mantiene giornali strutturati e indicizzati basati sulle informazioni di registrazione ricevute da una varietà di fonti:

  • Messaggi del registro del kernel, tramite kmsg
  • Semplici messaggi di registro di sistema, tramite libc syslog(3) chiama
  • Messaggi del registro di sistema strutturati tramite l'API Journal nativa, vedere sd_journal_print(3)
  • Uscita standard ed errore standard delle unità di servizio. Per ulteriori dettagli vedi sotto.
  • Record di controllo, originati dal sottosistema di controllo del kernel

Il demone raccoglierà implicitamente numerosi campi di metadati per ogni messaggio di log in modo sicuro e non falsificabile. Vedi systemd.journal-fields(7) per ulteriori informazioni sui metadati raccolti.

I dati di registro raccolti dal journal sono principalmente basati su testo ma possono anche includere dati binari ove necessario. I singoli campi che compongono un record di registro archiviato nel diario possono avere una dimensione massima di 2^64-1 byte.

Modifiche alla configurazione

Più risorse Linux

  • Comandi Linux cheat sheet
  • Cheat sheet sui comandi avanzati di Linux
  • Corso online gratuito:Panoramica tecnica RHEL
  • Cheat sheet della rete Linux
  • Cheat sheet di SELinux
  • Cheat sheet dei comandi comuni di Linux
  • Cosa sono i container Linux?
  • I nostri ultimi articoli su Linux

Il demone del journal di sistema può essere configurato usando il /etc/systemd/journald.conf file. Per molti host, questo file non necessita di modifiche perché le impostazioni predefinite sono abbastanza ragionevoli. Guarda il tuo journald.conf file ora, se non l'hai già fatto.

Le modifiche alla configurazione più comuni che potresti prendere in considerazione dovrebbero specificare la dimensione massima del file journal, il numero di file journal meno recenti e i tempi massimi di conservazione dei file. Il motivo principale per apportare tali modifiche sarebbe ridurre lo spazio di archiviazione utilizzato dal diario se si dispone di un piccolo dispositivo di archiviazione. In un ambiente mission-critical, potresti anche voler ridurre la quantità di tempo tra la sincronizzazione dei dati del journal archiviati nella memoria RAM sul dispositivo di archiviazione.

Il journald.conf la pagina man ha maggiori dettagli.

Controversie sul formato dei dati

Una delle controversie che circonda systemd è il formato binario in cui sono archiviati i contenuti del journal. Alcuni argomenti contro systemd si basano sul diario systemd archiviato in un formato binario. Questo sembrerebbe contrario alla filosofia Unix/Linux di usare il testo ASCII per i dati, che è un argomento che le persone usano per giustificare la loro antipatia per systemd. Ad esempio, Doug McIlroy, l'inventore delle pipe, ha dichiarato:

"Questa è la filosofia Unix:scrivi programmi che fanno bene una cosa. Scrivi programmi per lavorare insieme. Scrivi programmi per gestire i flussi di testo, perché questa è un'interfaccia universale". —Doug McIlroy, citato nel libro di Eric S. Raymond The Art of Unix Programming

Tuttavia, questi argomenti sembrano essere basati almeno su un malinteso parziale perché la pagina man afferma chiaramente che i dati "sono principalmente basati su testo", sebbene consenta moduli di dati binari. Linus Torvalds, creatore del kernel Linux, che è sempre chiaro sui suoi sentimenti, ha detto:

"In realtà non ho opinioni particolarmente forti su systemd stesso. Ho avuto problemi con alcuni degli sviluppatori principali che penso siano troppo sprezzanti riguardo a bug e compatibilità, e penso che alcuni dettagli di progettazione siano folli (io non mi piacciono i log binari, per esempio), ma quelli sono dettagli, non grandi problemi." —Linus Torvalds, citato in "Linus Torvalds and other on Linux's systemd" di ZDNet nel 2014

I file del journal di sistema sono archiviati in una o più sottodirectory di /var/log/journal . Accedi a un sistema di test in cui disponi dell'accesso come root e crea /var/log/journal la directory di lavoro attuale (PWD). Elenca le sottodirectory lì, scegline una e rendila PWD. Puoi guardare questi file in diversi modi. Ho iniziato con stat comando (nota che i nomi dei file journal sul tuo host saranno diversi dai miei):

[root@testvm1 3bccd1140fca488187f8a1439c832f07]# stat system@7ed846aadf1743139083681ec4042037-0000000000000001-0005a99c0280fd5f.journal
  File: system@7ed846aadf1743139083681ec4042037-0000000000000001-0005a99c0280fd5f.journal
  Size: 8388608         Blocks: 16392      IO Block: 4096   regular file
Device: fd04h/64772d    Inode: 524384      Links: 1
Access: (0640/-rw-r-----)  Uid: (    0/    root)   Gid: (  190/systemd-journal)
Access: 2020-07-13 08:30:05.764291231 -0400
Modify: 2020-07-04 07:33:52.916001110 -0400
Change: 2020-07-04 07:33:52.916001110 -0400
 Birth: -
[root@testvm1 3bccd1140fca488187f8a1439c832f07]#

Il file journal è identificato come un file "normale", che non è particolarmente utile. Il file command lo identifica come un file "journal", ma lo sai già. Guarda all'interno del file con il dd comando. Il comando seguente invia il flusso di dati di output a STDOUT; potresti volerlo reindirizzare attraverso il less cercapersone:

[root@testvm1 3bccd1140fca488187f8a1439c832f07]# dd if=system@7ed846aadf1743139083681ec4042037-0000000000000001-0005a99c0280fd5f.journal | less
<SNIP>
9�P1�8��9_SOURCE_MONOTONIC_TIMESTAMP=191726���/��P����9MESSAGE=Inode-cache hash table entries: 1048576 (order: 11, 8388608 bytes, linear)�hx
9�P1�p�9��/��P�b������9��9_SOURCE_MONOTONIC_TIMESTAMP=191825�pdXY�7p�9��9MESSAGE=mem auto-init: stack:off, heap alloc:off, heap free:off�i��
��(n�O���@Y�    �����Zս���82���7X�8�������8��DZR�����8<~B�4�<� �8tM˞8$����8��Ж��h9�&������9�����`@�9�pdXY�7b�ͺ��WV��9��9_SOURCE_MONOTONIC_TIM
ESTAMP=234745����4�h@�9��9MESSAGE=Memory: 12598028K/12963384K available (14339K kernel code, 2406K rwdata, 8164K rodata, 2468K init, 5072K b
ss, 365356K reserved, 0K cma-reserved)�j����(n�O���@Y�  ����]��m�82���7X�8�������8��DZR�����8<~B�4�<� �8tM˞8$����8��Ж��h9�&�����9�ͺ��WV��9���
4�hbB���a��^��9��9_SOURCE_MONOTONIC_TIMESTAMP=234758��3�����9��9MESSAGE=random: get_random_u64 called from __kmem_cache_create+0x3e/0x610 wi
th crng_init=0�k���(n�O���@Y�   ����j������82���7X��8C�X�Y"��8�������8��DZR�����8<~B�4�<� �8tM˞8$����8��Ж�à�9B���a���9�3���b�8�ȭ�����9h�9_SO�9h�9MESSAGE=SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1�l����(n�O���@Y�  ������z��X�82���7X�8�������8��DZR�����8<~B�4�<� �8tM˞
b�(+I)�x�9�9_SOURCE_MONOTONIC_TIMESTAMP=235444r�%/p��9�9MESSAGE=Kernel/User page tables isolation: enabled�m����(n�O���@Y�     ����k��B0��8
2���7X�8�������8��DZR�����8<~B�4�<� �8tM˞8$����8��Ж��h9�&����8�9�(+I)Ҡ�9�%/pb8O{ W���8�9��9_SOURCE_MONOTONIC_TIMESTAMP=235464u�N`�FP    M��9
��9MESSAGE=ftrace: allocating 41361 entries in 162 pages�n����(n�O���@Y�
<SNIP>

Anche questa piccola parte del flusso di dati da dd comando mostra un'interessante combinazione di testo ASCII e dati binari. Un altro strumento utile sono le strings comando, che mostra semplicemente tutte le stringhe di testo ASCII contenute in un file e ignora i dati binari:

[root@testvm1 3bccd1140fca488187f8a1439c832f07]# strings system@7ed846aadf1743139083681ec4042037-0000000000000001-0005a99c0280fd5f.journal
<SNIP>
MESSAGE=Linux version 5.7.6-201.fc32.x86_64 ([email protected]) (gcc version 10.1.1 20200507 (Red Hat 10.1.1-1) (GC
C), GNU ld version 2.34-3.fc32) #1 SMP Mon Jun 29 15:15:52 UTC 2020
MESSAGE
_BOOT_ID=6e944f99ebd9405984090f829a927fa4
_BOOT_ID
_MACHINE_ID=3bccd1140fca488187f8a1439c832f07
_MACHINE_ID
_HOSTNAME=testvm1.both.org
_HOSTNAME
PRIORITY=6
MESSAGE=Command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.7.6-201.fc32.x86_64 root=/dev/mapper/VG01-root ro resume=/dev/mapper/VG01-swap rd.lv
m.lv=VG01/root rd.lvm.lv=VG01/swap rd.lvm.lv=VG01/usr selinux=0
MESSAGE=x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
MESSAGE=x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
MESSAGE=x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
Z_g3;
MESSAGE=x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
Z_g3;
MESSAGE=x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'standard' format.
MESSAGE=BIOS-provided physical RAM map:
`k2X
MESSAGE=BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
MESSAGE=BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
MESSAGE=BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
PyLM
MESSAGE=BIOS-e820: [mem 0x0000000000100000-0x00000000dffeffff] usable
MESSAGE=BIOS-e820: [mem 0x00000000dfff0000-0x00000000dfffffff] ACPI data
MESSAGE=BIOS-e820: [mem 0x00000000fec00000-0x00000000fec00fff] reserved
MESSAGE=BIOS-e820: [mem 0x00000000fee00000-0x00000000fee00fff] reserved
MESSAGE=BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
MESSAGE=BIOS-e820: [mem 0x0000000100000000-0x00000003373fffff] usable
<SNIP>

Questi dati possono essere interpretati dagli esseri umani e questo particolare segmento sembra molto simile al flusso di dati di output da dmesg comando. Ti lascio esplorare ulteriormente da solo, ma la mia conclusione è che i file del diario sono chiaramente una miscela di testo binario e ASCII. Questo mix rende ingombrante l'uso dei tradizionali strumenti Linux basati su testo per estrarre dati utilizzabili. Ma c'è un modo migliore che offre molte possibilità per estrarre e visualizzare i dati del diario.

Informazioni su journalctl

Il journalctl comando è progettato per estrarre informazioni utilizzabili dai giornali di sistema utilizzando criteri potenti e flessibili per identificare i dati desiderati. I precedenti articoli di questa serie hanno descritto journalctl e c'è altro da sapere.

Esaminerò prima un po' e inizierò con alcune nozioni di base nel caso in cui non hai letto gli articoli precedenti o hai solo bisogno di un aggiornamento.

Puoi usare il journalctl comando senza opzioni o argomenti per visualizzare il journal di sistema che contiene tutte le informazioni del journal e del registro:

[root@testvm1 ~]# journalctl
-- Logs begin at Mon 2020-06-08 07:47:20 EDT, end at Thu 2020-07-16 10:30:43 EDT. --
Jun 08 07:47:20 testvm1.both.org kernel: Linux version 5.6.6-300.fc32.x86_64 ([email protected]) (gcc version 10.0>
Jun 08 07:47:20 testvm1.both.org kernel: Command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.6.6-300.fc32.x86_64 root=/dev/mapper/VG01-root ro >
Jun 08 07:47:20 testvm1.both.org kernel: x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
Jun 08 07:47:20 testvm1.both.org kernel: x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
Jun 08 07:47:20 testvm1.both.org kernel: x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
Jun 08 07:47:20 testvm1.both.org kernel: x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
Jun 08 07:47:20 testvm1.both.org kernel: x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'standard' format.
Jun 08 07:47:20 testvm1.both.org kernel: BIOS-provided physical RAM map:
Jun 08 07:47:20 testvm1.both.org kernel: BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
<SNIP>
Jul 16 09:51:00 testvm1.both.org NetworkManager[760]: <info>  [1594907460.1765] dhcp4 (enp0s3): option requested_routers    => '1'
Jul 16 09:51:00 testvm1.both.org NetworkManager[760]: <info>  [1594907460.1765] dhcp4 (enp0s3): option requested_static_routes => '1'
Jul 16 09:51:00 testvm1.both.org NetworkManager[760]: <info>  [1594907460.1765] dhcp4 (enp0s3): option requested_subnet_mask => '1'
Jul 16 09:51:00 testvm1.both.org NetworkManager[760]: <info>  [1594907460.1765] dhcp4 (enp0s3): option requested_time_offset => '1'
Jul 16 09:51:00 testvm1.both.org NetworkManager[760]: <info>  [1594907460.1766] dhcp4 (enp0s3): option requested_wpad       => '1'
Jul 16 09:51:00 testvm1.both.org NetworkManager[760]: <info>  [1594907460.1766] dhcp4 (enp0s3): option routers              => '192.168.0.2>
Jul 16 09:51:00 testvm1.both.org NetworkManager[760]: <info>  [1594907460.1766] dhcp4 (enp0s3): option subnet_mask          => '255.255.255>
Jul 16 09:51:00 testvm1.both.org NetworkManager[760]: <info>  [1594907460.1766] dhcp4 (enp0s3): state changed extended -> extended
Jul 16 09:51:00 testvm1.both.org systemd[1]: Starting Network Manager Script Dispatcher Service...
Jul 16 09:51:00 testvm1.both.org systemd[1]: Started Network Manager Script Dispatcher Service.
Jul 16 09:51:00 testvm1.both.org audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=NetworkManager-dispatcher com>
Jul 16 09:51:10 testvm1.both.org systemd[1]: NetworkManager-dispatcher.service: Succeeded.
Jul 16 09:51:10 testvm1.both.org audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=NetworkManager-dispatcher comm>
Jul 16 09:59:13 testvm1.both.org systemd[1]: Starting dnf makecache...
Jul 16 09:59:13 testvm1.both.org audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=dnf-makecache comm="systemd" >
Jul 16 09:59:13 testvm1.both.org audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=dnf-makecache comm="systemd" e>
Jul 16 09:59:13 testvm1.both.org systemd[1]: dnf-makecache.service: Succeeded.
Jul 16 09:59:13 testvm1.both.org systemd[1]: Finished dnf makecache.
Jul 16 09:59:14 testvm1.both.org dnf[378549]: Metadata cache refreshed recently.
Jul 16 10:00:42 testvm1.both.org systemd[1]: Starting system activity accounting tool...
Jul 16 10:00:42 testvm1.both.org systemd[1]: sysstat-collect.service: Succeeded.
Jul 16 10:00:42 testvm1.both.org audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=sysstat-collect comm="systemd>
Jul 16 10:00:42 testvm1.both.org systemd[1]: Finished system activity accounting tool.
Jul 16 10:00:42 testvm1.both.org audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=sysstat-collect comm="systemd">
Jul 16 10:01:01 testvm1.both.org CROND[378562]: (root) CMD (run-parts /etc/cron.hourly)
Jul 16 10:01:01 testvm1.both.org run-parts[378565]: (/etc/cron.hourly) starting 0anacron
Jul 16 10:01:01 testvm1.both.org run-parts[378571]: (/etc/cron.hourly) finished 0anacron

Puoi anche mostrare esplicitamente gli stessi dati dmesg comando presenta. Apri due sessioni terminali una accanto all'altra ed emetti il ​​dmesg comando in uno e il seguente comando nell'altro:

[root@testvm1 ~]# journalctl --dmesg

L'unica differenza che dovresti vedere è il formato dell'ora. Il dmesg il comando è in un formato monotono che mostra il numero di secondi dall'avvio del sistema. Il journalctl l'output è in un formato di data e ora. L'opzione monotona breve mostra il tempo trascorso dall'avvio:

[root@testvm1 ~]# journalctl --dmesg -o short-monotonic
-- Logs begin at Mon 2020-06-08 07:47:20 EDT, end at Mon 2020-07-20 13:01:01 EDT. --
[    0.000000] testvm1.both.org kernel: Linux version 5.7.6-201.fc32.x86_64 ([email protected]) (gcc version 10.1.>
[    0.000000] testvm1.both.org kernel: Command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.7.6-201.fc32.x86_64 root=/dev/mapper/VG01-root ro r>
[    0.000000] testvm1.both.org kernel: x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[    0.000000] testvm1.both.org kernel: x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[    0.000000] testvm1.both.org kernel: x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[    0.000000] testvm1.both.org kernel: x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
[    0.000000] testvm1.both.org kernel: x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'standard' format.
<snip>
[    0.000002] testvm1.both.org kernel: clocksource: kvm-clock: mask: 0xffffffffffffffff max_cycles: 0x1cd42e4dffb, max_idle_ns: 8815905914>
[    0.000005] testvm1.both.org kernel: tsc: Detected 2807.988 MHz processor
[    0.001157] testvm1.both.org kernel: e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.001159] testvm1.both.org kernel: e820: remove [mem 0x000a0000-0x000fffff] usable
[    0.001162] testvm1.both.org kernel: last_pfn = 0x24ec00 max_arch_pfn = 0x400000000
[    0.001172] testvm1.both.org kernel: MTRR default type: uncachable
[    0.001173] testvm1.both.org kernel: MTRR variable ranges disabled:
[    0.001173] testvm1.both.org kernel: Disabled
[    0.001174] testvm1.both.org kernel: x86/PAT: MTRRs disabled, skipping PAT initialization too.
[    0.001176] testvm1.both.org kernel: CPU MTRRs all blank - virtualized system.
[    0.001179] testvm1.both.org kernel: x86/PAT: Configuration [0-7]: WB  WT  UC- UC  WB  WT  UC- UC  
[    0.001182] testvm1.both.org kernel: last_pfn = 0xdfff0 max_arch_pfn = 0x400000000
[    0.001238] testvm1.both.org kernel: found SMP MP-table at [mem 0x0009fff0-0x0009ffff]
[    0.081068] testvm1.both.org kernel: RAMDISK: [mem 0x34194000-0x360c1fff]
[    0.081088] testvm1.both.org kernel: ACPI: Early table checksum verification disabled
<snip>
[   34.037575] testvm1.both.org kernel: 16:43:32.734466 main     6.1.10_Fedora r138449 started. Verbose level = 0
[   34.042209] testvm1.both.org kernel: 16:43:32.739032 main     vbglR3GuestCtrlDetectPeekGetCancelSupport: Supported (#1)
[   55.746944] testvm1.both.org kernel: e1000: enp0s3 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX
[   55.747738] testvm1.both.org kernel: IPv6: ADDRCONF(NETDEV_CHANGE): enp0s3: link becomes ready
<snip>
lines 624-681/681 (END)

Il journalctl Il comando ha molte opzioni, incluso il -o (output) opzione con diverse sottoopzioni che consentono di selezionare un formato di data e ora che soddisfi diversi insiemi di requisiti. Ne ho elencati la maggior parte di seguito, insieme a una breve descrizione che ho ampliato o modificato dal journalctl pagina man. Tieni presente che la differenza principale tra la maggior parte di questi è il formato della data e dell'ora e le altre informazioni rimangono le stesse.

formati di data e ora del giornale

  • breve: Questo è il formato predefinito e genera un output che è più simile alla formattazione dei classici file syslog, mostrando una riga per voce del diario. Questa opzione mostra i metadati del journal incluso il tempo monotono dall'avvio, il nome host completo e il nome dell'unità come kernel, DHCP, ecc.
    Jul 20 08:43:01 testvm1.both.org kernel: Inode-cache hash table entries: 1048576 (order: 11, 8388608 bytes, linear)
  • Short-full:  Questo formato è molto simile a quello predefinito ma mostra i timestamp nel formato --since= e --until= le opzioni accettano. A differenza delle informazioni sul timestamp mostrate nella modalità di output breve, questa modalità include nell'output le informazioni su giorno della settimana, anno e fuso orario ed è indipendente dalle impostazioni locali.
    Mon 2020-06-08 07:47:20 EDT testvm1.both.org kernel: x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
  • iso corto: Il formato short-iso è molto simile a quello predefinito, ma mostra i timestamp del wallclock ISO 8601.
    2020-06-08T07:47:20-0400 testvm1.both.org kernel: kvm-clock: Using msrs 4b564d01 and 4b564d00
  • iso-breve-preciso:   Questo formato è lo stesso di short-iso ma include una precisione di microsecondi completa.
    2020-06-08T07:47:20.223738-0400 testvm1.both.org kernel: Booting paravirtualized kernel on KVM
  • corto-monotonico:   Molto simile all'impostazione predefinita ma mostra timestamp monotoni invece di timestamp di wallclock.
    [    2.091107] testvm1.both.org kernel: ata1.00: ATA-6: VBOX HARDDISK, 1.0, max UDMA/133
  • breve precisione:  Anche questo formato è simile a quello predefinito ma mostra i timestamp syslog classici con la massima precisione di microsecondi.
    Jun 08 07:47:20.223052 testvm1.both.org kernel: BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
  • short-unix:  Come l'impostazione predefinita, ma mostra i secondi trascorsi dal 1 gennaio 1970, UTC invece dei timestamp di wallclock ("ora Unix"). L'ora viene mostrata con precisione al microsecondo.
    1591616840.232165 testvm1.both.org kernel: tcp_listen_portaddr_hash hash table entries: 8192
  • gatto: Genera un output molto conciso mostrando solo il messaggio di ogni voce del diario senza metadati, nemmeno un timestamp.
    ohci-pci 0000:00:06.0: irq 22, io mem 0xf0804000
  • prolisso: Questo formato mostra la struttura dei dati completa per tutti gli elementi di immissione con tutti i campi. Questa è l'opzione di formato più diversa da tutte le altre.
    Mon 2020-06-08 07:47:20.222969 EDT [s=d52ddc9f3e8f434b9b9411be2ea50b1e;i=1;b=dcb6dcc0658e4a8d8c781c21a2c6360d;m=242d7f;t=5a7912c6148f9;x=8f>
        _SOURCE_MONOTONIC_TIMESTAMP=0
        _TRANSPORT=kernel
        PRIORITY=5
        SYSLOG_FACILITY=0
        SYSLOG_IDENTIFIER=kernel
        MESSAGE=Linux version 5.6.6-300.fc32.x86_64 ([email protected]) (gcc version 10.0.1 20200328 (Red Hat 10.0.1-0>
        _BOOT_ID=dcb6dcc0658e4a8d8c781c21a2c6360d
        _MACHINE_ID=3bccd1140fca488187f8a1439c832f07
        _HOSTNAME=testvm1.both.org

Altre scelte, disponibili con -o opzione, consente di esportare i dati in vari formati come binario o JSON. Trovo anche il -x opzione illuminante perché può mostrare messaggi esplicativi aggiuntivi per alcune voci del diario. Se provi questa opzione, tieni presente che può aumentare notevolmente il flusso di dati di output. Ad esempio, le informazioni aggiuntive per una voce come:

[    4.503737] testvm1.both.org systemd[1]: Starting File System Check on /dev/mapper/VG01-root...
[    4.691555] testvm1.both.org systemd-fsck[548]: root: clean, 1813/327680 files, 48555/1310720 blocks
[    4.933065] testvm1.both.org systemd[1]: Finished File System Check on /dev/mapper/VG01-root.

si espande a questo:

[    4.503737] testvm1.both.org systemd[1]: Starting File System Check on /dev/mapper/VG01-root...
-- Subject: A start job for unit systemd-fsck-root.service has begun execution
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- A start job for unit systemd-fsck-root.service has begun execution.
--
-- The job identifier is 36.
[    4.691555] testvm1.both.org systemd-fsck[548]: root: clean, 1813/327680 files, 48555/1310720 blocks
[    4.933065] testvm1.both.org systemd[1]: Finished File System Check on /dev/mapper/VG01-root.
-- Subject: A start job for unit systemd-fsck-root.service has finished successfully
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- A start job for unit systemd-fsck-root.service has finished successfully.
--
-- The job identifier is 36

Ci sono alcune nuove informazioni qui, ma penso che il vantaggio principale sia che le informazioni sono contestualizzate per chiarire in una certa misura i concisi messaggi originali.

Il più delle volte, non è necessario o addirittura desiderabile elencare tutte le voci del diario e ricercarle manualmente. A volte cerco voci relative a un servizio specifico, altre volte cerco voci avvenute in momenti specifici. Il journalctl Il comando fornisce potenti opzioni che ti consentono di vedere solo i dati che ti interessa trovare.

Inizia con il --list-boots opzione, che elenca tutti gli stivali durante il periodo di tempo in cui esistono voci di giornale. Nota che il journalctl.conf il file può specificare che le voci del diario vengono eliminate dopo che raggiungono una certa età o dopo che lo spazio del dispositivo di archiviazione (HDD/SSD) occupato dai giornali raggiunge un importo massimo specificato:

[root@testvm1 ~]# journalctl --list-boots 
-10 dcb6dcc0658e4a8d8c781c21a2c6360d Mon 2020-06-08 07:47:20 EDT—Mon 2020-06-08 07:53:05 EDT
 -9 7d61951a85f445c5946774aaae8bc2a4 Fri 2020-07-03 15:50:06 EDT—Fri 2020-07-03 18:21:23 EDT
 -8 1b3a847577e544b4a2679fe576b62206 Fri 2020-07-03 18:21:58 EDT—Fri 2020-07-03 22:10:54 EDT
 -7 5fef01a3568743af99118107ca6f61ae Fri 2020-07-03 22:18:41 EDT—Sat 2020-07-04 06:50:19 EDT
 -6 6e944f99ebd9405984090f829a927fa4 Sat 2020-07-04 07:33:25 EDT—Sat 2020-07-04 07:58:59 EDT
 -5 ec8b0c81ca4744b1bad071bdef432959 Sat 2020-07-04 08:12:06 EDT—Sat 2020-07-04 09:12:47 EDT
 -4 cb173ec716824e21b87ccf6cb43a9a99 Sat 2020-07-04 10:19:53 EDT—Sat 2020-07-04 11:31:03 EDT
 -3 4fe354a893194409843aa9623a36dbb0 Sat 2020-07-04 07:59:58 EDT—Sun 2020-07-05 09:39:30 EDT
 -2 06fb81f1b29e4f68af9860844668446c Mon 2020-07-06 06:27:05 EDT—Mon 2020-07-13 08:50:06 EDT
 -1 33dbf8e6b9de4113a591c4f487d0ac37 Mon 2020-07-13 04:50:33 EDT—Thu 2020-07-16 13:49:32 EDT
  0 75c9b70913934748b5396b3b172bee50 Mon 2020-07-20 08:43:01 EDT—Fri 2020-07-24 12:44:06 EDT

L'ID di avvio più recente viene visualizzato in basso; è il numero esadecimale lungo e casuale. È possibile utilizzare questi dati per visualizzare i giornali per un avvio specifico. Questo può essere specificato utilizzando il numero di offset di avvio nella colonna più a sinistra o l'UUID nella seconda colonna. Questo comando visualizza il journal per l'istanza di avvio con l'offset di -2 —il secondo avvio precedente da quello attuale:

[root@testvm1 ~]# journalctl -b -2
-- Logs begin at Mon 2020-06-08 07:47:20 EDT, end at Fri 2020-07-24 12:44:06 EDT. --
Jul 06 06:27:05 testvm1.both.org kernel: Linux version 5.7.6-201.fc32.x86_64 ([email protected]) (gcc version 10.1>
Jul 06 06:27:05 testvm1.both.org kernel: Command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.7.6-201.fc32.x86_64 root=/dev/mapper/VG01-root ro >
Jul 06 06:27:05 testvm1.both.org kernel: x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
Jul 06 06:27:05 testvm1.both.org kernel: x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
<SNIP>

Or you could use the UUID for the desired boot. The offset numbers change after each boot, but the UUID does not:

[root@testvm1 ~]# journalctl -b 06fb81f1b29e4f68af9860844668446c

The -u option allows you to select specific units to examine. You can use a unit name or a pattern for matching, and you can use this option multiple times to match multiple units or patterns. In this example, I used it in combination with -b to show chronyd journal entries for the current boot:

[root@testvm1 ~]# journalctl -u chronyd -b
-- Logs begin at Mon 2020-06-08 07:47:20 EDT, end at Sun 2020-07-26 09:10:47 EDT. --
Jul 20 12:43:31 testvm1.both.org systemd[1]: Starting NTP client/server...
Jul 20 12:43:31 testvm1.both.org chronyd[811]: chronyd version 3.5 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCD>
Jul 20 12:43:31 testvm1.both.org chronyd[811]: Frequency -0.021 +/- 0.560 ppm read from /var/lib/chrony/drift
Jul 20 12:43:31 testvm1.both.org chronyd[811]: Using right/UTC timezone to obtain leap second data
Jul 20 12:43:31 testvm1.both.org systemd[1]: Started NTP client/server.
Jul 20 12:44:00 testvm1.both.org chronyd[811]: Selected source 192.168.0.52
Jul 20 12:44:00 testvm1.both.org chronyd[811]: System clock TAI offset set to 37 seconds
Jul 20 12:44:00 testvm1.both.org chronyd[811]: System clock wrong by 1.412227 seconds, adjustment started
Jul 20 12:44:01 testvm1.both.org chronyd[811]: System clock was stepped by 1.412227 seconds
[root@testvm1 ~]#

Suppose you want to look at events that were recorded between two arbitrary times. You can also use -S (--since ) and -U (--until ) to specify the beginning and ending times. The following command displays journal entries starting at 15:36:00 on July 24, 2020, through the current time:

[root@testvm1 ~]# journalctl -S "2020-07-24 15:36:00"

And this command displays all journal entries starting at 15:36:00 on July 24, 2020, until 16:00:00 on July 25:

[root@testvm1 ~]# journalctl -S "2020-07-24 15:36:00" -U "2020-07-25 16:00:00"

This command combines -S , -U , and -u to give journal entries for the NetworkManager service unit starting at 15:36:00 on July 24, 2020, until 16:00:00 on July 25:

[root@testvm1 ~]# journalctl -S "2020-07-24 15:36:00" -U "2020-07-25 16:00:00" -u NetworkManager

Some syslog facilities, such as cron, auth, mail, daemon, user, and more, can be viewed with the --facility opzione. You can use --facility=help to list the available facilities. In this example, the mail facility is not the Sendmail service that would be used for an email service, but the local client used by Linux to send email to root as event notifications. Sendmail actually has two parts, the server, which (for Fedora and related distributions) is not installed by default, and the client, which is always installed so that it can be used to deliver system emails to local recipients, especially root:

[root@testvm1 ~]# journalctl --facility=mail

The journalctl man page lists all the options that can be used to narrow searches. The table below summarizes some of the options I use most frequently. Most of these options can be used in various combinations to further narrow a search. Refer to my previous article Analyzing systemd calendar and timespans for details on creating and testing timestamps, as well as important tips like using quotes around timestamps.

Options to narrow searches of the journal

Option Description
--list-boots This displays a list of boots. The information can be used to show journal entries only for a particular boot.
-b [offset|boot ID] This specifies which boot to display information for. It includes all journal entries from that boot through shutdown or reboot.
--facility=[facility name] This specifies the facility names as they're known to syslog. Use --facility=help to list the valid facility names.
-k , --dmesg These display only kernel messages and are equivalent to using the dmesg command.
-S , --since [timestamp] These show all journal entries since (after) the specified time. They can be used with --until  to display an arbitrary range of time. Fuzzy times such as "yesterday" and "2 hours ago"—with quotes—are also allowed.
-u [unit name] The -u option allows you to select specific units to examine. You can use a unit name or a pattern for matching. This option can be used multiple times to match multiple units or patterns. 
-U , --until [timestamp] These show all journal entries until (prior to) the specified time. They can be used with --since  to display an arbitrary range of time. Fuzzy times such as "yesterday" and "2 hours ago"—with quotes—are also allowed.

Other interesting options

The journalctl program offers some other interesting options, as well. These are useful for refining the data search, specifying how the journal data is displayed, and managing the journal files.

Additional interesting journalctl options

Option Description
-f , --follow This journalctl option is similar to using the tail -f comando. It shows the most recent entries in the journal that match whatever other options have been specified and also displays new entries as they occur. This can be useful when watching for events and when testing changes.
-e , --pager-end The -e option displays the end of the data stream instead of the beginning. This does not reverse the order of the data stream, rather it causes the pager to jump to the end.
--file [journal filename] This names a specific journal file in /var/log/journal/<journal subdirectory> .
-r , --reverse This option reverses the order of the journal entries in the pager so that the newest are at the top rather than the bottom.
-n , --lines=[X] This shows the most recent X number of lines from the journal.
--utc This displays times in UTC rather than local time.
-g , --grep=[REGEX] I like the -g option because it enables me to search for specific patterns in the journal data stream. This is just like piping a text data stream through the grep comando. This option uses Perl-compatible regular expressions.
--disk-usage This option displays the amount of disk storage used by the current and archived journals. It might not be as much as you think.
--flush Journal data stored in the virtual filesystem /run/log/journal/ , which is volatile storage, is written to /var/log/journal/ which is persistent storage. This option ensures that all data is flushed to /run/log/journal/ at the time it returns.
--sync This writes all unwritten journal entries (still in RAM but not in /run/log/journal ) to the persistent filesystem. All journal entries known to the journaling system at the time the command is entered are moved to persistent storage.
--vacuum-size= --vacuum-time= --vacuum-files= These can be used singly or in combination to remove the oldest archived journal files until the specified condition is met. These options only consider archived files, and not active files, so the result might not be exactly what was specified.

I'll explore some of these entries below. More options can be found in the journalctl man page.

Journal files

If you have not already, be sure to list the files in the journal directory on your host. Remember that the name of the directory containing the journal files is a long, random number. This directory contains multiple active and archived journal files, including some for users:

[root@david ~]# cd /var/log/journal/ad8f29ed15044f8ba0458c846300c2a4/
[root@david ad8f29ed15044f8ba0458c846300c2a4]# ll
total 352308
-rw-r-----+ 1 root systemd-journal  33554432 May 28 13:07 system@0c91aaef57c441859ea5e421edff6528-0000000000000001-0005a6703120d448.journal
-rw-r-----+ 1 root systemd-journal 109051904 Jun 23 21:24 system@0c91aaef57c441859ea5e421edff6528-0000000000008238-0005a6b85e4e03c6.journal
-rw-r-----+ 1 root systemd-journal 100663296 Jul 21 18:39 system@0c91aaef57c441859ea5e421edff6528-0000000000021f3e-0005a8ca55efa66a.journal
-rw-r-----+ 1 root systemd-journal  41943040 Jul 30 09:34 system.journal
-rw-r-----+ 1 root systemd-journal   8388608 May 28 13:07 user-1000@037bcc7935234a5ea243b3af304fd08a-0000000000000c45-0005a6705ac48a3c.journal
-rw-r-----+ 1 root systemd-journal  16777216 Jun 23 21:24 user-1000@bc90cea5294447fba2c867dfe40530db-0000000000008266-0005a6b85e910761.journal
-rw-r-----+ 1 root systemd-journal  41943040 Jul 21 16:08 user-1000@bc90cea5294447fba2c867dfe40530db-0000000000021f4b-0005a8ca68c83ab7.journal
-rw-r-----+ 1 root systemd-journal   8388608 Jul 30 09:34 user-1000.journal
[root@david ad8f29ed15044f8ba0458c846300c2a4]#

You can see the user files in this listing for the user ID (UID) 1000, which is my Linux account. The --files option allows me to see the content of specified files, including the user files:

[root@david ad8f29ed15044f8ba0458c846300c2a4]# journalctl --file user-1000.journal
<SNIP>
Jul 29 14:13:32 david.both.org tumblerd[145509]: Registered thumbnailer /usr/bin/gdk-pixbuf-thumbnailer -s %s %u %o
Jul 29 14:13:32 david.both.org Thunar[2788]: ThunarThumbnailer: got 0 handle (Queue)
Jul 29 14:13:32 david.both.org Thunar[2788]: ThunarThumbnailer: got 0 handle (Error or Ready)
Jul 29 14:13:32 david.both.org Thunar[2788]: ThunarThumbnailer: got 0 handle (Finished)
Jul 29 14:15:33 david.both.org tumblerd[145552]: error: Broken zip file structure
Jul 29 14:20:34 david.both.org systemd[2466]: dbus-:[email protected]: Succeeded.
Jul 29 14:34:17 david.both.org systemd[2466]: Starting Cleanup of User's Temporary Files and Directories...
Jul 29 14:34:17 david.both.org systemd[2466]: systemd-tmpfiles-clean.service: Succeeded.
Jul 29 14:34:17 david.both.org systemd[2466]: Finished Cleanup of User's Temporary Files and Directories.
Jul 29 14:48:26 david.both.org systemd[2466]: Started dbus-:[email protected].
Jul 29 14:48:26 david.both.org tumblerd[145875]: Registered thumbnailer gsf-office-thumbnailer -i %i -o %o -s %s
<SNIP>

This output shows, among other things, temporary file cleanup for the UID1000 user. Data relating to individual users may be helpful in locating the root cause of problems originating in user space. I found a number of interesting entries in this output. Try it on your host and see what you find.

Adding journal entries

It can be useful to add your own entries to the journal. This is accomplished with the systemd-cat program that allows piping the STDOUT of a command or program to the journal. This command can be used as part of a pipeline on the command line or in a script:

[root@testvm1 ~]# echo "Hello world" | systemd-cat -p info -t myprog
[root@testvm1 ~]# journalctl -n 10
Jul 27 09:01:01 testvm1.both.org CROND[976442]: (root) CMD (run-parts /etc/cron.hourly)
Jul 27 09:01:01 testvm1.both.org run-parts[976445]: (/etc/cron.hourly) starting 0anacron
Jul 27 09:01:01 testvm1.both.org run-parts[976451]: (/etc/cron.hourly) finished 0anacron
Jul 27 09:07:53 testvm1.both.org unknown[976501]: Hello world
Jul 27 09:10:47 testvm1.both.org systemd[1]: Starting system activity accounting tool...
Jul 27 09:10:47 testvm1.both.org systemd[1]: sysstat-collect.service: Succeeded.
Jul 27 09:10:47 testvm1.both.org systemd[1]: Finished system activity accounting tool.
Jul 27 09:10:47 testvm1.both.org audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=sysstat-collect comm="systemd" exe="/usr/lib/syst>
Jul 27 09:10:47 testvm1.both.org audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=sysstat-collect comm="systemd" exe="/usr/lib/syste>
Jul 27 09:17:10 testvm1.both.org myprog[976516]: Hello world
[root@testvm1 ~]#

The -p option specifies a priority, emerg, alert, crit, err, warning, notice, info, debug, or a value between 0 and 7 that represents each of those named levels. These priority values are the same as those defined by syslog(3) . The default is info. The -t option is an identifier, which can be any arbitrary short string, such as a program or script name. This string can be used for searches by the journalctl comando:

[root@testvm1 ~]# journalctl -t myprog
-- Logs begin at Mon 2020-06-08 07:47:20 EDT, end at Mon 2020-07-27 09:21:57 EDT. --
Jul 27 09:17:10 testvm1.both.org myprog[976516]: Hello world
[root@testvm1 ~]#

Journal management

I use the --disk-usage option to check on journal sizes, along with other commands relating to disk usage, to ensure that my /var filesystem is not filling up:

[root@testvm1 ~]# journalctl --disk-usage 
Archived and active journals take up 136.0M in the file system.
[root@testvm1 ~]#

The disk usage for the journals on the testvm1 host is about 136MB. The result on my primary workstation is 328MB, and the host I use for my firewall and router uses 2.8GB for the journals. Journal sizes depend greatly on the host's use and daily run time. My physical hosts all run 24x7.

The /etc/systemd/journald.conf file can be used to configure the journal file sizes, rotation, and retention times to meet any needs not met by the default settings. You can also configure the journal storage location—you can specify a directory on the storage device or whether to store everything in RAM, which is volatile storage. If the journals are stored in RAM, they will not be persistent between boots.

The default time unit in the journald.conf file is seconds, but it can be overridden using the suffixes year , month , week , day , h , or m .

Suppose you want to limit the total amount of storage space allocated to journal files to 1GB, store all journal entries in persistent storage, keep a maximum of 10 files, and delete any journal archive files that are more than a month old. You can configure this in /etc/systemd/journald.conf using:

SystemMaxUse=1G
Storage=persistent
SystemMaxFiles=10
MaxRetentionSec=1month

By default, the SystemMaxUse is 10% of available disk space. The default settings have been fine for the systems I work with, and I have not needed to change any of them. The journald.conf man page states that the time-based settings for specifying how long to store journal entries in a single file or to retain older files are normally not necessary. This is because file number and size configurations usually force rotation and deletion of old files before any time settings might be needed.

The SystemKeepFree option ensures a specific amount of space is kept free for other data. Many databases and application programs use the /var filesystem to store data, so ensuring enough available storage space may be critical in systems with smaller hard drives and minimum space allocated to /var .

If you make changes to this configuration, be sure to monitor the results carefully for an appropriate period of time to ensure they are performing as expected.

Journal file rotation

The journal files are typically rotated automatically based upon the configuration in the /etc/systemd/journald.conf file. Files are rotated whenever one of the specified conditions is met. So if, for example, the space allocated to journal files is exceeded, the oldest file(s) is deleted, the active file is made into an archive, and a new active file is created.

Journal files can also be rotated manually. I suggest using the --flush option to ensure current data is moved to persistent storage before you run the command:

[root@testvm1 ~]# journalctl --rotate

There is another way to purge old journal files without performing a file rotation. The vacuum-size= , vacuum-files= , and vacuum-time= commands can be used to delete old archive files down to a specified total size, number of files, or prior time. The option values consider only the archive files and not the active ones, so the resulting reduction in total file size might be somewhat less than expected.

The following command purges old archive files so that only ones that are less than one month old are left. You can use the s , m , h , days , months , weeks , and years suffixes:

[root@testvm1 ~]# journalctl --vacuum-time=1month 

This command deletes all archive files except for the four most recent ones. If there are fewer than four archive files, nothing will happen, and the original number of files remains:

[root@testvm1 ~]# journalctl --vacuum-files=4

This last vacuum command deletes archive files until 200MB or less of archived files are left:

[root@testvm1 ~]# journalctl --vacuum-size=200M

Only complete files are deleted. The vacuum commands do not truncate archive files to meet the specification. They also work only on archive files, not active ones.

Pensieri finali

This article looked at using the journalctl command to extract various types of data from the systemd journal in different formats. It also explored managing journal files and how to add entries to the log from commands and scripts.

The systemd journal system provides a significant amount of metadata and context for entries compared to the old syslogd program. This additional data and the context available from the other journal entries around the time of an incident can help the sysadmin locate and resolve problems much faster than having to search multiple syslog files.

In my opinion, the journalctl command meets the Unix philosophy that programs should do one thing and do it well. The only thing journalctl does is extract data from the journal and provide many options for selecting and formatting that data. At about 85K, it is not very big. Of course, that does not include shared libraries, but those are, by definition, shared with other programs.

You should now have enough information to use the systemd journal more effectively. If you would like to know more than what I covered here, look in the man pages for journalctl and systemd-cat .

Resources

There is a great deal of information about systemd available on the internet, but much is terse, obtuse, or even misleading. In addition to the resources mentioned in this article, the following webpages offer more detailed and reliable information about systemd startup. This list has grown since I started this series of articles to reflect the research I have done.

  • DigitalOcean has a very good article about journalctl and how to view and manipulate systemd logs.
  • The Fedora Project has a good, practical guide to systemd. It has pretty much everything you need to know in order to configure, manage, and maintain a Fedora computer using systemd.
  • The Fedora Project also has a good cheat sheet that cross-references the old SystemV commands to comparable systemd ones.
  • Red Hat documentation contains a good description of the Unit file structure as well as other important information.
  • For detailed technical information about systemd and the reasons for creating it, check out Freedesktop.org's description of systemd.
  • Linux.com's "More systemd fun" offers more advanced systemd information and tips.

There is also a series of deeply technical articles for Linux sysadmins by Lennart Poettering, the designer and primary developer of systemd. These articles were written between April 2010 and September 2011, but they are just as relevant now as they were then. Much of everything else good that has been written about systemd and its ecosystem is based on these papers.

  • Rethinking PID 1
  • systemd for Administrators, Part I
  • systemd for Administrators, Part II
  • systemd for Administrators, Part III
  • systemd for Administrators, Part IV
  • systemd for Administrators, Part V
  • systemd for Administrators, Part VI
  • systemd for Administrators, Part VII
  • systemd for Administrators, Part VIII
  • systemd for Administrators, Part IX
  • systemd for Administrators, Part X
  • systemd for Administrators, Part XI

Linux
  1. Gestisci l'avvio usando systemd

  2. Inizia a utilizzare systemd come strumento di risoluzione dei problemi

  3. Risolvere i problemi utilizzando il filesystem proc su Linux

  4. Messaggi di errore "Interruzione comando emesso nexus" nel file /var/log/messages

  5. Log guardando usando coda o meno

Utilizzo di Telnet per la risoluzione dei problemi del sistema di posta

Utilizzo delle funzionalità di systemd per proteggere i servizi

Utilizzo di vmstat per risolvere i problemi di prestazioni in Linux

RabbitMQ - Ottieni messaggi da una coda usando curl

reindirizzare i log del servizio systemd su file

I log di sistema sono vuoti (/var/log/messages; /var/log/secure; ecc.)