在 Cumulus Linux 上监控接口管理状态和物理状态

问题

日志对于确定以下内容很有用:

  • 管理状态(端口/网桥/Bond 是否启动或关闭)
  • 物理状态(端口/网桥/Bond 的连接是否启动或关闭)

/var/log/ 中的当前级别不足时。

环境

  • Cumulus Linux,所有版本

解决方案

利用 ip monitor

使用 Linux ip monitor 工具来监控链路状态。

cumulus@switch:~$ ip -timestamp monitor link
  • -timestamp 命令允许您为每条消息添加时间戳
  • link 关键字指定仅关注链路更改

在后台运行

如果要在后台运行并将其重定向到日志怎么办?

Cumulus Linux 是 Linux,因此请使用 &> 重定向输出

cumulus@switch:~$ sudo sh -c "ip -timestamp monitor link > /var/log/link.log" &

前一个示例中的重定向 (>) 要求您在受重定向子句 (>) 约束的两个命令周围使用引号,以便 root 用户运行这两个命令。如果使用 root 帐户(默认在 Cumulus Linux 2.0 及更高版本上禁用),则无需这样做

root@switch:~# ip -timestamp monitor link > /var/log/link.log &

在启动时自动记录日志

如果即使在交换机重启后也希望自动记录链路活动,该怎么办?

利用位于 /etc/rc.localrc.local 启动脚本。此处 rc.local 已在 Cumulus Linux 交换机上配置

cumulus@switch:~$ cat /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
ip -timestamp monitor link > /var/log/link.log

exit 0

cumulus@switch:~$

查看日志输出

日志中管理状态与物理状态看起来有何不同?

要查看差异,请关闭并打开端口并查看日志。

cumulus@switch:~$ sudo ip link set swp1 down

cumulus@switch:~$ sudo ip link set swp1 up

cumulus@switch:~$ cat /var/log/link.log
Timestamp: Wed Jul 16 19:00:35 2014 350805 usec
3: swp1: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond24 state DOWN
    link/ether 44:38:39:00:25:d9 brd ff:ff:ff:ff:ff:ff
Timestamp: Wed Jul 16 19:00:37 2014 840831 usec
3: swp1: <NO-CARRIER,BROADCAST,MULTICAST,SLAVE,UP> mtu 1500 qdisc pfifo_fast master bond24 state DOWN
    link/ether 44:38:39:00:25:d9 brd ff:ff:ff:ff:ff:ff

/var/log/linkstate

Cumulus Linux 提供了一个链路状态日志,输出到 /var/log/linkstate,并提供了所有物理和逻辑网络链路状态更改的简明记录。特别是,输出显示物理链路和管理链路的启动/关闭更改。

之所以存在此日志,是因为链路状态更改的发生频率远低于其他记录的事件,并且单独的日志确保链路状态更改的记录持续更长时间,因为信息不会与 syslog 的其余部分一起轮换出去。

cumulus@leaf01:mgmt-vrf:~$ sudo tail /var/log/linkstate
2017-05-22T11:21:07.085595-04:00 leaf01 switchd[19517]: sync_base.c:596 swp51: ifindex 54, admin down
2017-05-22T11:21:07.086167-04:00 leaf01 switchd[19517]: sync_base.c:604 swp51: ifindex 54, oper down
2017-05-22T11:21:07.153894-04:00 leaf01 switchd[19517]: nic.c:223 nic_set_carrier: swp51: setting kernel carrier: down
2017-05-22T11:23:02.968972-04:00 leaf01 switchd[19517]: sync_base.c:596 swp51: ifindex 54, admin up
2017-05-22T11:23:05.152445-04:00 leaf01 switchd[19517]: nic.c:223 nic_set_carrier: swp51: setting kernel carrier: up
2017-05-22T11:23:05.165747-04:00 leaf01 switchd[19517]: sync_base.c:604 swp51: ifindex 54, oper up
2017-05-22T11:23:06.683631-04:00 leaf01 switchd[19517]: sync_base.c:596 swp51: ifindex 54, admin down
2017-05-22T11:23:06.684531-04:00 leaf01 switchd[19517]: sync_base.c:604 swp51: ifindex 54, oper down
2017-05-22T11:23:06.723817-04:00 leaf01 switchd[19517]: nic.c:223 nic_set_carrier: swp51: setting kernel carrier: down

管理/物理状态故障排除表

现在查看每种可能的场景,以使故障排除更容易。

管理状态物理状态ip link show 输出
启动启动swp1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 500
启动关闭swp1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 500
关闭启动swp1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 500
关闭关闭swp1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 500

请注意,管理关闭(上面的关闭/启动)和关闭/关闭看起来相同。

有关物理端口的其他故障排除,请阅读有关 双工、速度和自动协商设置 的文档。