Monit is a free open source and a very helpful program that automatically monitors and manages server process, files, directories, checksums, permissions, filesystems and services like Apache, Nginx, MySQL, FTP, SSH, Postfix and so on in a UNIX/Linux based systems and provides an excellent monitoring functionality to system administrators.
You can reduce the downtime using Monit because when any services goes down , Monit will check it and start the services automatically, example: if your dns service is down then monit will check, if found it's down then monit will start the dns service automatically. One interesting thing is that monit runs it own httpd server. If your apache server is down, monit will running using it's own server.
In this tutorial we are going to show you, how to install Monit along with CentOS Webpanel on CentOS 7.
Prerequisites:
To complete this tutorial, you will need:
1. CentOS Linux release 7.6.1810 (Core)
2. CWP7.admin , CWP version: 0.9.8.772
3. CSF Firewall
Update your YUM Repositories then Install Monit
# yum update -y
# yum install monit
Open Monit Configuration File : /etc/monitrc , Next uncomment the following section
# vi /etc/monitrc
set daemon 30 # check services at 30 seconds intervals
set log syslog
set pidfile /var/run/monit.pid
set idfile /var/.monit.id
set statefile /var/.monit.state
set mailserver localhost port 25
set eventqueue
basedir /var/monit # set the base directory where events will be stored
slots 100 # optionally limit the queue size
set alert admin@datahead.com #receive all alerts
set alert admin@datahead.com not on { instance, action }
:x (save & close)
Add the IP address, allow anyone to connect
# vi /etc/monitrc
set httpd port 2812 and
use address 0.0.0.0
allow 0.0.0.0/0.0.0.0
allow admin:monit # require user 'admin' with password 'monit'
Check Monit syntax for error
# monit -t
Control file syntax OK
Create the below file(s) if missing :
# touch /var/run/monit.pid
# touch /var/log/moinit.log
Now I will monitor some services like amavisd, clamd, crond, php-fpm & cwpsrv. Open monit Configuration file & add the below code at end of the line:Monitor CWP.amavisd
# vi /etc/monitrc
check process amavisd with pidfile /var/run/amavisd/amavisd.pid
start program "/usr/bin/systemctl start amavisd.service"
stop program "/usr/bin/systemctl stop amavisd.service"
if failed unixsocket /var/run/amavisd/amavisd.sock then restart
if cpu > 70% for 4 cycles then alert
if cpu > 90% for 8 cycles then restart
if 4 restarts within 8 cycles then timeout
Monitor CWP.clamd
# vi /etc/monitrc
check process clamd with pidfile /var/run/clamd.amavisd/clamd.pid
start program "/usr/bin/systemctl start clamd.service"
stop program "/usr/bin/systemctl stop clamd.service"
if failed unixsocket /var/run/clamd.amavisd/clamd.sock then restart
if cpu > 70% for 4 cycles then alert
if cpu > 90% for 8 cycles then restart
if 4 restarts within 8 cycles then timeout
Monitor CWP.crond
# vi /etc/monitrc
check process crond with pidfile /var/run/crond.pid
start program = "/usr/bin/systemctl start crond.service"
stop program = "/usr/bin/systemctl stop crond.service"
Monitor CWP.cwp-phpfpm
# vi /etc/monitrc
check process cwp-phpfpm matching "cwp-phpfpm"
start program "/usr/bin/systemctl start cwp-phpfpm.service"
stop program "/usr/bin/systemctl stop cwp-phpfpm.service"
if failed unixsocket /usr/local/cwp/php71/var/sockets/cwpsrv.sock then restart
if failed unixsocket /usr/local/cwp/php71/var/sockets/cwpsvc.sock then restart
if failed unixsocket /usr/local/cwp/php71/var/sockets/login.sock then restart
if cpu > 70% for 4 cycles then alert
if cpu > 90% for 8 cycles then restart
if 4 restarts within 8 cycles then timeout
Monitor cwp.cwpsrv
# vi /etc/monitrc
check process cwpsrv with pidfile /usr/local/cwpsrv/var/run/nginx.pid
start program "/usr/bin/systemctl start cwpsrv.service"
stop program "/usr/bin/systemctl stop cwpsrv.service"
if 4 restarts within 8 cycles then timeout
Open 2812 port on CSF Firewall & Restart CSF Firewall
# vi /etc/csf/csf.conf
# Allow incoming TCP ports
TCP_IN = "20,21,22,2812,25,53,80,110,143,443,465,587,993,995,2030,2031,2082,2083,2086,2087,2095,2096"
# csf -r
Once this is configured, monit should reload and reread the configuration file, and the web interface will be available:
# monit reload
Another way To Monitor:Download all the file from download link (DownLoad Link) and upload to /etc/monit.d/ directory.
Now Check Monit syntax , If no error then enable & restart monit service
# monit -t
# systemctl enable monit
# systemctl restart monit
Now check the monit log
# tail -f /var/log/monit.log
Monit Basic Command
Start monit by using the following command.
# monit
Monit daemon with PID 99008 awakened
Check the monit status.
# monit status
Reload it, to take effect of changes.
# monit reload
you can start running all of the monitored programs.
# monit start all
Restart all monit monitored service(s)
# monit restart all
Start, Stop & Restart a specific service using
# monit start httpd
# monit stop sshd
# monit restart nginx
Check Monit Summary:
Now login to your monit server using Monit username & password that you set earlier. Login URL : http://SERVER_FQDN:2812
Comments
Post a Comment
You are always welcome to comment here, but your remarks should be relevant to the conversation. To keep the exchanges focused and engaging, we reserve the right to remove off-topic comments, or self-promoting URLs and vacuous messages.
We will try to reply to your queries as soon as time allows.
Regards,
Admin