看起来从 Ubuntu 18.04 服务将忽略文件/etc/default/snmpd
文件。
我需要snmpd
使用以下选项运行(因为我已经在中了/etc/default/snmpd
):
SNMPDOPTS='-Lsd -Lf /dev/null -I -smux,mteTrigger,mteTriggerConf -p /run/snmpd.pid udp:161,udp6:161'
但是,当我将其作为服务运行时,正在执行的操作如下:
# service snmpd status
● snmpd.service - Simple Network Management Protocol (SNMP) Daemon.
Loaded: loaded (/lib/systemd/system/snmpd.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-10-23 10:44:56 JST; 2s ago
Process: 3089 ExecStartPre=/bin/mkdir -p /var/run/agentx (code=exited, status=0/SUCCESS)
Main PID: 3091 (snmpd)
Tasks: 1 (limit: 4915)
CGroup: /system.slice/snmpd.service
└─3091 /usr/sbin/snmpd -Lsd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux mteTrigger mteTriggerConf -f
10月 23 10:44:56 example.com systemd[1]: Starting Simple Network Management Protocol (SNMP) Daemon....
10月 23 10:44:56 example.com systemd[1]: Started Simple Network Management Protocol (SNMP) Daemon..
10月 23 10:44:58 example.com snmpd[3091]: NET-SNMP version 5.7.3
我已经尝试过发布的解决方案这里:
以 root 身份(或使用 sudo)运行 systemctl edit snmpd。在该新文件中,输入:
[Service]
ExecStart=
ExecStart=/usr/sbin/snmpd -Lsd -Lf /dev/null -I -smux,mteTrigger,mteTriggerConf -p /run/snmpd.pid udp:161,udp6:161
但是当我这样做时,service snmpd status
报告:
● snmpd.service - Simple Network Management Protocol (SNMP) Daemon.
Loaded: loaded (/lib/systemd/system/snmpd.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/snmpd.service.d
└─override.conf
Active: inactive (dead) since Fri 2020-10-23 10:51:19 JST; 4s ago
Process: 14039 ExecStart=/usr/sbin/snmpd -Lsd -Lf /dev/null -I -smux,mteTrigger,mteTriggerConf -p /run/snmpd.pid udp:161,udp6:161 (code=exited, status=0/SUCCESS)
Process: 14038 ExecStartPre=/bin/mkdir -p /var/run/agentx (code=exited, status=0/SUCCESS)
Main PID: 14039 (code=exited, status=0/SUCCESS)
10月 23 10:51:17 example.com systemd[1]: Starting Simple Network Management Protocol (SNMP) Daemon....
10月 23 10:51:17 example.com systemd[1]: Started Simple Network Management Protocol (SNMP) Daemon..
10月 23 10:51:19 example.com snmpd[14063]: NET-SNMP version 5.7.3
10月 23 10:51:19 example.com snmpd[14063]: Received TERM or STOP signal... shutting down...
它似乎工作了几秒钟才无错误地退出。
如果我停止该服务并snmpd
手动启动这些选项,它可以正常工作。
我该如何修复它?
答案1
我解决了-f
在最后添加的问题(这会阻止守护进程退出):
ExecStart=/usr/sbin/snmpd -Lsd -Lf /dev/null -I -smux,mteTrigger,mteTriggerConf -p /run/snmpd.pid udp:161,udp6:161 -f