How Can Monit Help You Manage Your Linux Server?

Monit is a very popular and lightweight Linux server monitoring tool used by the system administrators around the world.It's free, it's easy to use- what's not to like. Besides monitoring, it can be used to restart programs that are misbehaving, as well as check files and directories for changes, and monitor network connections to remote servers. Monit also allows user scripts, so you can monitor whatever you ask it to (nicely)! Today we'll demonstrate a simple, but practical, script to have Monit check a MySQL process running and restart it automatically if it’s stopped or not responding! 

Installing Monit

Monit can usually be found in CentOS' official repository, so the easiest way to install Monit on your CentOS 6 server is to use yum package manager:

ServerSuit ~# yum install monit -y

Once Monit is installed, you’ll need to configure it. The configuration file is called monitrc and you can find it in /etc/monitrc directory, and we'll use it to create a monitoring config for our MySQL server, which checks if MySQL service is running every 2 minutes, and restart it if it's down.

Configuring Monit

There are three types of commands Monit accepts:

1. Set statements – these are for basic Monit settings like used ports, checks interval and log files location.


set daemon 120                    # Check services ar 2-minute intervals
set logfile /var/log/monit.log    # set log file path
set mailserver mail.ServerSuit.com # set mailserver for alert delivery
set httpd port 2812               # Run web server on port 2812	 
  allow localhost                 # Allow localhost to connect
  allow user:pass                 # require Username(user)and password(pass)

2. Include statements – it’s a good idea to keep the main files more compact and use separate config file for every service monitored, but for this exercise we have only one service, so let’s ignore these for now.

3. Service entry statements - here you can specify the programs you want to be managed by Monit.


check process mysqld with pidfile /var/run/mysqld/mysqld.pid
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout

Our Monit configuration is ready, but, of course, we gotta check the configuration file for possible syntax errors:


ServerSuit ~# monit -t	

If there aren't any errors, you're good to go!


ServerSuit ~# monit start all

Done! Now if you shutdown your MySQL server by using ‘service mysql stop’ command, you'll see that, in about 2 minutes, Monit will restart the service itself. You can check service status using the console with command ‘monit status’, or you can configure Monit web interface access in a config file. Currently, Monit is set up to allow access only from the server itself for security reasons, so you’ll need to change the config file, or use Nginx as reverse proxy server as described in our previous article.

This setup isn't really that complicated, but you can still save yourself a lot of time by using ServerSuit's software library to set up Monit!

You'll get our convenient software list when you sign up:

ServerSuit's Library of Preconfigured Linux Software

Then all you have to do is click that Monit button, and ServerSuit will push a preconfigured version of Monit to your server.

Monit discrption and automated installation

ServerSuit is free for 30-days when you first sign up, so there's literally never a bad time to try it out! Our linux server management suite is there to help you with server monitoring, account management, and a whole lot more, so check us out!

Until next time!

May 08 2016

Add or review comments

Please leave your comment

Existing comments

Comments 184


