Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@palpalani
Last active December 22, 2015 21:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save palpalani/6535839 to your computer and use it in GitHub Desktop.
Save palpalani/6535839 to your computer and use it in GitHub Desktop.
Monitor centminmod (http://centminmod.com) powered VPS or dedicated server using Moint (http://mmonit.com/monit).
//Monitor CentMinMod (https://community.centminmod.com/) server using Monit
//Mmonit 5.14 - http://mmonit.com/monit/
//How to: http://mmonit.com/wiki/Monit/HowTo
//Real-world configuration examples - http://mmonit.com/wiki/Monit/ConfigurationExamples
//Pushover notifications - http://mmonit.com/wiki/MMonit/Notification
//About Monit
Monit is a helpful program that automatically monitors and manages server programs to ensure that they not only stay online consistently, but that the file size, checksum, or permissions are always correct. Additionally monit comes with a basic web interface through which all of the processes can be set up. This tutorial will cover the most basic setup and configuration.
//Install Monit on CentOS 6.x
//STEP 1: Installation
//packages needed
yum install pam-devel
yum install openssl-devel
//STEP 2: Install Monit
cd /usr/local/src
wget http://mmonit.com/monit/dist/monit-5.14.tar.gz
tar -zxvf monit-5.14.tar.gz
cd monit-5.14
./configure (If this fails, fix as necessary, then re-unpack the tar and try again)
make
make install
//STEP 3: Setup monitrc
cp monitrc /etc/
vi /etc/monitrc
# Set the 'set daemon' line at the beginning to your preferred interval.
# At the end of monitrc add the following.
//nginx
check process nginx with pidfile /user/local/nginx/logs/nginx.pid
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
group nginx
//php-fpm
check process php-fpm with pidfile /var/run/php-fpm/php-fpm.pid
group nginx
start program = "/etc/init.d/php-fpm start"
stop program = "/etc/init.d/php-fpm stop"
if failed host localhost port 80 protocol http
and request '/phpping'
with timeout 20 seconds for 5 cycles
then restart
## If the restarts attempts fail then alert.
if 3 restarts within 5 cycles then timeout
//MySql/MariaDB
check process mysql with pidfile /var/lib/mysql/server.yourdomain.com.pid
group nginx
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed host localhost port 3306 protocol mysql then restart
if 5 restarts within 5 cycles then timeout
//STEP 4: setup the init.d file
cp contrib/rc.monit /etc/init.d/monit
chmod 755 /etc/init.d/monit
//You may need to fix the line inside the above file that's pointing at '/usr/bin/monit' to '/usr/local/bin/monit'. After this is in place you should have the 'service monit restart' command available.
//STEP 5: start Monit at boot
//edit vim '/etc/rc.d/rc.local' and add in the next line
/usr/local/bin/monit -c /etc/monitrc -p /var/run/monit.pid -l /var/log/monit.log
//STEP 6: Check
service monit status
//Optional - Enable email alert
cp monitrc /etc/
vi /etc/monitrc
set mailserver localhost, # primary mailserver
set mail-format { from: monit@YOURSERVER.com }
set alert alert@m3webware.com
//Optional - Enabling monitor status for online
cp monitrc /etc/
vi /etc/monitrc
set httpd port 2812 and
use address YOURSERVER.com
allow monit:password //SET your own username and password
In case if you installed CSF firewall, Edit 'vi /etc/csf/csf.conf' and add the port 2812 in TCP_IN and TCP_OUT. then run 'csf -r'
Finish Up
Once you have configured all of the programs that you want to run, they will be automatically tracked and restarted should they turn off.
You can control the programs through both the web interface or the command line.
Once you have set up the configuration, check the syntax:
monit -t
After resolving any possible syntax errors, you can start running all of the monitored programs.
monit start all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment