Cumulus Linux 中的服务和守护进程
服务(也称为守护进程)和进程是 Linux 系统功能的核心。大多数时候,服务会自行管理;您只需启用并启动它,然后让它运行即可。但是,由于 Cumulus Linux 交换机是 Linux 系统,您可以根据需要深入研究。服务可以在运行时启动多个进程。在 Cumulus Linux 交换机上监控服务非常重要。
您可以在 Cumulus Linux 中管理服务,以识别所有活动或停止的服务以及特定服务的启动时间状态,禁用或启用特定服务,并识别活动侦听器端口。
systemd 和 systemctl 命令
您可以使用 systemctl
命令管理使用 systemd
的服务。
命令选项 | 描述 |
---|---|
status | 返回指定服务的状态。 |
start | 启动服务。 |
stop | 停止服务。 |
restart | 停止,然后启动服务,同时保持状态。如果有依赖服务或将重启服务标记为必需的服务,则其他服务也会重启。例如,运行 systemctl restart frr.service 会重启您启用并正在运行的任何路由协议服务,例如 bgpd 或 ospfd 。 |
reload | 重新加载服务的配置。 |
enable | 启用服务在系统启动时启动,但除非您使用 systemctl start SERVICENAME.service 命令或重启交换机,否则不会启动它。 |
disable | 禁用服务,但除非您使用 systemctl stop SERVICENAME.service 命令或重启交换机,否则不会停止它。您可以启动或停止已禁用的服务。 |
reenable | 禁用,然后启用服务。运行此命令,以便任何新的 Wants 或 WantedBy 行创建排序所需的符号链接。这不会影响其他服务。 |
您无需使用这些命令直接与服务交互。如果关键服务崩溃或遇到错误,systemd
会自动重启它。systemd
是现代 Linux 系统中服务的看护者,负责在启动时启动所有必要的服务。
以下示例重启网络服务
cumulus@switch:~$ sudo systemctl restart networking.service
以下示例显示所有正在运行的服务
cumulus@switch:~$ sudo systemctl status
● switch
State: running
Jobs: 0 queued
Failed: 0 units
Since: Thu 2019-01-10 00:19:34 UTC; 23h ago
CGroup: /
├─init.scope
│ └─1 /sbin/init
└─system.slice
├─haveged.service
│ └─234 /usr/sbin/haveged --Foreground --verbose=1 -w 1024
├─sysmonitor.service
│ ├─ 658 /bin/bash /usr/lib/cumulus/sysmonitor
│ └─26543 sleep 60
├─systemd-udevd.service
│ └─218 /lib/systemd/systemd-udevd
├─system-ntp.slice
│ └─ntp@mgmt.service
│ └─vrf
│ └─mgmt
│ └─12108 /usr/sbin/ntpd -n -u ntp:ntp -g
├─cron.service
│ └─274 /usr/sbin/cron -f -L 38
├─system-serial\x2dgetty.slice
│ └─serial-getty@ttyS0.service
│ └─745 /sbin/agetty -o -p -- \u --keep-baud 115200,38400,9600 ttyS0 vt220
├─nginx.service
│ ├─332 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
│ └─333 nginx: worker process
├─auditd.service
│ └─235 /sbin/auditd
├─rasdaemon.service
│ └─275 /usr/sbin/rasdaemon -f -r
├─clagd.service
│ └─11443 /usr/bin/python /usr/sbin/clagd --daemon 169.254.1.2 peerlink.4094 44:39:39:ff:40:9
--priority 100 --vxlanAnycas
├─switchd.service
│ └─430 /usr/sbin/switchd -vx
...
在 systemctl
参数之后添加服务名称。
确保服务在多次重启后启动
默认情况下,systemd
仅在给定时间间隔内尝试重启特定服务一定次数,然后服务启动失败。设置 StartLimitInterval(默认为 10 秒)和 StartBurstLimit(默认为 5 次尝试)位于服务脚本中;但是,某些服务会覆盖这些默认值,有时时间会更长。例如,switchd.service
设置 StartLimitInterval=10m 和 StartBurstLimit=3; 因此,如果您在十分钟内重启 switchd
超过三次,则它不会启动。
当重启因该原因失败时,您会看到类似于以下内容的消息
Job for switchd.service failed. See 'systemctl status switchd.service' and 'journalctl -xn' for details.
systemctl status switchd.service
显示类似于以下的输出
Active: failed (Result: start-limit) since Thu 2016-04-07 21:55:14 UTC; 15s ago
要清除此错误,请运行 systemctl reset-failed switchd.service
。如果您知道您将频繁重启(在 StartLimitInterval 内多次),您可以在发出重启请求之前运行相同的命令。这也适用于停止然后启动。
防止 systemd 服务在启动后挂起
如果您启动、重启或重新加载可以从另一个 systemd
服务启动的 systemd
服务,则必须将 --no-block
选项与 systemctl
一起使用。
识别 IPv4 和 IPv6 的活动侦听器端口
您可以使用 netstat
命令识别 IPv4 和 IPv6 下的活动侦听器端口
cumulus@switch:~$ netstat -nlp --inet --inet6
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN 444/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 874/sshd
tcp6 0 0 :::53 :::* LISTEN 444/dnsmasq
tcp6 0 0 :::22 :::* LISTEN 874/sshd
udp 0 0 0.0.0.0:28450 0.0.0.0:* 839/dhclient
udp 0 0 0.0.0.0:53 0.0.0.0:* 444/dnsmasq
udp 0 0 0.0.0.0:68 0.0.0.0:* 839/dhclient
udp 0 0 192.168.0.42:123 0.0.0.0:* 907/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 907/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 907/ntpd
udp 0 0 0.0.0.0:4784 0.0.0.0:* 909/ptmd
udp 0 0 0.0.0.0:3784 0.0.0.0:* 909/ptmd
udp 0 0 0.0.0.0:3785 0.0.0.0:* 909/ptmd
udp6 0 0 :::58352 :::* 839/dhclient
udp6 0 0 :::53 :::* 444/dnsmasq
udp6 0 0 fe80::a200:ff:fe00::123 :::* 907/ntpd
udp6 0 0 ::1:123 :::* 907/ntpd
udp6 0 0 :::123 :::* 907/ntpd
udp6 0 0 :::4784 :::* 909/ptmd
udp6 0 0 :::3784 :::* 909/ptmd
识别活动或停止的服务
要查看活动或停止的服务,请运行 cl-service-summary
命令
cumulus@switch:~$ cl-service-summary
Service cron enabled active
Service ssh enabled active
Service rsyslog enabled active
Service asic-monitor enabled inactive
Service clagd disabled active
Service cumulus-poe inactive
Service lldpd enabled active
Service mstpd enabled active
Service neighmgrd enabled active
Service netd enabled active
Service netq-agent disabled inactive
Service ntp disabled inactive
Service portwd enabled inactive
Service ptmd enabled active
Service pwmd enabled active
Service smond enabled active
Service switchd enabled active
Service sysmonitor enabled active
Service vxrd inactive
Service vxsnd inactive
Service rdnbrd disabled inactive
Service frr enabled active
Service ntp@mgmt disabled inactive
Service ntp@ntp disabled inactive
...
您还可以运行 systemctl list-unit-files --type service
命令以列出交换机上的所有服务并查看其状态
cumulus@switch:~$ systemctl list-unit-files --type service
UNIT FILE STATE VENDOR PRESET
aclinit.service enabled enabled
acltool.service enabled enabled
acpid.service disabled enabled
air-agent@.service indirect enabled
apt-daily-upgrade.service static -
apt-daily.service static -
asic-monitor.service enabled enabled
atftpd.service generated -
auditd.service enabled enabled
autovt@.service alias -
blk-availability.service enabled enabled
bmcd.service disabled enabled
bootlog.service enabled enabled
cl-system-services.service enabled enabled
clagd.service disabled enabled
clagd_rebootNotifier.service disabled enabled
console-getty.service disabled disabled
console-setup.service enabled enabled
container-getty@.service static -
containerd.service disabled enabled
cron.service enabled enabled
cryptdisks-early.service masked enabled
cryptdisks.service masked enabled
csmgrd.service enabled enabled
cumulus-aclcheck.service static -
cumulus-cleanup-health_check.service static -
cumulus-cleanup-lttng_traces.service static -
cumulus-core.service static -
...
识别基本服务
要识别交换机启动时必须运行的服务
cumulus@switch:~$ systemctl list-dependencies --before basic.target
要识别网络所需的服务
cumulus@switch:~$ systemctl list-dependencies --after network.target ● ├─switchd.service ● └─network-pre.target
要识别多用户环境所需的服务,请运行
cumulus@switch:~$ systemctl list-dependencies --before multi-user.target ● ├─bootlog.service ● ├─systemd-readahead-done.service ● ├─systemd-readahead-done.timer ● ├─systemd-update-utmp-runlevel.service ● └─graphical.target ● └─systemd-update-utmp-runlevel.service
重要服务
下表列出了 Cumulus Linux 中最重要的服务。
服务名称 | 描述 | 影响转发吗? |
---|---|---|
switchd | 硬件抽象守护进程。将内核与 ASIC 同步。 | 是 |
sx_sdk | 与 Spectrum ASIC 交互。仅在 Spectrum 交换机上。 | 是 |
frr | FRR。处理路由协议。每个路由协议都有单独的进程,例如 bgpd 和 ospfd 。 | 是(如果路由) |
clagd | Cumulus 链路聚合守护进程。处理 MLAG。 | 是(如果使用 MLAG) |
neighmgrd | 保持邻居条目刷新,如果 ARP 抑制已开启,则窥探 ARP 和 ND 数据包,并刷新 VRR MAC 地址。 | 是 |
mstpd | 生成树协议守护进程。 | 是(如果使用第 2 层) |
ptmd | 规范拓扑管理器。根据 LLDP 输出验证布线。还设置 BFD 会话。 | 是(如果使用 BFD) |
nvued | 处理 NVUE 对象模型。 | 否 |
rsyslog | 处理 syslog 消息的日志记录。 | 否 |
ntp | 网络时间协议. | 否 |
ledmgrd | LED 管理器。读取系统 LED 的状态。 | 否 |
sysmonitor | 监视和记录关键系统负载(可用内存、磁盘、CPU)。 | 否 |
lldpd | 处理 LLDP 信息的 Tx/Rx。 | 否 |
smond | 从 pwmd 读取 平台传感器和风扇信息。 | 否 |
pwmd | 读取和设置风扇速度。 | 否 |
限制服务资源
您可以为以下服务配置内存和 CPU 使用率限制,以在应用程序和用户之间分配硬件资源,从而提高整体效率。
- SNMP
- DHCP 服务器
- DHCP 中继
- NTP
- syslog
要配置 CPU 使用率限制,请运行 nv set service control <service-name-id> resource-limit cpu <percent>
命令。
以下示例配置 syslog 服务以将 CPU 使用率限制为 60%
cumulus@switch:~$ nv set service control rsyslog resource-limit cpu 60
cumulus@switch:~$ nv config apply
要配置内存使用率限制,请运行 nv set service control <service-name-id> resource-limit memory <size>
命令。
以下示例配置 DHCP 服务以将内存使用率限制为 6700M
cumulus@switch:~$ nv set service control dhcpd resource-limit memory 6700M
cumulus@switch:~$ nv config apply
值 100 配置为不对服务的 CPU 使用率进行限制。
要显示所有服务的当前 CPU 和内存使用率,请运行 nv show service control
命令
cumulus@switch:~$ nv show service control
要显示特定服务的当前 CPU 和内存使用率,请运行 nv show service control <service>
命令
cumulus@switch:~$ nv show service control rsyslog
要显示特定服务的配置资源限制,请运行 nv show service control <service-name-id> resource-limit
命令
cumulus@switch:~$ nv show service control rsyslog resource-limit