每次我重新启动 VPS 时,Dnsmasq 都无法启动

Dnsmasq fails to start every time I reboot my VPS

每次我重新启动 VPS 时,Dnsmasq 都无法启动。下面是关于它的日志。

Aug 22 18:14:51 debian dnsmasq[776]: dnsmasq: syntax check OK.
Aug 22 18:14:51 debian dnsmasq[798]: chown: invalid user: ‘dnsmasq:nogroup’
Aug 22 18:14:51 debian systemd[1]: dnsmasq.service: Control process exited, code=exited status=2
Aug 22 18:14:51 debian systemd[1]: Failed to start dnsmasq - A lightweight DHCP and caching DNS server.
Aug 22 18:14:51 debian systemd[1]: dnsmasq.service: Unit entered failed state.
Aug 22 18:14:51 debian systemd[1]: dnsmasq.service: Failed with result 'exit-code'.

我在 /etc/dnsmasq.conf 文件中正确设置了用户名和组名。我尝试重新安装 dnsmasq 然后它起作用了。但是在我重新启动 VPS 之后,它无法再次启动。那我又要重新安装了...

所以,如果我想使用 dnsmasq,我必须不重启我的 VPS。但我想知道是什么原因造成的,以及如何一劳永逸地解决它。我VPS的系统是Debian 9,内核是4.9.0-7-amd64。

终于,我找到了问题并解决了它。正如系统通知的那样,chown: invalid user: ‘dnsmasq:nogroup’ 是错误代码。我想应该是dnsmasq未能自动添加用户或组导致的错误。

一种解决方案可能是手动添加名为 "dnsmasq" 的用户。我没有尝试过,但我认为它会起作用。另一种处理方法是在相关文件中查找用户 "dnsmasq" 并将用户 "dnsmasq" 替换为现有用户 "nobody".

/etc/init.d/dnsmasq 文件中有 3 个地方需要替换。

  1. if [ ! "$DNSMASQ_USER" ]; then DNSMASQ_USER="*dnsmasq*" fi
  2. # /run may be volatile, so we need to ensure that # /run/dnsmasq exists here as well as in postinst if [ ! -d /run/dnsmasq ]; then mkdir /run/dnsmasq || return 2 chown *dnsmasq*:nogroup /run/dnsmasq || return 2 fi
  3. # /run may be volatile, so we need to ensure that # /run/dnsmasq exists here as well as in postinst if [ ! -d /run/dnsmasq ]; then mkdir /run/dnsmasq || return 2 chown *dnsmasq*:nogroup /run/dnsmasq || return 2 fi

替换上面3个强调的地方。

虽然我不确定为什么 dnsmasq 无法访问帐户文件。