Bobcares

How to install Monit monitoring system on CentOS 8?

by | Oct 2, 2020

Monit monitoring tool can notify webmasters whenever the service/process goes down. It automatically does the maintenance and repair of the particular process and ensures it is brought back online.

As a part of our Server Management Services, we help our Customers with software installations regularly.

Let us today discuss the steps to perform this task.

Install Monit on Centos 8

Like in most other installations, the first step here is to update and install necessary packages. We have to make sure all dependencies have been met by installing the following important packages.

$ sudo dnf -y update
$ sudo dnf -y install zlib-devel pam-devel openssl-devel libtool bison flex autoconf gcc make git epel-release

Now, let us move on to the monit install:

$ sudo dnf -y install monit

After the install, let us start monit with the command below:

$ sudo monit
###You should see the message below in the end###
New Monit id: a447ea6daa8857bcf3c5089d0d225e83
Stored in '/root/.monit.id'
Starting Monit 5.26.0 daemon with http interface at [localhost]:2812

After starting Monit, we can check the status as follows:

$ sudo monit status
Monit 5.26.0 uptime: 1m
System 'master'
status OK
monitoring status Monitored
monitoring mode active
on reboot start
load average [0.00] [0.00] [0.00]
cpu 0.0%us 0.0%sy 0.0%wa
memory usage 306.4 MB [17.4%]
swap usage 0 B [0.0%]
uptime 1h 59m
boot time Wed, 30 Sep 2020 17:53:25
data collected Wed, 30 Sep 2020 19:51:59

Further, we can as well enable Monit to start when the server restarts.

$ sudo systemctl enable --now monit

Monit configuration

Monit uses the monitrc control file located in /etc/monitrc directory for its configuration.

The file is setup to start Monit’s http server. Look for the section in the snippet below and change the IP from localhost to 0.0.0.0 which will allow us to access the web interface from all IPs that can reach the server.

$ sudo vim /etc/monitrc

set httpd port 2812
#use address localhost => only accept connection from localhost (drop if you use M/Monit)
use address 0.0.0.0
allow 0.0.0.0/0
allow admin:monit

Also, open the port 2812 once we are done editing. and then restart Monit service as well.

$ sudo firewall-cmd --permanent --add-port=2812/tcp
$ sudo firewall-cmd --reload
$ sudo systemctl restart monit

After starting Monit, open the link http://[IP-or-domain_name]:2812  on the browser. Log in with the username “admin” and password “monit” when prompted.

Add services for Monit to monitor

Once we have Monit running, we need to add the services to the monitoring.

For instance, to enable the monitoring of nginx, we shall add the following configuration in /etc/monit.d directory that can hold configuration files for various services being monitored.

$ sudo vim /etc/monit.d/nginx-monitor
check process nginx with pidfile /run/nginx.pid
start program "/usr/bin/systemctl start nginx.service"
stop program "/usr/bin/systemctl stop nginx.service"
if failed port 80 protocol http then restart

To check whether the syntax in the configuration file is correct, we can do so using the command given below:

$ sudo monit -t
Control file syntax OK

Now reload Monit for it to accommodate the new configuration.

$ sudo monit reload
Reinitializing monit daemon

The web interface will now show the details of those being monitored.

Other services such as sshd, httpd, syslogd, postfix, and much more can be added in the same fashion in their own files within /etc/monit.d/ directory.

Alert configuration

Monit checks services at 30 seconds intervals by default. we can change this value in the configuration file (/etc/monitrc) to befit our requirements. Look for the line “set daemon 30” in the file and change the number (in seconds) to more or less.

There are predefined alerting templates available in Monit to alert system administrators when the particular service fails.

For instance to use the local relay (email server) to alert the root user, edit the /etc/monitrc file with the below template:

set mail-format {
from: Monit <monit@$HOST>
subject: monit alert — $EVENT $SERVICE
message: $EVENT Service $SERVICE
Date: $DATE
Action: $ACTION
Host: $HOST
Description: $DESCRIPTION
}

To set the recipient address to receive alerts on all type of actions use the format below:

set alert root@localhost

Likewise, to set the recipient address to not alert on user-initiated service restarts, use the format below:

set alert root@localhost not on { instance, action }

Finally, set the mail server configuration so that you can receive mails.

set mailserver localhost

Here, replace the localhost with the corresponding mail server name to receive the mails on an external server. Now, reload the service for the changes to take effect.

systemctl reload monit

[Need any further assistance to install Monit on Centos? – We’re available 24*7]

Conclusion

In short, install of Monit on Centos involves steps to adjust the configuration and setting up alerts to notify the users. Today, we saw how our Support Engineers perform this task.

 

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF