How to Install Monit on CentOS 7 – Monitoring Tool

How to Install Monit on CentOS 7

Monit is an opensource process monitoring tool for Linux operating system which helps you to monitor system process using the web browser and also whenever requires it automatically do the maintenance or repair of the particular process in such a way that it can be brought back online.

Monit can also use for managing and monitoring of programs, files, directories, and devices for timestamps changes, checksum changes, or size changes; not limited to perform various TCP/IP network checks, protocol checks, and can utilize SSL for such checks.

rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install monit
(1/2): epel/x86_64/updateinfo  | 927 kB  00:00:03
(2/2): epel/x86_64/primary     | 3.5 MB  00:00:08
epel                             12611/12611
Resolving Dependencies
--> Running transaction check
---> Package monit.x86_64 0:5.25.1-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================
 Package            Arch      Version       Repository  Size
===============================================================
Installing:
 monit              x86_64    5.25.1-1.el7  epel       318 k

Transaction Summary
================================================================
Install  1 Package

Total download size: 318 k
Installed size: 818 k
Downloading packages:
monit-5.25.1-1.el7.x86_64.rpm             | 318 kB  00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : monit-5.25.1-1.el7.x86_64                 1/1
  Verifying  : monit-5.25.1-1.el7.x86_64                 1/1

Installed:monit-5.25.1-1.el7.x86_64

Start monit by using the following command.

monit

Output

[root@server ~]# monit
New Monit id: 8dc7a69b24bb98fa5526c9ff92c1592d
Stored in '/root/.monit.id'
Starting Monit 5.25.1 daemon with http interface at [localhost]:2812

Check the monit status.

[root@server ~]# monit status
Monit 5.25.1 uptime: 0m

System 'server.webhostingchennai.co.in'
  status                       OK
  monitoring status            Monitored
  monitoring mode              active
  on reboot                    start
  load average                 [0.08] [0.20] [0.19]
  cpu                          0.0%us 0.0%sy 0.0%wa
  memory usage                 109.1 MB [11.0%]
  swap usage                   0 B [0.0%]
  uptime                       18h 14m
  boot time                    Mon, 16 Jul 2018 13:49:47
  data collected               Tue, 17 Jul 2018 08:04:07

[root@server ~]#

Configure Monit

/etc/monitrc the main configuration file of Monit. We can make changes to the Monit configuration file for our requirement.

nano /etc/monitrc

By default, monit is set to check the services at an interval of 1 min. This setting can be altered by changing the below line.

set daemon  60

Alerts can be configured by.

set mailserver mx.webhostingchennai.local port 25

Monit Web Interface

Monit also provides a web interface for monitoring and managing the configured services. By default, monit listens on 2812 port, but it needs to be set up.

Open monit configuration file /etc/monitrc.

nano /etc/monitrc

Look for httpd port 2812, modify the following entries,
From:

set httpd port 2812 and
use address localhost  # only accept connection from localhost
allow localhost        # allow localhost to connect to the server and
allow admin:monit      # require user 'admin' with password 'monit'
allow @monit           # allow users of group 'monit' to connect (rw)
allow @users readonly  # allow users of group 'users' to connect readonly

TO:

set httpd port 2812
allow 0.0.0.0/0.0.0.0
allow admin:monit

From the above settings, monit will listen on 2812; admin user will able to access the web interface from any network.

Reload monit.

systemctl restart monit

Auto-start Monit on start-up.

systemctl enable monit

Configuring in Firewall

Configure the firewall to allow access to Monit web interface, running on port 2812.

firewall-cmd --permanent --add-port=2812/tcp
firewall-cmd --reload

Accessing web interface

http://your_ip_address:2812

Note: You can also use your customized port by editing “/etc/monitrc” and modify the “httpd port 2812” to “httpd port 3000”

Here, I’m using port 3000.

how to install monit on centos

Use username admin and password monit to login.

Configure services with Monit for monitoring

Once the web interface is up, we can start to set up other services that you want to monitor. You can place the configuration files under /etc/monit.d/ directory.

Configuring SSH service.

nano /etc/monit.d/sshdmonitor
check process sshd with pidfile /var/run/sshd.pid
start program  "/usr/bin/systemctl start sshd.service"
stop program  "/usr/bin/systemctl stop sshd.service"
if failed port 22 protocol ssh then restart

Configuring for syslog.

nano /etc/monit.d/syslogmonitor
check process syslogd with pidfile /var/run/syslogd.pid
start program = "/usr/bin/systemctl start rsyslog.service"
stop program = "/usr/bin/systemctl stop rsyslog.service"

Configuring service for HTTP.

nano /etc/monit.d/httpdmonitor
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

Once configured, test the monit syntax

monit -t

Output

Control file syntax OK

Reload it, to take effect of changes.

monit reload

No access the web interface. You can see the new services that was configured.

Hope this article helps you, please share your comments to improve better.

For installing Monitorix : Click here

You may also like...

Leave a Reply

Your email address will not be published.