Linux 使用supervisord而不是monit的优势是什么

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12156434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:11:36  来源:igfitidea点击:

what is the advantage of using supervisord over monit

linuxubuntumonitsupervisord

提问by murtaza52

We have a custom setup which has several daemons (web apps + background tasks) running. I am looking at using a service which helps us to monitor those daemons and restart them if their resource consumption exceeds over a level.

我们有一个自定义设置,其中运行了多个守护进程(Web 应用程序 + 后台任务)。我正在考虑使用一种服务来帮助我们监控这些守护进程并在它们的资源消耗超过某个水平时重新启动它们。

I will appreciate any insight on when one is better over the other. As I understand monit spins up a new process while supervisord starts a sub process. What is the pros and cons of this approach ?

我会很感激任何关于什么时候一个比另一个更好的见解。据我了解,monit 启动一个新进程,而 supervisord 启动一个子进程。这种方法的优缺点是什么?

I will also be using upstart to monitor monit or supervisord itself. The webapp deployment will be done using capistrano.

我还将使用 upstart 来监控 monit 或 supervisord 本身。webapp 部署将使用 capistrano 完成。

Thanks

谢谢

回答by Darek

If you want to additionally monitor resources you should settle for monit. In addition to just checking whether a process is running (availability), monit can also perform some checks of resource usage (performance, capacity usage), load levels and even basic security checks (md5sum of a bianry file, config file, etc). It has a rule-based config which is quite easy to comprehend. Also there is a lot of ready to use configs: http://mmonit.com/wiki/Monit/ConfigurationExamples

如果您想额外监控资源,您应该选择 monit。除了只检查进程是否正在运行(可用性)之外,monit 还可以对资源使用情况(性能、容量使用情况)、负载级别甚至基本安全检查(二进制文件的 md5sum、配置文件等)进行一些检查。它有一个基于规则的配置,很容易理解。还有很多准备使用的配置:http: //mmonit.com/wiki/Monit/ConfigurationExamples

Monit requires processes to create PID files, which can be a flaw, because if a process does not create pid file you have to create some wrappers around. See http://mmonit.com/wiki/Monit/FAQ#pidfile

Monit 要求进程创建 PID 文件,这可能是一个缺陷,因为如果进程不创建 pid 文件,您必须创建一些包装器。见http://mmonit.com/wiki/Monit/FAQ#pidfile

Supervisord on the other hand is more bound to a process, it spawns it by itself. It cannot make any resource based checks as monit. It has a nice CLI servicectland a web GUI though.

另一方面,Supervisord 更依赖于一个进程,它自己生成它。它不能将任何基于资源的检查作为 monit。不过,它有一个不错的 CLIservicectl和 Web GUI。

回答by cressie176

I haven't used monit but there are some significant flaws with supervisord.

我没有使用过 monit,但是 supervisord 有一些重大缺陷。

  1. Programs should run in the foreground
  1. 程序应该在前台运行

This means you can't just execute /etc/init.d/apache2 start. Most times you can just write a one liner e.g. "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND" but sometimes you need your own wrapper script. The problem with wrapper scripts is that you end up with two processes, a parent and child. See the the next flaw...

这意味着您不能只执行 /etc/init.d/apache2 start。大多数情况下,您可以只编写一行代码,例如“source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND”,但有时您需要自己的包装脚本。包装器脚本的问题在于您最终会得到两个进程,一个父进程和一个子进程。看下一个缺陷...

  1. supervisord does not manage child processes
  1. supervisord 不管理子进程

If your program starts child process, supervisord wont detect this. If the parent process dies (or if it's restarted using supervisorctl) the child processes keep running but will be "adopted" by the init process and stay running. This might prevent future invocations of your program running or consume additional resources. The recent config options stopasgroup and killasgroup are supposed to fix this, but didn't work for me.

如果您的程序启动子进程,supervisord 不会检测到这一点。如果父进程死亡(或者如果它使用 supervisorctl 重新启动),子进程会继续运行,但将被 init 进程“采用”并保持运行。这可能会阻止将来调用您的程序运行或消耗额外的资源。最近的配置选项 stopasgroup 和 killasgroup 应该可以解决这个问题,但对我不起作用。

  1. supervisord has no dependency management - see #122
  1. supervisord 没有依赖管理 - 见#122

I recently setup squid with qlproxy. qlproxyd needs to start first otherwise squid can fail. Even though both programs were managed with supervisord there was no way to ensure this. I needed to write a start script for squid that made it wait for the qlproxyd process. Adding the start script resulted in the orphaned process problem described in flaw 2

我最近用 qlproxy 设置了鱿鱼。qlproxyd 需要先启动,否则鱿鱼可能会失败。尽管这两个程序都是由 supervisord 管理的,但也无法确保这一点。我需要为鱿鱼编写一个启动脚本,让它等待 qlproxyd 进程。添加启动脚本导致了缺陷2中描述的孤立进程问题

  1. supervisord doesn't allow you to control the delay between startretries
  1. supervisord 不允许您控制 startretries 之间的延迟

Sometimes when a process fails to start (or crashes), it's because it can't get access to another resource, possibly due to a network wobble. Supervisor can be set to restart the process a number of times. Between restarts the process will enter a "BACKOFF" state but there's no documentation or control over the duration of the backoff.

有时,当一个进程无法启动(或崩溃)时,这是因为它无法访问另一个资源,可能是由于网络不稳定。主管可以设置为多次重启进程。在重新启动之间,进程将进入“BACKOFF”状态,但没有文档或控制回退的持续时间。

In its defence supervisor does meet our needs 80% of the time. The configuration is sensible and documentation pretty good.

在其国防主管确实满足我们的需求 80% 的时间。配置很合理,文档也很好。