How to install Monit monitoring software on CentOS Webpanel (CWP7)?

In this tutorial we will show you how toCentOS CentOS Webpanel (CWP7) installation on 7Monit monitoring.

What is Monit monitoring?

Monit monitoring is a free and open sourcesoftware, it is a very usefulLinuxmonitoring program.

  • It can automatically monitor and manage server processes, files, directories, checksum permissions, file systems and services in UNIX/Linux.
  • For example: Apache, Nginx,MySQL, FTP, SSH, Postfix, etc...
  • System-based system management that provides excellent monitoring capabilities for system administrators.

Why install Monit monitoring?

You can use Monit monitoring to reduce downtime, yesE-commerceWebsiteSEOInternet marketingis an auxiliary effect.

Because when any service is down, Monit checks it and starts the service automatically.

For example: if your Apache or Nginx service is down for no reason, then monit will check, and if it is found to be down, then monit will automatically start the related services.

One interesting thing is that monit runs its own httpd service.

If your apache service is down, monit will run with its own service.

How to install and install Monit monitoring software in CWP 7?

To complete this tutorial, you will need the following prerequisites:

  1.  CentOS Linux version 7 (core)
  2.  CWP7
  3.  CSF Firewall

Step 1: SSHUpdate your YUM repository, then install Monit monitoring▼

yum update -y
yum install monit

Step 2:Open port 2812 on the 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" 

Step 3: Restart CSF Firewall▼

csf -r 

Step 4:with SFTPsoftwareAfter entering the Linux server, edit the Monit configuration file/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
include /etc/monit.d/*
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@xxxxx #receive all alerts
set alert admin@xxxxx not on { instance, action } 
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'

Step 5:Check Monit syntax for errors ▼

# monit -t
Control file syntax OK  

If missing, create the following files:

# touch /var/run/monit.pid 
# touch /var/log/moinit.log

If Redis is installed, you may need to manually configure the location address of Redis' pid file ▼

Monit adds monitoring service

Now, we will monitor some services such asamavisd, clamd, crond, php-fpm and cwpsrv.Open the monit configuration file/etc/monitrc, and add the following code at the 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

Monitoring 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 

Once configured, monit should reload and reread the configuration file, and the web interface will be available:

monit reload

InquireMySQL databaseFor the method of process pidfile, please check the tutorial below ▼

Monit Monitoring ServiceAnother way (recommended)

1) Download the Monit monitoring service file▼

  • On the download page, click the "Download Now" button in the normal download to download the Monit monitoring service file for free.
  • (Access code: 5588)

2) Unzip and upload to /etc/monit.d/ directory.

  • If inMonit configuration file There is a monitoring service with the same configuration in /etc/monitrc, which needs to beOnMonit configuration file /etc/monitrc is deleted, otherwise an error will occur.

After creating the required configuration files, test for syntax errors▼

monit -t

If the following prompt appears ▼

monit -t
/etc/monit.d/cwp.mariadbd:1: Service name conflict, mysql already defined '"/usr/sbin/mariadbd"'
  • This means that /etc/monit.d/cwp.mariadbd:1: Service name conflict; mysql already defined '"/usr/sbin/mariadbd"'
  • This is the descriptioncwp.mariadbdThe file already exists, just delete itcwp.mysqldfile.

If there are no errors, enable and restart the monit service ▼

systemctl enable monit
systemctl restart monit

Start the Monit service at boot ▼

systemctl enable monit.service

Now check the monitoring log ▼

tail -f /var/log/monit.log

Monit monitoring basic commands

Start monit with the following command ▼

monit

Check Monit status ▼

monit status

Reload it for the changes to take effect▼

monit reload

Start running all programs monitored by Monit▼

monit start all

Restart all Monit air surveillance services▼

monit restart all

To start, stop and restart specific services, you can usemonit start namesuch a command ▼

monit start httpd
monit stop sshd 
monit restart nginx

Monit monitoring summary▼

monit summary

How to install Monit monitoring software on CentOS Webpanel (CWP7)?

Now, log in to the monit server using the Monit username and password you set earlier.

Login URL:http://SERVER_FQDN:2812

Solve the problem that Monit service is always unmonitored

Monit includes commands for enabling and disabling monitoring of all or specific services.

If the Monit service is always unmonitored, you can use the following command▼

monit monitor mysql

Or re-enable all monitoring▼

monit monitor all
  • Note that you must enable the Monit HTTP interface for these commands to work.

Monit Command (Special for CentOS 7)

View Monit startup status▼

systemctl status monit.service

Start the Monit service▼

systemctl start monit.service

Close the Monit service▼

systemctl stop monit.service

Restart the Monit service▼

systemctl restart monit

Start the Monit service at boot▼

systemctl enable monit.service

Turn on and off the Monit service▼

systemctl disable monit.service

Monit Notes

Monit monitors process services, which means that services monitored by Monit cannot be stopped using normal methods, because once stopped, Monit will start them again.

To stop a service monitored by Monit, you should use something likemonit stop nameSuch a command, for example to stop nginx ▼

monit stop nginx

To stop all services monitored by Monit, enter the following command▼

monit stop all

Uninstall Monit monitoring program ▼

yum remove monit

Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "How to install Monit monitoring software on CentOS Webpanel (CWP7)? , to help you.

Welcome to share the link of this article:https://www.chenweiliang.com/cwl-1443.html

Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!

🔔 Be the first to get the valuable "ChatGPT Content Marketing AI Tool Usage Guide" in the channel top directory! 🌟
📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
Share and like if you like!
Your sharing and likes are our continuous motivation!

 

Comment

Your email address will not be published. Required fields * Callout

scroll to top