使用 NVUE 的日志文件

NVUE 提供命令来显示当前系统日志配置,显示交换机上日志文件的内容,以及删除日志文件。

显示系统日志配置

要显示交换机上当前的系统日志配置,请运行 nv show system log 命令

cumulus@switch:~$ nv show system log
            operational      
-----------  -----------------
[file]       syslog           
[component]  apt              
[component]  audit            
[component]  auth             
[component]  boot             
[component]  csmgr            
[component]  datapath         
[component]  dpkg             
[component]  ifupdown2        
[component]  installer        
[component]  mlag             
[component]  nginx            
[component]  nvue             
[component]  otlp-telemetry   
[component]  platform-phc     
[component]  platform-thermal 
[component]  pps              
[component]  ptm              
[component]  ptp              
[component]  ptp-firefly-servo
[component]  routing          
[component]  stp              
[component]  synce

显示系统日志文件

要显示最新系统日志文件的内容,请运行 nv show system log file 命令

cumulus@switch:~$ nv show system log file
2025-01-15T11:59:20.314123+00:00 cumulus systemd-modules-load[322]: Inserted module 'loop'
2025-01-15T11:59:20.314357+00:00 cumulus systemd-random-seed[331]: Kernel entropy pool is not initialized yet, waiting until it is.
2025-01-15T11:59:20.314386+00:00 cumulus systemd-modules-load[322]: Inserted module 'bonding'
2025-01-15T11:59:20.314396+00:00 cumulus systemd[1]: Starting systemd-journal-flush.service - Flush Journal to Persistent Storage...
2025-01-15T11:59:20.314438+00:00 cumulus systemd[1]: modprobe@drm.service: Deactivated successfully.
2025-01-15T11:59:20.314448+00:00 cumulus systemd[1]: Finished modprobe@drm.service - Load Kernel Module drm.
2025-01-15T11:59:20.314456+00:00 cumulus systemd-modules-load[322]: Inserted module 'bridge'
2025-01-15T11:59:20.314464+00:00 cumulus systemd-modules-load[322]: Inserted module 'br_netfilter'
2025-01-15T11:59:20.314472+00:00 cumulus systemd[1]: Finished systemd-journal-flush.service - Flush Journal to Persistent Storage.
2025-01-15T11:59:20.314486+00:00 cumulus systemd-modules-load[322]: Inserted module 'tun'
2025-01-15T11:59:20.314494+00:00 cumulus systemd-modules-load[322]: Inserted module 'at24'
2025-01-15T11:59:20.314502+00:00 cumulus systemd[1]: Finished systemd-random-see/var/log/syslog
...

nv show system log file 命令提供以下选项

选项描述
brief以更简洁的格式显示最新系统日志文件的内容。
follow实时显示系统日志文件的内容。此命令持续显示日志文件输出,并在更新时显示,类似于 tail -f 命令的行为。
list显示系统上可用的系统日志文件及其文件名和对应的文件路径。
<file-name>显示特定系统日志文件的内容。

以下示例显示最新系统日志文件的内容

cumulus@switch:~$ nv show system log file
2025-01-15T11:59:20.314123+00:00 cumulus systemd-modules-load[322]: Inserted module 'loop'
2025-01-15T11:59:20.314357+00:00 cumulus systemd-random-seed[331]: Kernel entropy pool is not initialized yet, waiting until it is.
2025-01-15T11:59:20.314386+00:00 cumulus systemd-modules-load[322]: Inserted module 'bonding'
2025-01-15T11:59:20.314396+00:00 cumulus systemd[1]: Starting systemd-journal-flush.service - Flush Journal to Persistent Storage...
2025-01-15T11:59:20.314438+00:00 cumulus systemd[1]: modprobe@drm.service: Deactivated successfully.
2025-01-15T11:59:20.314448+00:00 cumulus systemd[1]: Finished modprobe@drm.service - Load Kernel Module drm.
2025-01-15T11:59:20.314456+00:00 cumulus systemd-modules-load[322]: Inserted module 'bridge'
2025-01-15T11:59:20.314464+00:00 cumulus systemd-modules-load[322]: Inserted module 'br_netfilter'
2025-01-15T11:59:20.314472+00:00 cumulus systemd[1]: Finished systemd-journal-flush.service - Flush Journal to Persistent Storage.
2025-01-15T11:59:20.314486+00:00 cumulus systemd-modules-load[322]: Inserted module 'tun'
2025-01-15T11:59:20.314494+00:00 cumulus systemd-modules-load[322]: Inserted module 'at24'
...

