How to Install and Configure Monit on Linux Server for Process Monitoring

Monit is a powerful open-source utility designed for managing and monitoring processes, files, directories, and devices on a Unix system. It is capable of performing automatic maintenance and repair, and can execute useful actions in error situations. For instance, Monit can start a process if it does not run, restart a process if it does not respond, and stop a process if it uses too many resources. Additionally, Monit can monitor files, directories, and devices for changes, such as timestamp changes, checksum changes, or size changes.

This short guide will walk you through the steps to install and configure Monit on a Linux server for process monitoring.

For more in-depth information on various web servers, you can visit our pages on server software, Apache, Nginx, and LiteSpeed. If you’re interested in different types of hosting, we also have articles on dedicated server, VPS server, cloud hosting, and shared hosting.

Step 1: Download the Latest Monit

The first step in installing Monit is to download the latest version from the rpmforge repository. The repository provides separate versions for x86 (32-bit) systems and x64 (64-bit) systems. Use the wget command to download the appropriate version for your system.

wget http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/monit-5.2.5-1.el5.rf.i386.rpm

Example:

[root@server ~]# wget http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/monit-5.2.5-1.el5.rf.i386.rpm
--2011-08-14 00:12:58--  http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/monit-5.2.5-1.el5.rf.i386.rpm
Resolving apt.sw.be... 193.1.193.67
Connecting to apt.sw.be|193.1.193.67|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 573934 (560K) [application/x-redhat-package-manager]
Saving to: `monit-5.2.5-1.el5.rf.i386.rpm'

100%[=============================================================>] 573,934     20.9K/s   in 34s

2011-08-14 00:13:38 (16.6 KB/s) - `monit-5.2.5-1.el5.rf.i386.rpm' saved [573934/573934]

Step 2: Install the Monit RPM

Once the download is complete, you can install the Monit RPM using the rpm command.

rpm -Uvh monit-5.2.5-1.el5.rf.i386.rpm

Example:

[root@server ~]# rpm -Uvh monit-5.2.5-1.el5.rf.i386.rpm
Preparing...                ########################################### [100%]
   1:monit                  ########################################### [100%]

3. Configure monit

[root@server ~]# vi /etc/monit.conf

 set daemon  120           # check services at 2-minute intervals
 set logfile syslog facility log_daemon
 set mailserver mail.server.local,               # primary mailserver
 set alert admin@server.local 

 set httpd port 2812 and
     allow localhost        # allow localhost to connect to the server and
     allow 192.168.2.2        # allow client ip address to connect to the server and
     allow admin:monit      # require user 'admin' with password 'monit'

Step 3: Configure Monit

After the installation, you need to configure Monit. This involves setting the daemon, logfile, mailserver, alert, httpd port, and access permissions. You can do this by editing the monit.conf file.

vi /etc/monit.conf

Inside this file, you can set the following configurations:

set daemon 120
set logfile syslog facility log_daemon
set mailserver mail.server.local
set alert admin@server.local
set httpd port 2812 and
allow localhost
allow 192.168.2.2
allow admin:monit

Step 4: Create /var/monit Directory

Next, create a /var/monit directory. This is where you will place the id and state.

mkdir /var/monit

Step 5: Configure Service to be Monitored

Now, you need to configure theservices that you want Monit to monitor. This is done by editing the localhost file in the /etc/monit.d/ directory.

vi /etc/monit.d/localhost

In this file, you can set up the monitoring for various processes such as httpd, sshd, and mysqld. For each process, you need to specify the pidfile location, the start and stop programs, and the conditions for restart and timeout.

check process httpd with pidfile /var/run/httpd.pid
start program = "/etc/init.d/httpd start"
stop program = "/etc/init.d/httpd stop"
if failed host 127.0.0.1 port 80 protocol http then restart
if 5 restarts within 5 cycles then timeout

Step 6: Set Monit to Auto Start on Boot Up

To ensure that Monit starts automatically whenever your server boots up, you need to edit the /etc/default/monit file and set the startup variable to 1.

vi /etc/default/monit
startup=1

Alternatively, you can use the chkconfig command to enable Monit.

chkconfig monit on

Step 7: Start Monit Service

With everything set up, you can now start the Monit service. You can do this using the service command or the /etc/init.d/ command.

service monit start

or

/etc/init.d/monit start

Step 8: Monitor Monit from Your Browser

Monit provides a web interface that runs on port number 2812. You can access this interface by pointing your browser to http://serverip:2812/.

See also  How to Reset CentOS root Password

Commands Mentioned

  • wget – used to download files from the internet
  • rpm -Uvh – used to install RPM packages
  • vi – a text editor used for configuring files
  • mkdir – used to create directories
  • service – used to start, stop, and manage services
  • chkconfig – used to manage services across different runlevels

Conclusion

Monit is a powerful tool that provides an efficient way to manage and monitor your Unix system. By following this guide, you should be able to install and configure Monit on your Linux server for process monitoring.

See also  How to Install Clam Antivirus on CentOS 6.3

Remember to configure Monit to monitor the specific services that are important to your system. With Monit, you can ensure that your system runs smoothly and efficiently, as it can automatically perform maintenance and repair tasks, and execute useful actions in error situations.

For more guides and tutorials on web servers and hosting, feel free to explore our website. Whether you’re looking for the best web servers, information on Apache, Nginx, LiteSpeed, or different types of hosting like dedicated server, VPS server, cloud hosting, and shared hosting, we’ve got you covered. Our aim is to provide you with comprehensive, easy-to-understand guides that help you get the most out of your web hosting experience. Happy hosting!

See also  How to Fix "/var/lib/pgsql/data is missing. Use "service postgresql initdb" to initialize the cluster first" Error On Linux CentOS 6.2 Server

FAQ

  1. What is Monit used for?

    Monit is an open-source utility used for managing and monitoring processes, files, directories, and devices on a Unix system. It can perform automatic maintenance and repair, and execute useful actions in error situations.

  2. How do I install Monit on a Linux server?

    You can install Monit on a Linux server by first downloading the latest version from the rpmforge repository, then installing the MonitRPM using the rpm command. After installation, you need to configure Monit by setting the daemon, logfile, mailserver, alert, httpd port, and access permissions in the monit.conf file.

  3. How do I configure Monit to monitor specific services?

    You can configure Monit to monitor specific services by editing the localhost file in the /etc/monit.d/ directory. In this file, you can set up the monitoring for various processes such as httpd, sshd, and mysqld by specifying the pidfile location, the start and stop programs, and the conditions for restart and timeout.

  4. How do I set Monit to auto start on boot up?

    You can set Monit to auto start on boot up by editing the /etc/default/monit file and setting the startup variable to 1. Alternatively, you can use the chkconfig command to enable Monit.

  5. How can I monitor Monit from my browser?

    Monit provides a web interface that runs on port number 2812. You can access this interface by pointing your browser to http://serverip:2812/.

Comments

2 Comments

  • Avatar Patryk Moura says:

    Hi, my monit can show up at port 2812… as we can see here http://37.49.226.152:2812/ and not here too vamola.net:2812…

    Just to handsup, its opened to allow any hosts: “Starting monit: Starting monit daemon with http interface at [*:2812]”

    Any ideas?

    Thanks!!!

  • Avatar Patryk Moura says:

    Oh, i meant, monit CAN’T….

Leave a Reply

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