无法让“检查主机”与 monit/Ubuntu 16.04 一起工作

无法让“检查主机”与 monit/Ubuntu 16.04 一起工作

我是 monit 的新手,我无法按照示例操作并在运行 Ubuntu 16.04 的服务器上运行。具体来说,我试图添加以下格式的“检查主机”行:

check host <subdomain.domain.com> with address <subdomain.domain.com>
  if failed port 80 protocol http 
  and request <page-name>
  with timeout 5 seconds
  then exec <command>

此语法与此处的语法类似(参见“检查主机 ftp.redhat.com”): https://linux.die.net/man/1/monit

但是,我收到了一个奇怪的错误:

There is no service named "subdomain.domain.com"

根据文档所述,此错误毫无意义,因为我正在尝试检查远程 http 地址,而不是检查服务。我不确定如何继续。

为了便于理解,我用 Golang 编写了一个微服务器,通过 nginx 从端口 80 转发请求。此进程每天会收到数百万个 http 请求。

因为进程可能会崩溃但不会停止,所以我认为检查它是否正在运行的最简单方法是访问实际的公共 URL 并确保它正在响应——当它崩溃时,我开始收到 502 错误。如果它停止运行,我只想重新启动它。我提到这一点,是因为我主要是一名开发人员,而不是服务器管理员,如果有更好的方法来确保 golang 微服务器仍在正常运行,我会很感兴趣。

答案1

检查您的 monit 版本,如果通过 apt-get 安装(在 16.04 上),则应为 5.16,而文档(截至今天)为 5.24。您可以在此处查看更新日志:https://mmonit.com/monit/changes/

如果您想安装当前版本,这里有一个很好的教程:https://guides.wp-bullet.com/install-latest-monit-ubuntu-16-04-later/

否则,这里有一个适用于旧版本的 monit-script(甚至适用于 5.6 = Ubuntu 14.04):

check host example.com with address example.com
  if failed
    url https://example.com
    timeout 10 seconds
    for 3 cycles 
  then alert

相关内容