Monit installation and configuration on Linux/Unix
Introduction
Monit tool is a free and open-source tool to manage and monitor the UNIX systems. It does automatic maintenance and repair and can execute meaningful actions in an error situation, like starting a process if it is not running, restarting a process if not responding, and stopping the process if it uses high resources. Monit has a user-friendly web interface where you can directly view the system status and set up the processes. We can use Monit to monitor files, directories, and filesystems for changes. By using Monit, we will be able to monitor remote hosts’ TCP/IP port, server protocols, and ping. Monit has its own log file for verifying the services. It has alerts about any critical issues for the recovery status.
Below Points are covered in this article
- Monit installation On Monit Master Collector
- Installation of Monit agent on the client
- Configuration of Monit
- Monitoring the services
- References
1. Monit installation On Monit Master Collector
Follow the steps to download monit on the master collector:
Open the terminal/console to install the monit on Linux and download the zip package
# wget https://mmonit.com/dist/mmonit-3.7.7-linux-x64.tar.gz
Unzip the tar
# gunzip mmonit-3.7.7-linux-x64.tar.gz
# tar -xvf mmonit-3.7.7-linux-x64.tar
Start the Monit by using the below command:
# cd mmonit-3.7.6-linux-x64/bin
# ./mmonit start
2. Monit Installation On Client Servers
Prerequisites
By default, the Monit tool is not available from the system base repositories, you need to add and enable a third-party epel repository to install the Monit package under your RHEL/CentOS systems. Once you’ve added the epel repository, install the package by running the following yum command. For Ubuntu/Debian/Linux Mint users can easily install using the apt-get command as shown.
On RedHat/CenOS/Fedora/
# yum install monit
On Ubuntu/Debian/Linux
$ sudo apt-get install monit
3. Configuration of Monit
Monit has a web interface that runs on port 2812 using a web server. Open port 2812 from master(Monit) to all client servers and vice versa. The main configuration file of Monit is located at /etc/monit.conf under (RedHat/CentOS/Fedora) and /etc/monit/monitrc file for (Ubuntu/Debian/Linux Mint) then, uncomment the following section under monit.conf or monitrc file and add the IP address or domain name of your server, allow anyone to connect and change Monit user and password or you can use default ones.
Now start the Monit service to get the new configurations setting by using the below command:
# /etc/init.d/monit start
Now you can connect to the Monit web interface by using the “http://localhost:2812” as shown below image. You can use the username and password the same that you have set into the /etc/monit.conf under (RedHat/CentOS/Fedora) and /etc/monit/monitrc file for (Ubuntu/Debian/Linux Mint).
4. Monitoring The Services
Now we need to add the programs which we want to monitor after the web interface setup is done. The programs should be added into the /etc/monit.conf under(RedHat/CentOs/Fedora) and /etc/monit/monitrc file for (Ubuntu/Debian/Linux Mint).
Examples:
Microservices
CPU Memory Monit
Disk space
Logging
Before going forward please check the monit syntax for errors.
Command to check the monit syntax is
# monit -t
$ sudo monit -t
If you get the message “Control File Syntax OK” then we are good to go.
For starting a monit service you can use the following command.
# /etc/init.d/monit restart
$ sudo /etc/init.d/monit restart
After restarting monit hit the URL “http://localhost:2812” you will be able to see the status of all programs that you have added into the /etc/monit.conf under(RedHat/CentOs/Fedora) and /etc/monit/monitrc file for (Ubuntu/Debian/Linux Mint).
5. References
https://mmonit.com/monit/documentation/monit.html
https://mmonit.com/documentation/
Thank you for reading my article. I hope it will help you to set up Monit on Linux/Unix.