What is Monit?
Monit is a free, open-source process supervision tool for Unix and Linux. With Monit, system status can be viewed directly from the command line, or via the native HTTP web server. Monit is able to do automatic maintenance, repair, and run meaningful causal actions in error situations.
How To Install Monit on CentOS 7 / Debian 11
##For CentOS 7
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install monit
##
##For Debian 11
apt-get update
apt-get -y install monit
cp /etc/monit/monitrc /etc/monit/monitrc_bkp
nano /etc/monit/monitrc
##Copy paste##
####Copy from here#####
###############################################################################
## 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
###############################################################################
set daemon 120 # check services at 2-minute intervals
set logfile /var/log/monit.log
set idfile /var/lib/monit/id
set statefile /var/lib/monit/state
set mailserver localhost # primary mailserver
set eventqueue
basedir /var/lib/monit/events # set the base directory where events will be stored
slots 100 # optionally limit the queue size
set mail-format {
subject: monit alert on {your servername or IP} -- $EVENT $SERVICE
}
set alert icallify.logs@gmail.com
include /etc/monit/conf.d/*
include /etc/monit/conf-enabled/*
## Chekck mariadb service running status
check process mysqld with pidfile /var/run/mysqld/mysql.pid
start program = "/bin/systemctl start mariadb"
stop program = "/bin/systemctl stop mariadb"
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout
## Check fail2ban service running status
check process fail2ban with pidfile /var/run/fail2ban/fail2ban.pid
start program = "/bin/systemctl start fail2ban"
stop program = "/bin/systemctl stop fail2ban"
## Check asterisk service running status
check process asterisk with pidfile /var/run/asterisk/asterisk.pid
start program = "/bin/systemctl start asterisk"
stop program = "/bin/systemctl stop asterisk"
## Check apache service running service status
check process apache2 with pidfile /var/run/apache2/apache2.pid
start program = "/bin/systemctl start apache2" with timeout 30 seconds
stop program = "/bin/systemctl stop apache2"
## Check overall system performance
check system localhost
if loadavg (5min) > 8 for 4 cycles then alert
if loadavg (15min) > 8 for 4 cycles then alert
if memory usage > 80% for 4 cycles then alert
if swap usage > 20% for 4 cycles then alert
if cpu usage (user) > 80% for 4 cycles then alert
if cpu usage (system) > 20% for 4 cycles then alert
if cpu usage (wait) > 20% for 4 cycles then alert
check filesystem "root" with path /
if space usage > 80% for 1 cycles then alert
######EOF##########
#Logrotaion configuration
sed -i -e 's/weekly/size 30M/g' /etc/logrotate.d/monit
#Enable service on startup
systemctl restart monit
systemctl enable monit
Comments
Post a Comment