IQBAL SHAIKH
Good stuff, if needed I will use it, Thanks.
ServerSuit
Thank you, Iqbal! Hope to receive some feedback afterwards!
Amit Jadhav
I wll try.. good
Lbgsesse
best viagra sale sites <a href="http://genqpviag.com/#">viagra amex</a> buy viagra on line [url=http://genqpviag.com/]super viagra online[/url] ’
Lbgsesse
Lbgsesse
best viagra sale sites <a href="http://genqpviag.com/#">viagra amex</a> buy viagra on line [url=http://genqpviag.com/]super viagra online[/url] ’
Jdbxsesse
viagra 50mg tablets <a href="http://llviabest.com/#">cipla viagra review</a> what to say to get prescribed viagra [url=http://llviabest.com/]buy generic viagra mastercard[/url] ’
JbnbUript
canadian pharmacy <a href="http://online21rxon.com/ ">Viagra Soft Flavored</a> shoppers drug mart pharmacy
JbnbUript
JbnbUript
canadian pharmacy <a href="http://online21rxon.com/ ">Viagra Soft Flavored</a> shoppers drug mart pharmacy
Jbbvsesse
dapoxetine <a href="http://canadianpharmnorx.com/ ">canadian pharmacy no prescription</a> canadian pharmacy no prescription needed
Jbbvsesse
Jbbvsesse
dapoxetine <a href="http://canadianpharmnorx.com/ ">canadian pharmacy no prescription</a> canadian pharmacy no prescription needed
Kbcxhifs
canadian pharmacy without prescription <a href="http://xuypharmacyonline.com/">buy prescription drugs from canada</a> canadian pharmacy viagra
Kbcxhifs
Kbcxhifs
canadian pharmacy without prescription <a href="http://xuypharmacyonline.com/">buy prescription drugs from canada</a> canadian pharmacy viagra
FvfcExole
viagra patent date <a href="http://hopeviagrin.com/ ">viagra blue vision</a> wholesale generic viagra
FvfcExole
FvfcExole
viagra patent date <a href="http://hopeviagrin.com/ ">viagra blue vision</a> wholesale generic viagra
NncsExole
pharmacy discount <a href="http://lightvigra.com/ ">what\'s the difference in viagra</a> cheap viagra online canada
NncsExole
NncsExole
pharmacy discount <a href="http://lightvigra.com/ ">what\'s the difference in viagra</a> cheap viagra online canada
Lbsxsesse
canada drugs online pharmacy <a href="https://ssviagriia.com/ ">does alcohol inhibit viagra</a> canadian pharmacies shipping to usa
Fqbbsesse
cash converters small loans <a href="http://ascashapply.com/ ">payday loans moncton</a> payday loans chipley fl
Fqbbsesse
Fqbbsesse
cash converters small loans <a href="http://ascashapply.com/ ">payday loans moncton</a> payday loans chipley fl
FbsgExole
cialis <a href="http://llecialisjaw.com/ ">http://llecialisjaw.com/ </a> receive cialis overnight
FbsgExole
FbsgExole
cialis <a href="http://llecialisjaw.com/ ">http://llecialisjaw.com/ </a> receive cialis overnight
NbnhExole
price of viagra in us <a href="http://vigedon.com/ ">http://vigedon.com/ </a> cheap sildenafil citrate
NbnhExole
NbnhExole
price of viagra in us <a href="http://vigedon.com/ ">http://vigedon.com/ </a> cheap sildenafil citrate
Labxsesse
cialis o duroval <a href="https://jecialisbn.com/ ">cialis product info</a> cialis naturale alle erbe
Labxsesse
Labxsesse
cialis o duroval <a href="https://jecialisbn.com/ ">cialis product info</a> cialis naturale alle erbe
Kndnhifs
viagra samples <a href="http://viagratx.com/ ">women in viagra commercials</a> substitute for viagra
Kndnhifs
viagra samples <a href="http://viagratx.com/ ">women in viagra commercials</a> substitute for viagra
FjjuExole
FjjuExole
viagra advertisement <a href="http://viagraonlinejc.com/ ">http://viagraonlinejc.com/ </a> herbal viagra reviews
NbmoExole
cialis online <a href="http://buycialisxz.com/ ">http://buycialisxz.com/ </a> cialisorigina
NbmoExole
NbmoExole
cialis online <a href="http://buycialisxz.com/ ">http://buycialisxz.com/ </a> cialisorigina
Fbshsesse
[url=https://thesisacloud.com/]thesis writing services uk[/url] doctoral thesis help <a href="http://thesisacloud.com/ ">uk thesis</a> editing thesis
Fbshsesse
Lmoppsesse
[url=http://essaywriteris.com/]good essay writing websites[/url] top essay writers <a href="http://essaywriteris.com/ ">professional essay writers</a> best essay writing website
Lmoppsesse
Lmoppsesse
[url=http://essaywriteris.com/]good essay writing websites[/url] top essay writers <a href="http://essaywriteris.com/ ">professional essay writers</a> best essay writing website
Fbshsesse
GrvUript
Abgcsesse
[url=https://thesiswritingtob.com/]thesis abstracts[/url] writing a thesis paragraph <a href="http://thesiswritingtob.com/ ">online thesis help</a> help thesis
Brfghifs
Fbshsesse
[url=https://thesisacloud.com/]thesis statistics help[/url] thesis writing practice <a href="http://thesisacloud.com/ ">thesis writing help uk</a> thesis binding service
Fbshsesse
Fbshsesse
[url=https://thesisacloud.com/]thesis statistics help[/url] thesis writing practice <a href="http://thesisacloud.com/ ">thesis writing help uk</a> thesis binding service
Abgcsesse
Abgcsesse
[url=https://thesiswritingtob.com/]thesis paper writing[/url] thesis editing <a href="http://thesiswritingtob.com/ ">thesis to book</a> thesis topic
Fbshsesse
Abgcsesse
[url=https://thesiswritingtob.com/]thesiswritingtob.com[/url] thesis for dummies <a href="http://thesiswritingtob.com/ ">thesiswritingtob.com</a> thesis printing
Abgcsesse
Abgcsesse
[url=https://thesiswritingtob.com/]thesiswritingtob.com[/url] thesis for dummies <a href="http://thesiswritingtob.com/ ">thesiswritingtob.com</a> thesis printing
Jbsdsesse
Jbsdsesse
24 hour pharmacy [url=http://onlinecanda21.com/ ]Avalide[/url] prescription drugs from canada online
Fbsfsesse
Prozac http://uspharmus.com/ Eskalith
Fbsfsesse
Fbsfsesse
Prozac http://uspharmus.com/ Eskalith
LhdvExole
cialis egypt http://asciled.com/ buy cialis with no persciption
LhdvExole
LhdvExole
cialis egypt http://asciled.com/ buy cialis with no persciption
Lrbssesse
levitra free https://uslevitraanna.com/ buy viagra levitra
Lrbssesse
Lrbssesse
levitra free https://uslevitraanna.com/ buy viagra levitra
RfvbExole
generic cialis site:.au [url=http://cileve.com/ ]buy cialis no prescription uk[/url] cheapest cialis tadalafil 20 mg
RfvbExole
RfvbExole
generic cialis site:.au [url=http://cileve.com/ ]buy cialis no prescription uk[/url] cheapest cialis tadalafil 20 mg
GvdbUript
online pharmacy tadalafil https://boxtadafil.com/ tadalafil blood pressure
GvdbUript
GvdbUript
online pharmacy tadalafil https://boxtadafil.com/ tadalafil blood pressure
Bbdfhifs
flomax and viagra [url=https://gensitecil.com/ ]india pharmacy viagra[/url] viagra overnight delivery usa
Bbdfhifs
Bbdfhifs
flomax and viagra [url=https://gensitecil.com/ ]india pharmacy viagra[/url] viagra overnight delivery usa
Abdgsesse
canada online pharmacy https://canadianeve21.com/ canadian pharmacy without prescription
Abdgsesse
Abdgsesse
canada online pharmacy https://canadianeve21.com/ canadian pharmacy without prescription
Jbsdsesse
drugs from canada with prescription https://onlinecanda21.com/ cholesterol
Jbsdsesse
Jbsdsesse
drugs from canada with prescription https://onlinecanda21.com/ cholesterol
LhdvExole
cialis 10 mg http://asciled.com/ cialis for free
LhdvExole
LhdvExole
cialis 10 mg http://asciled.com/ cialis for free
Fbsfsesse
Fbsfsesse
online pharmacy drugstore [url=http://uspharmus.com/ ]canada drugs direct[/url] Priligy
Lrbssesse
how long does levitra 20 mg last [url=http://uslevitraanna.com/ ]levitra coupons manufacturer[/url] levitra user reviews
Lrbssesse
Lrbssesse
how long does levitra 20 mg last [url=http://uslevitraanna.com/ ]levitra coupons manufacturer[/url] levitra user reviews
Jebgsesse
online drugs http://pharmacylo.com/ canadapharmacy24h
Jebgsesse
Jebgsesse
online drugs http://pharmacylo.com/ canadapharmacy24h
GtnbUript
effects of viagra http://jokviagra.com/ viagra woman
GtnbUript
GtnbUript
effects of viagra http://jokviagra.com/ viagra woman
Fmrfsesse
cialis 80 [url=http://cialisee.com/ ]cialis mit paypal bezahlen[/url] cialis con alimentos
Fmrfsesse
Fmrfsesse
cialis 80 [url=http://cialisee.com/ ]cialis mit paypal bezahlen[/url] cialis con alimentos
LbsoExole
canadian pharmacy cialis no prescription [url=https://ucialisdas.com/ ]free sample of cialis[/url] cialis vs viagra
LbsoExole
LbsoExole
canadian pharmacy cialis no prescription [url=https://ucialisdas.com/ ]free sample of cialis[/url] cialis vs viagra
Lebnsesse
pharmacy canada https://xlnpharmacy.com/ pharmacy store
Lebnsesse
Lebnsesse
pharmacy canada https://xlnpharmacy.com/ pharmacy store
RebfExole
cialis malaysia http://rcialisgl.com/ windsor, ontario, canada pharmacy cialis
RebfExole
RebfExole
cialis malaysia http://rcialisgl.com/ windsor, ontario, canada pharmacy cialis
Bbshhifs
watermelon viagra https://loxviagra.com/ buy viagra online usa
Bbshhifs
Bbshhifs
watermelon viagra https://loxviagra.com/ buy viagra online usa
Jebgsesse
non prescription online pharmacy reviews https://pharmacylo.com/ canadian drug store
Jebgsesse
Jebgsesse
non prescription online pharmacy reviews https://pharmacylo.com/ canadian drug store
Fmrfsesse
cialis shop in australia http://cialisee.com/ cialis australia paypal
Fmrfsesse
Fmrfsesse
cialis shop in australia http://cialisee.com/ cialis australia paypal
LbsoExole
generic cialis in texas https://ucialisdas.com/ generic cialis tadalafil
LbsoExole
LbsoExole
generic cialis in texas https://ucialisdas.com/ generic cialis tadalafil
GtnbUript
is cialis better than viagra [url=http://jokviagra.com/ ]generic viagra in usa[/url] women on viagra
GtnbUript
GtnbUript
is cialis better than viagra [url=http://jokviagra.com/ ]generic viagra in usa[/url] women on viagra
Lebnsesse
Reglan http://xlnpharmacy.com/ Eulexin
Lebnsesse
Lebnsesse
Reglan http://xlnpharmacy.com/ Eulexin
Bbshhifs
levitra vs viagra [url=http://loxviagra.com/ ]online viagra[/url] how much is viagra per pill
Bbshhifs
Bbshhifs
levitra vs viagra [url=http://loxviagra.com/ ]online viagra[/url] how much is viagra per pill
Anoosesse
pourquoi utiliser du viagra https://llviagra.com/ teflon post it viagra
Anoosesse
Anoosesse
pourquoi utiliser du viagra https://llviagra.com/ teflon post it viagra
Jebgsesse
Prothiaden [url=http://pharmacylo.com/ ]buying drugs canada[/url] Epivir-HBV
Jebgsesse
Jebgsesse
Prothiaden [url=http://pharmacylo.com/ ]buying drugs canada[/url] Epivir-HBV
LbsoExole
cialis soft tabs canadian pharmacy [url=https://ucialisdas.com/ ]cialis without prescription[/url] cialis black box warning
LbsoExole
LbsoExole
cialis soft tabs canadian pharmacy [url=https://ucialisdas.com/ ]cialis without prescription[/url] cialis black box warning
Fmrfsesse
best online to buy cialis [url=http://cialisee.com/ ]where to buy cialis in singapore[/url] cialis buy onilne
Fmrfsesse
Fmrfsesse
best online to buy cialis [url=http://cialisee.com/ ]where to buy cialis in singapore[/url] cialis buy onilne
Lebnsesse
best erectile dysfunction pills [url=https://xlnpharmacy.com/ ]pharmacy cost comparison[/url] escrow pharmacy canada
Lebnsesse
best erectile dysfunction pills [url=https://xlnpharmacy.com/ ]pharmacy cost comparison[/url] escrow pharmacy canada
GtnbUript
viagra price https://jokviagra.com/ natural viagra foods
GtnbUript
GtnbUript
viagra price https://jokviagra.com/ natural viagra foods
Jebgsesse
thrifty drug store http://pharmacylo.com/ ed meds online
Jebgsesse
Jebgsesse
thrifty drug store http://pharmacylo.com/ ed meds online
Fmrfsesse
cialis switzerland [url=http://cialisee.com/ ]generiac cialis[/url] online cialis florida delivery
Fmrfsesse
Fmrfsesse
cialis switzerland [url=http://cialisee.com/ ]generiac cialis[/url] online cialis florida delivery
sesseGtv
davita rx pharmacy [url=https://pharmacyhrn.com/ ]canadian pharmacy residency[/url] canadian pharmacy british columbia
sesseGtv
sesseGtv
davita rx pharmacy [url=https://pharmacyhrn.com/ ]canadian pharmacy residency[/url] canadian pharmacy british columbia
sesseHtf
cheapest cialis on the web [url=https://cialishav.com/ ]cialis no prescriptuin[/url] buy cialis in mexico
sesseHtf
sesseHtf
cheapest cialis on the web [url=https://cialishav.com/ ]cialis no prescriptuin[/url] buy cialis in mexico
sesseDev
pharmacy rx one review <a href=https://cjepharmacy.com/>canada drugs promo code</a> most commonly abused prescription drugs
sesseDev
sesseDev
pharmacy rx one review <a href=https://cjepharmacy.com/>canada drugs promo code</a> most commonly abused prescription drugs
UriptAsd
cialis shop [url=https://cialisjla.com/ ]australia cialis on line[/url] cheap cialis tablets
UriptAsd
UriptAsd
cialis shop [url=https://cialisjla.com/ ]australia cialis on line[/url] cheap cialis tablets
ExoleVed
where to by cialis [url=https://krocialis.com/ ]fake cialis[/url] how much is cialis
ExoleVed
ExoleVed
where to by cialis [url=https://krocialis.com/ ]fake cialis[/url] how much is cialis
Exoleloh
when will cialis be sold over the counter [url=https://rcialisgl.com/ ]when does the patent on cialis expire[/url] purchase cialis australia
Exoleloh
Exoleloh
when will cialis be sold over the counter [url=https://rcialisgl.com/ ]when does the patent on cialis expire[/url] purchase cialis australia
sesseGtv
cheap drugs [url=https://pharmacyhrn.com/ ]canadian pharmacy keeps calling[/url] erectile
sesseGtv
sesseGtv
cheap drugs [url=https://pharmacyhrn.com/ ]canadian pharmacy keeps calling[/url] erectile
sesseHtf
cialis 5 mg precio [url=https://cialishav.com/ ]cialis heart attack[/url] cialis from canadian pharmacy
sesseHtf
sesseHtf
cialis 5 mg precio [url=https://cialishav.com/ ]cialis heart attack[/url] cialis from canadian pharmacy
Exoleloh
tadalafil reviews [url=https://rcialisgl.com/ ]price of cialis in pakistan[/url] cialis professionel
Exoleloh
Exoleloh
tadalafil reviews [url=https://rcialisgl.com/ ]price of cialis in pakistan[/url] cialis professionel
hifsSwa
european cialis [url=https://ckacialis.com/ ]cialis best price[/url] viagra/cialis black and gold 800
hifsSwa
hifsSwa
european cialis [url=https://ckacialis.com/ ]cialis best price[/url] viagra/cialis black and gold 800