Monit is a process supervision tool that can be used to monitor and manage the status of various services and processes on a Linux server. Here’s how to install and use Monit on Ubuntu/Debian:
- Install Monit using the package manager:
sudo apt-get update
sudo apt-get install monit
- Configure Monit by editing the configuration file at
/etc/monit/monitrc
:
sudo nano /etc/monit/monitrc
- In the configuration file, you can specify which services and processes you want Monit to monitor. Here’s an example configuration that monitors the Apache web server and the SSH daemon:
# /etc/monit/monitrc
set daemon 120 # Check services every 120 seconds
check process apache2 with pidfile /var/run/apache2.pid
start program = "/usr/sbin/service apache2 start"
stop program = "/usr/sbin/service apache2 stop"
if failed host localhost port 80 protocol http
request "/index.html"
with timeout 10 seconds
then restart
check process ssh with pidfile /var/run/sshd.pid
start program = "/usr/sbin/service ssh start"
stop program = "/usr/sbin/service ssh stop"
if failed port 22 protocol ssh
with timeout 10 seconds
then restart
- Save and close the configuration file, and restart the Monit service:
sudo service monit restart
- Verify that Monit is running and monitoring the specified services by checking its status:
sudo monit status
The output should show the status of each monitored service and process, including whether they are running and if Monit is taking any action.
Note: The example configuration above assumes that the Apache web server and the SSH daemon are already installed and running on your system. You’ll need to adjust the configuration as needed to match your specific environment.
Note: Monit has many more features and options available, including the ability to send alerts, run custom scripts, and more. For more information, refer to the Monit documentation.