我计划使用以下配置在我的生产服务器上启用 Monit。我对 Monit 完全陌生,想听听其他人的建议,或者是否有其他指令我应该考虑根据您的经验来支持我的监控脚本。
我的服务器是 CentOS 5.6。
谢谢!
#httpd----
check process httpd with pidfile /var/run/httpd.pid
group apache
start program = "/etc/init.d/httpd start"
stop program = "/etc/init.d/httpd stop"
if failed host 127.0.0.1 port 80
protocol http then restart
if cpu > 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if 5 restarts within 5 cycles then timeout
#mysqld----
check process mysqld with pidfile /var/run/mysqld/mysqld.pid
group mysql
start program = "/etc/init.d/mysqld start"
stop program = "/etc/init.d/mysqld stop"
if failed host 127.0.0.1 port 3306 then restart
if cpu > 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if 5 restarts within 5 cycles then timeout
#postfix----
check process postfix with pidfile /var/spool/postfix/pid/master.pid
start program = "/etc/init.d/postfix start"
stop program = "/etc/init.d/postfix stop"
if cpu > 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if 5 restarts within 5 cycles then timeout
Run Code Online (Sandbox Code Playgroud)
我的 Postfix 部分中有一行用于 monit:
if failed port 25 protocol smtp then restart
Run Code Online (Sandbox Code Playgroud)
根据 Apache 提供的服务,您可以测试请求(例如,request "/monit_token"
)而不是普通的 HTTP 响应。请求可以是直接访问您的应用程序的内容,而不仅仅是静态文件。同样,这取决于你在做什么。
既然你在那里有 Postfix,你应该考虑在 Postfix 关闭的情况下,Monit 警报实际上是如何开箱即用的。在我的情况下,我正在做一个set mailserver gmail-smtp-in.l.google.com
并将邮件发送到一个 gmail 帐户,这样我就不会依赖我自己的邮件服务器的功能来向我发送警报电子邮件。我还有一个 Gmail 过滤器,可以将警报消息转发到 SMS 网关,因此我收到了一条文本。
我也有这样的配置:
check file alerttest with path /.monit_is_running
alert xxx@gmail.com with reminder on 1440 cycles
Run Code Online (Sandbox Code Playgroud)
没有文件,/.monit_is_running
因此此警报将始终大约每天触发一次。这是 monit 本身的心跳,所以我知道它正在运行(类似于“谁在监视观察者”)。这是我从 Serverfault 上的某个人那里得到的一个想法,实际上,但我不记得是谁主动的。
归档时间: |
|
查看次数: |
3038 次 |
最近记录: |