The administration of each process in Linux can be a tedious task, but with the right tools it becomes something really simple and today we find thousands of applications in the network developed for a correct and optimal management of each Linux distribution..
One of the most special applications for proper management is Monit through which the supervision of processes will be something much simpler to understand with various details about them and thus know at what point we can have a failure and take the necessary measures to do so. .
What is Monit?
Monit is a small open source utility that has been developed in order to manage and monitor Unix systems. By using the Monit application, it is responsible for carrying out the maintenance and automatic repair of processes with error and is able to execute management actions in error situations in order to maintain the operability of the operating system.
Monit can be implemented in FreeBSD, macOS, Linux and OpenBSD.
Monit features
Some of its most outstanding features are:
- Proactive: Monit can act if there is an error situation in the system and, in addition to this, it can control the characteristics of a process such as the amount of memory or CPU cycles that a process uses and more.
- Process management: Monit is ideal for monitoring daemon processes or similar programs that run on the localhost.
- Management of files, directories and file systems: With the implementation of Monit it will be possible to monitor files, directories and file systems on the computer, Monit can control these objects to determine if there is any change, whether in the date and time, changes in the sum of verification or changes in its size.
- Cloud and host: Monit gives us the ability to monitor network connections to multiple servers, either localhost or remote hosts. The TCP, UDP and Unix domain sockets are compatible with the utility.
- Programs and scripts: Monit can be used as a scripting platform before they are launched into the productive field.
1. How to install Monit on Ubuntu or Linux server
Step 1
To install Monit on Ubuntu we will execute the following command:
sudo apt install monit
Step 2
We can run the following line to enable Monit with the operating system boot:
sudo systemctl enable monit
Step 3
Some other options to control Monit are:
Check the status of Monit
sudo systemctl status monit
Stop the Monit service
sudo systemctl stop monit
Restart the Monit service
sudo systemctl restart monit
Start the Monit service
sudo systemctl start monit
2. How to configure Monit on Ubuntu or Linux server
Step 1
Monit can be managed from two main directories that are:
- Main configuration file: / etc / monit / monitrc
- Directories for specific process or server files: / etc / monit / conf-available / and / etc / monit / conf-enabled /
We will access the main configuration directory using any of the desired editors:
sudo nano / etc / monit / monitrc
Step 2
There we will see the following:
Step 3
In this file it will be possible to add more process options to manage, create email alerts or enable HTTPD. To enable the integrated HTTP interface through which you can see the status of the monitored services and manage services from a web interface, we must locate the following line:
set httpd port 2812 and
Step 4
There we uncomment, remove the # sign to the following lines:
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'
We save the changes using the Ctrl + O keys and exit it using the Ctrl + X keys. Now, we are going to configure Monit to monitor some Linux applications.
Step 5
For example, to manage Apache, let's run the following line:
cat / etc / monit / conf-available / apache2
Step 6
We can see details of the parameters that will be analyzed. If we want to monitor OpenVPN we will execute the following line:
sudo nano / etc / monit / conf-available / openvpn
This will create a new file where we will paste the following:
check process openvpn with pidfile /var/run/openvpn/server.pid group nogroup start program = "/etc/init.d/openvpn start" stop program = "/etc/init.d/openvpn stop" if failed host localhost port 1194 then restart if 5 restarts with 5 cycles then timeout depend on openvpn_bin check file openvpn_bin with path / usr / sbin / openvpn group nogroup include / etc / monit / templates / rootbin
Step 7
Save the changes to the file with the Ctrl + O keys and exit with Ctrl + X. Now, let's enable it by running:
sudo ln -s / etc / monit / conf-available / openvpn / etc / monit / conf-enabled /
Whenever we perform a new task, we must execute the following command to verify that everything works correctly:
monit -t
Step 8
We proceed to restart the service by executing any of the following lines:
sudo /etc/init.d/monit reload sudo systemctl reload monit
Other application alternatives to monitor are:
MySQL
cat / etc / monit / conf-available / mysql
NGINX
cat / etc / monit / conf-available / nginx
OpenSSHD Server
cat / etc / monit / conf-available / openssh-server
Step 9
To know the current status of a process, in this case OpenVPN, we will execute the following:
sudo monit status openvpn
Step 10
When we want to access the Monit logs, just run the following line:
sudo tail -f /var/log/monit.log
Monit is a practical alternative for the correct management of each application that we install on Linux and thus have the capacity of a centralized administration..