如何使用Monit搭建监控系统?

时间:2023-04-01 12:20:39 

monit是一款功能强大的系统状态、进程、文件、目录和设备的监控软件,它可以自动重启那些已经挂掉的程序,非常适合监控系统关键的进程和资源,那么如何使用Monit搭建监控系统?小编带来了Monit教程,希望对你有帮助!

如何使用Monit搭建监控系统?

修改monitrc文件
在conf文件夹下
###############################################################################
## Monit control file
###############################################################################
##
## Comments begin with a '#' and extend through the end of the line. Keywords
## are case insensitive. All path's MUST BE FULLY QUALIFIED, starting with '/'.
##
## Below you will find examples of some frequently used statements. For
## information about the control file and a complete list of statements and
## options, please have a look in the Monit manual.
##
##
###############################################################################
## Global section
###############################################################################
##
## Start Monit in the background (run as a daemon):
# 1.间隔30秒检查服务
set daemon  30              # check services at 30 seconds intervals
#   with start delay 240    # optional: delay the first check by 4-minutes (by
#                           # default Monit check immediately after Monit start)
#
#
## Set syslog logging. If you want to log to a standalone log file instead,
## specify the full path to the log file
#
# set log syslog
# 2.设置日志地址
set log /root/monit/logs
#
#
## Set the location of the Monit lock file which stores the process id of the
## running Monit instance. By default this file is stored in $HOME/.monit.pid
#
# set pidfile /var/run/monit.pid
# 3.设置monit的启动端口
set pidfile /root/monit/var/monit.pid
#
## Set the location of the Monit id file which stores the unique id for the
## Monit instance. The id is generated and stored on first Monit start. By
## default the file is placed in $HOME/.monit.id.
#
# set idfile /var/.monit.id
#
## Set the location of the Monit state file which saves monitoring states
## on each cycle. By default the file is placed in $HOME/.monit.state. If
## the state file is stored on a persistent filesystem, Monit will recover
## the monitoring state across reboots. If it is on temporary filesystem, the
## state will be lost on reboot which may be convenient in some situations.
#
# set statefile /var/.monit.state
# 4.设置monit状态地址
set statefile /root/monit/var/monit.state
#

## Set limits for various tests. The following example shows the default values:
##
# set limits {
#     programOutput:     512 B,      # check program's output truncate limit
#     sendExpectBuffer:  256 B,      # limit for send/expect protocol test
#     fileContentBuffer: 512 B,      # limit for file content test
#     httpContentBuffer: 1 MB,       # limit for HTTP content test
#     networkTimeout:    5 seconds   # timeout for network I/O
#     programTimeout:    300 seconds # timeout for check program
#     stopTimeout:       30 seconds  # timeout for service stop
#     startTimeout:      30 seconds  # timeout for service start
#     restartTimeout:    30 seconds  # timeout for service restart
# }

## Set global SSL options (just most common options showed, see manual for
## full list).
#
# set ssl {
#     verify     : enable, # verify SSL certificates (disabled by default but STRONGLY RECOMMENDED)
#     selfsigned : allow   # allow self signed SSL certificates (reject by default)
# }
#
#
## Set the list of mAIl servers for alert delivery. Multiple servers may be
## specified using a comma separator. If the first mAIl server fAIls, Monit
# will use the second mAIl server in the list and so on. By default Monit uses
# port 25 - it is possible to override this with the PORT option.
#
# set mAIlserver mAIl.bar.baz,               # primary mAIlserver
#                backup.bar.baz port 10025,  # backup mAIlserver on port 10025
#                localhost                   # fallback relay
#
#
# 5.设置邮箱地址
set mAIlserver "163.com"
username "social-touch.com" password "not"
using tlsv1
with TIMEOUT 30 SECONDS
## By default Monit will drop alert events if no mAIl servers are avAIlable.
## If you want to keep the alerts for later delivery retry, you can use the
## EVENTQUEUE statement. The base directory where undelivered alerts will be
## stored is specified by the BASEDIR option. You can limit the queue size
## by using the SLOTS option (if omitted, the queue is limited by space
## avAIlable in the back end filesystem).
#
# set eventqueue
#     basedir /var/monit  # set the base directory where events will be stored
#     slots 100           # optionally limit the queue size
#
#
## Send status and events to M/Monit (for more informations about M/Monit
## see https://mmonit.com/). By default Monit registers credentials with
## M/Monit so M/Monit can smoothly communicate back to Monit and you don't
## have to register Monit credentials manually in M/Monit. It is possible to
## disable credential registration using the commented out option below.
## Though, if safety is a concern we recommend instead using https when
## communicating with M/Monit and send credentials encrypted. The password
## should be URL encoded if it contAIns URL-significant characters like
## ":", "?", "@". Default timeout is 5 seconds, you can customize it by
## adding the timeout option.
#
# set mmonit http://monit:monit@192.168.1.10:8080/collector
#     # with timeout 30 seconds              # Default timeout is 5 seconds
#     # and register without credentials     # Don't register credentials
#
#
## Monit by default uses the following format for alerts if the mAIl-format
## statement is missing::
## --8<--
## set mAIl-format {
##   from:    Monit

例子2:
# cis-ua
check process cis-ua with pidfile /data/cis/cis-ua/UserAnalysisServerV2.pid
start program = "/data/cis/cis-ua/startUserAnalysisServer.sh"
stop program = "/data/cis/cis-ua/stopUserAnalysisServer.sh"
if fAIled host mad133 port 10084
with timeout 75 seconds
then restart
group cis-ua

启动和关闭
写了几个常用的脚本,放在monit根目录下,即和bin同级的目录
start.sh(启动)
pwd=$(cd `dirname $0`; pwd)
$pwd/bin/monit -c $pwd/conf/monitrc

kill.sh(关闭)

#bin/monit -c /data/server/monit/conf/monitrc quit
kill -9 `ps -ef | grep monit/bin/monit | grep -v "grep" | awk '{print $2}' `

restart.sh(重启)
kill -9 `ps -ef | grep monit/bin/monit | grep -v "grep" | awk '{print $2}' `
sleep 3
pwd=$(cd `dirname $0`; pwd)
$pwd/bin/monit -c $pwd/conf/monitrc

macdown提供Mac软件教程,欢迎关注本站!

标签:Monit系统监控,Monit,Mac下载,Monit教程
0
投稿

猜你喜欢

  • Win7任务栏的颜色默认的并不好看如何修改

    2022-08-21 08:27:17
  • 6.2.3 将数据显示到Excel表格中

    2022-06-25 08:58:33
  • 快播如何截取GIF动态图?

    2023-03-24 04:10:12
  • word2016怎么快速制作发票? 发票word模板的使用方法

    2022-06-18 11:47:13
  • WPS 如何在word里查找文字

    2023-02-19 01:46:32
  • 如何在 Mac 上将喜欢的网站添加到 Safari?

    2023-01-27 13:12:55
  • PowerPoint制作文字不带下划线的目录式的跳转

    2022-06-27 00:27:30
  • Outlook怎么发邮件?使用Outlook发邮件的方法

    2022-01-28 08:23:26
  • WeGame版本在哪看?WeGame版本查看方法简述

    2022-04-12 14:26:40
  • 电脑版wps分享文档发生异常怎么办

    2022-08-04 21:09:43
  • iOS 16 专注模式新改进:可在到达指定位置时自动切换锁定屏幕

    2023-07-11 05:53:52
  • 电脑插入耳机检测不到没反应怎么办?

    2022-07-13 23:11:17
  • Win8系统无法打开vsd文件怎么办?

    2023-11-07 18:05:06
  • snkrs抽签多久后才能知道中没中-安卓snkrs抽签多久后才能知道中没中

    2022-12-24 03:06:07
  • WPS文字中图片怎么实现层层叠加

    2022-01-19 20:45:19
  • iOS 13.5.1 可用,Apple Pay 已支持添加八达通卡

    2023-12-11 11:40:25
  • excel怎么替换星号?Excel中替换*符号的详细方法

    2022-06-15 10:24:49
  • RavMonD.exe是什么进程?RavMonD.exe内存占用高关不掉怎么办?

    2022-02-01 09:35:43
  • Microsoft 微软官网发布Chromium版Edge浏览器预览版

    2022-02-15 16:33:40
  • Mac天真答疑「10」如何用最快的速度玩转Mac触控板手势

    2022-01-15 19:37:21
  • asp之家 电脑教程 m.aspxhome.com