以下示例以更简洁的格式显示最新系统日志文件的内容

cumulus@switch:~$ nv show system log file brief
2025-01-15T11:59:20.314123+00:00 cumulus systemd-modules-load[322]: Inserted module 'loop'
2025-01-15T11:59:20.314357+00:00 cumulus systemd-random-seed[331]: Kernel entropy pool is not initialized yet, waiting until it is.
2025-01-15T11:59:20.314386+00:00 cumulus systemd-modules-load[322]: Inserted module 'bonding'
2025-01-15T11:59:20.314396+00:00 cumulus systemd[1]: Starting systemd-journal-flush.service - Flush Journal to Persistent Storage...
2025-01-15T11:59:20.314438+00:00 cumulus systemd[1]: modprobe@drm.service: Deactivated successfully.
2025-01-15T11:59:20.314448+00:00 cumulus systemd[1]: Finished modprobe@drm.service - Load Kernel Module drm.
2025-01-15T11:59:20.314456+00:00 cumulus systemd-modules-load[322]: Inserted module 'bridge'
2025-01-15T11:59:20.314464+00:00 cumulus systemd-modules-load[322]: Inserted module 'br_netfilter'
...

以下示例实时显示最新系统日志文件的内容

cumulus@switch:~$ nv show system log file follow
2025-01-16T22:00:08.749566+00:00 leaf01 sshd[17758]: pam_unix(sshd:session): session closed for user cumulus
2025-01-16T22:00:19.589388+00:00 leaf01 sshd[18387]: Accepted publickey for cumulus from 192.168.200.1 port 39400 ssh2: RSA SHA256:l/CnwXBKo6zp1gdL48W0Qpntk4wpJuV0567K+sPF66w
2025-01-16T22:00:19.590984+00:00 leaf01 sshd[18387]: pam_unix(sshd:session): session opened for user cumulus(uid=1000) by (uid=0)
2025-01-16T22:00:19.626551+00:00 leaf01 sshd[18387]: pam_env(sshd:session): deprecated reading of user environment enabled
2025-01-16T22:00:29.900648+00:00 leaf01 sudo:  cumulus : TTY=pts/0 ; PWD=/var/home/cumulus ; USER=root ; COMMAND=/usr/bin/nv show system log file brief
2025-01-16T22:00:30.525635+00:00 leaf01 systemd[1]: mnt-air.mount: Deactivated successfully.
2025-01-16T22:01:00.534717+00:00 leaf01 systemd[1]: mnt-air.mount: Deactivated successfully.
2025-01-16T22:01:30.544233+00:00 leaf01 systemd[1]: mnt-air.mount: Deactivated successfully.
...

以下示例显示系统上可用的系统日志文件及其文件名和对应的文件路径

cumulus@switch:~$ nv show system log file list
File name  File path      
---------  ---------------
syslog     /var/log/syslog

以下示例显示 syslog 文件的内容

