如何使用Monit搭建监控系统?
时间:2023-04-01 12:20:39
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软件教程,欢迎关注本站!