19 C
Texas

How To Install Monit on CentOS 8

Today we are going to learn that how to Install Monit on Centos 8. Before proceeding further let’s have a short introduction about Monit.

What is Monit?

Monit is an Open Source process tracking tool for Linux OS that helps you to monitor the processes by system. When the process is going down, it robotically does the preservation and restore that specific process and guarantees it is introduced again on-line.
Monit also can be used for handling and monitoring of packages, files, directories, filesystems, TCP/IP network exams, protocol assessments, and can make use of SSL for such tests. So, follow the below steps for an easy and smooth installation of Monit on your system.

Step 1: Update System

Update your system by running

sudo yum update -y
- Advertisement -

And install the required tools by typing

sudo dnf install -y git gcc glibc make glibc-devel kernel-headers autoconf automake libtool bison flex libzip-devel pam-devel openssl openssl-devel

Step 2: Clone Monit

Fire the below command to clone the source code of Monit for compiling

git clone https://bitbucket.org/tildeslash/monit.git

After this run the given commands step by step to Compile the Monit.

cd monit
./bootstrap
./configure
make
make install

Step 3: Configuring Monit Functionality

First of all copy the monitrc file we’ve downloaded above to the /etc directory

sudo cp monitrc /etc/

Then edit that file using any editor you prefer.

sudo nano /etc/monitrc

And apply the few changes as below

Provide the time interval that required for the process checking by Monit. Modify it by changing the line

set daemon 30

Provide the email server to get notified about the alerts in your inbox.

set mailserver mx.osradar.local port 25

Note: You can also customize the alert templates. For doing so modify the configuration file.

Now, change the log setting by running

set log /var/log/monit.log

And don’t forget to change uncomment the given line

include /etc/monit.d/*

Step 4: Configuring Monit Web Interface

Monit also provides the Web Interface to monitor and manage the configured services with the Monit. By default, it listens to the port 2812. To configure the web interface edit the /etc/monitrc file with your favorite editor.

sudo nano /etc/monitrc

Then moderate the below entries

From

To:

By doing these setting, Monit will be able to listen to all the interfaces on port 2812. Only the administrator will be able to access the Web based dashboard.

Step 5: Configuring Systemd For Monit

As to start Monit automatically on boot, create a new configuration file for systemd

sudo nano /lib/systemd/system/monit.service

Then paste the below data into the file

This file is systemd template for monit service. To
# register monit with systemd, place the monit.service file
# to the /lib/systemd/system/ directory and then start it
# using systemctl (see below).
#
# Enable monit to start on boot:
# systemctl enable monit.service
#
# Start monit immediately:
# systemctl start monit.service
#
# Stop monit:
# systemctl stop monit.service
#
# Status:
# systemctl status monit.service
[Unit]
Description=Pro-active monitoring utility for unix systems
After=network.target
Documentation=man:monit(1) https://mmonit.com/wiki/Monit/HowTo
[Service]
Type=simple
KillMode=process
ExecStart=/usr/local/bin/monit -I
ExecStop=/usr/local/bin/monit quit
ExecReload=/usr/local/bin/monit reload
Restart = on-abnormal
StandardOutput=null
[Install]
WantedBy=multi-user.target

Then reload the systemd daemon

sudo systemctl daemon-reload

And start & enable the systemd services.

sudo systemctl start monit
sudo systemctl enable monit

Step 6: Allow Firewall Access

Give permissions Monit web interface through firewall by typing

firewall-cmd --permanent --add-port=2812/tcp
firewall-cmd --reload
How To Install Monit on CentOS 8

Step 7: Accessing Monit Web Dashboard

Go to your browser & type 127.0.0.1:2812/

How To Install Monit on CentOS 8

Provide the credential details as admin admin (or use whatever you’ve given in step 4).

Then click on the OK button and you will be redirected to the Homepage of Monit.

How To Install Monit on CentOS 8

Here you can see the configured services.

Step 8: Configuring Services with Monit for Monitoring & Managing

First of all create a new directory

sudo mkdir /etc/monit.d/

Then configure the services for syslog

sudo nano /etc/monit.d/syslogmonitor

And paste the below info.

check process SysLog with pidfile /var/run/rsyslogd.pid
start program = "/usr/bin/systemctl start rsyslog.service"
stop program = "/usr/bin/systemctl stop rsyslog.service"

Edit the file /etc/monit.d/httpdmonitor for configuring the HTTP services.

sudo nano /etc/monit.d/httpdmonitor

And modify the changes like this

check process HTTPD with pidfile /var/run/httpd/httpd.pid
start program "/usr/bin/systemctl start httpd.service"
stop program "/usr/bin/systemctl stop httpd.service"
if failed port 80 protocol http then restart

After doing all these settings, verify the Monit syntax by

monit -t

Now, reload the Monit to take the effect of changes.

sudo systemctl reload monit

Now, again go to the Web Dashboard to see if the services, we’ve configured are showing.

How To Install Monit on CentOS 8

When you click on the any listed service, it will give you the information in details.

How To Install Monit on CentOS 8

Here you can perform various functions like start, stop, restart or disable these services.

Step 9: Testing the Monitoring

First of all stop the http service for testing purposes.

sudo systemctl stop httpd

After 30s type this command to check the logs

cat /var/log/monit.log

Ouput:]

EDT Mar 19 13:01:49] error    : 'HTTPD' process is not running
[EDT Mar 19 13:01:49] info : 'HTTPD' trying to restart
[EDT Mar 19 13:01:49] info : 'HTTPD' start: '/usr/bin/systemctl start httpd.service'

Type the command to edit the configuration

sudo nano /etc/monitrc

Set the alert template like this according to your requirements.

set mail-format {
from: Monit
subject: monit alert -- $EVENT $SERVICE
message: $EVENT Service $SERVICE
Date: $DATE
Action: $ACTION
Host: $HOST
Description: $DESCRIPTION
Your faithful employee , monit
}

Now, set the recipient address to get notified of all actions.

set alert root@localhost

And set the recipient address for not alerting on user initiated service restarts.

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

Then finally, set up the email server in order to receive emails.

set mailserver localhost

As I’ve installed the local relay in order to read email from terminal you can also do so or set up your own email server.

dnf install -y sendmail && systemctl start sendmail

Reload the services

sudo systemctl reload monit

Now, you can see the email alerts by running

cat /var/spool/mail/root
How To Install Monit on CentOS 8

You can also install the mutt, an email client to view alerts by running

dnf install -y mutt

So, this is how you can Install Monit on Your CentOS system and easily Monitor and Manage the process.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article