linux service monitors
文章目录
linux环境下,对进程自动监控的实现方案。
基于linux 系统的定时服务的改进
实现原理: 使用linux 提供的crontab 机制,定时查询服务器进程是否存在,如果宕机则运行重启脚本
核心代码:
|
|
开源工具
主要介绍两个 Monit 和Supervisor
Monit monitors and manages any service, and Supervisor is a nice tool for managing persistent scripts and commands without having to write init scripts for them.
- Monit
Monit is a good choice when you’re managing just a few machines, and don’t want to hassle with the complexity of something like Nagios or Chef. It works best as a single-host monitor, but it can also monitor remote services, which is useful when local services depend on them, such as database or file servers. The coolest feature is you can monitor any service, and you will see why in the configuration examples.
- Supervisor
Supervisor is a slick tool for managing scripts and commands that don’t have init scripts. It saves you from having to write your own, and it’s much easier to use than systemd.
On Debian/Ubuntu, Supervisor starts automatically after installation. Verify with ps:
|
|
Let’s take our Python hello world script
from last week to practice with. Set it up in /etc/supervisor/conf.d/helloworld.conf
:
|
|
Now Supervisor needs to re-read the conf.d/
directory, and then apply the changes:
|
|
Check your new logfiles to verify that it’s running:
|
|
supervisor是Linux下一个便利的启动和监控服务的命令。 supervisor包括两个命令:supervisord和supervisorctl,分别是后台的守护进程以及命令行管理命令。要安装这两个命令只需要执行sudo apt-get install supervisor即可。
ubuntu 18 系统下supervisor 的使用
注意事项
- 使用 apt 安装(不要使用pip,需要root 权限)
- 在 conf.d 文件夹下 创建自己的配置文件
查询命令
我们可以检查一下 Supervisor 状态。
|
|
其次检查守护的进程的状态:
|
|
文章作者 jijeng
上次更新 2020-02-18