cumulus@switch:~$ nv show system log file syslog
2025-01-15T11:59:20.314123+00:00 cumulus systemd-modules-load[322]: Inserted mod
ule 'loop'
2025-01-15T11:59:20.314357+00:00 cumulus systemd-random-seed[331]: Kernel entropy pool is not initialized yet, waiting until it is.
2025-01-15T11:59:20.314386+00:00 cumulus systemd-modules-load[322]: Inserted module 'bonding'
2025-01-15T11:59:20.314396+00:00 cumulus systemd[1]: Starting systemd-journal-flush.service - Flush Journal to Persistent Storage...
2025-01-15T11:59:20.314438+00:00 cumulus systemd[1]: modprobe@drm.service: Deactivated successfully.
2025-01-15T11:59:20.314448+00:00 cumulus systemd[1]: Finished modprobe@drm.service - Load Kernel Module drm.
2025-01-15T11:59:20.314456+00:00 cumulus systemd-modules-load[322]: Inserted module 'bridge'
2025-01-15T11:59:20.314464+00:00 cumulus systemd-modules-load[322]: Inserted module 'br_netfilter'
...

显示生成日志的组件

要显示系统生成日志的组件,请运行 nv show system log component 命令。

cumulus@switch:~$ nv show system log component 
Component          Summary
-----------------  -------
apt                       
audit                     
auth                      
boot                      
csmgr                     
datapath                  
dpkg                      
ifupdown2                 
installer                 
mlag                      
nginx                     
nvue                      
otlp-telemetry            
platform-phc              
platform-thermal          
pps                       
ptm                       
ptp                       
ptp-firefly-servo         
routing                   
stp                       
synce

nv show system log component 命令提供以下选项

选项描述
<component-name> file显示特定组件的最新文件的内容。
<component-name> file list提供指定组件的日志文件列表,并显示关联的日志。
组件文件列表

以下示例显示 NVUE 的最新日志文件的内容

cumulus@switch:~$ nv show system log component nvue file
2025-01-15T11:59:23.648913+00:00 cumulus nvued:    INFO: nvued:214 Starting nvued
2025-01-15T11:59:23.649568+00:00 cumulus nvued:    INFO: nvued:216 NVUE logging set to INFO, chatty deps set to INFO
2025-01-15T11:59:23.650005+00:00 cumulus nvued:    INFO: nvued:171 Attempting to extend the SystemD start/stop timeout on Cumulus/VX platform to 15 minutes
2025-01-15T11:59:23.650327+00:00 cumulus nvued:    INFO: nvued:184 Successfully sent request to SystemD to extend start timeout: True
2025-01-15T11:59:23.692508+00:00 cumulus nvued:    INFO: _access.py:137 Loaded /etc/nvue-auth.yaml
2025-01-15T11:59:23.768857+00:00 cumulus nvued:    INFO: safe_sh.py:108 <Running: '/usr/bin/platform-detect'>
2025-01-15T11:59:23.826070+00:00 cumulus nvued:    INFO: safe_sh.py:195 <Finished: '/usr/bin/platform-detect'>
2025-01-15T11:59:23.826338+00:00 cumulus nvued:    INFO: osinfo.py:298 Platform name vx
...

以下示例显示 NVUE 的日志文件和关联的日志

cumulus@switch:~$ nv show system log component nvue file list
File name    File path           
-----------  --------------------
nv-cli.log   /var/log/nv-cli.log 
nvued.log    /var/log/nvued.log  
nvued.log.1  /var/log/nvued.log.1

删除系统日志文件

删除日志文件使您能够管理存储空间并确保只保留相关的日志。您通常在上传或存档日志文件后,或者当您不再需要日志文件进行故障排除或审计时删除日志文件。日志文件删除是日志管理中的关键步骤,以确保过时或不相关的数据不会占用系统资源。

要删除日志文件,请运行 nv action delete system log file <file-name> 命令

cumulus@switch:~$ nv action delete system log file mstpd.log 

要从特定系统组件中删除日志文件,请运行 nv action delete system log component <component-name> file <file-name> 命令

cumulus@switch:~$ nv action delete system log component nvue file nvued.log

轮换系统日志文件

要轮换系统日志文件

cumulus@switch:~$ nv action rotate system log
Action executing ...
Log rotation successful
Action succeeded

Cumulus Linux 会自动管理日志文件大小,防止日志填满存储空间并减慢系统速度。