How does CentOS 6 use Monit to monitor? Linux installation and uninstallation of Monit tutorial

CentOS 6 How to usemonit monitoring?

LinuxInstall and uninstall monit tutorial

The monit monitoring program is an open source monitoring tool for the Linux operating system. It can help you use a web browser to monitor system processes. When a program or service fails, monit can automatically restart it.

monit can be operated directly on the command line, you can assign multiple monit tasks (not only monitoring), so if a service fails a check, you can pass monit's alert or do something (try restarting some services).

This article assumes that you know at least the basics of Linux, know how to use SSH, and most importantly, that you host your website on your own VPS.

The installation of Monit monitoring program is actually very simple, I will show you step by step installation of monit on CentOS 6.

Step 1: Enable EPEL repository

RHEL/CentOS 7 64-bit:

wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -ivh epel-release-latest-7.noarch.rpm

RHEL/CentOS 6 32-bit:

wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
 rpm -ivh epel-release-6-8.noarch.rpm
  • CentOS 7 does not support 32-bit EPEL repositories, so use RHEL/CentOS 6 32-bit.

Step 2: Install monit

yum update
yum install -y libcrypto.so.6 libssl.so.6
yum install monit

Step 3: Configure monit

Once installed, edit the main configuration file and set your own username and password, see the example below:

nano /etc/monit.conf

Edit the monit configuration file:

 set httpd port 2812 and  # # set the listening port to your desire.
 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

For details on how to configure monit, please browse this "How to setup monit.conf file? monit configuration file example description"article.

Once you have modified the new configuration, you need to enable the reload settings of the monit service:

/etc/init.d/monit start

monit standard start, stop, restart commands:

/etc/init.d/monit start
/etc/init.d/monit stop
/etc/init.d/monit restart

Step 4: Configure the monit monitoring service

After the initial configuration is complete, we can configure some services that we want to monitor.

Here are some useful configuration examples for monit:

  #
  # 监控apache
  #
  check process apache with pidfile /usr/local/apache/logs/httpd.pid
  start program = "/etc/init.d/httpd start"
  stop program = "/etc/init.d/httpd stop"
  if failed host www.ufo.org.in port 80 protocol http then restart
  if 3 restarts within 5 cycles then timeout
  group server

  #
  #监控mysql(1)
  #
  check process mysqld with pidfile /var/run/mysqld/mysqld.pid
  start program = "/etc/init.d/mysqld start"
  stop program = "/etc/init.d/mysqld stop"
  if failed host localhost port 3306 for 3 times within 4 cycles then alert
  #若在四个周期内,三次 3306(我的Mysql)端口都无法连通,则邮件通知
  if 5 restarts within 5 cycles then timeout

  #
  #检测nginx服务
  #
  check process nginx with pidfile /usr/local/nginx/logs/nginx.pid
  start program = "/etc/init.d/nginx start"
  stop program = "/etc/init.d/nginx stop"
  if failed host localhost port 80 protocol http
  then restart

After creating the required configuration files, test for syntax errors:

monit -t

Start monit by simply typing:

monit

To set monit to start with the system, add at the end of the /etc/inittab file:

# Run monit in standard run-levels
  mo:2345:respawn:/usr/local/bin/monit -Ic /etc/monitrc

Monit Notes

Since monit is set as a daemon process, and the settings that start with the system are added in inittab, if the monit process stops, the init process will restart it, and monit monitors other services, which means that the monit monitors Services cannot be stopped using the usual methods, because once stopped, monit will start them again.

To stop a service monitored by Monit, you should use something likemonit stop nameA command like this, for example, to stop nginx:

monit stop nginx

To stop all services monitored by monit use:

monit stop all

To start a service you can usemonit start namesuch a command.

Start all:

monit start all

Uninstall monit:

yum remove monit

Extended reading:

Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "CentOS 6 how to use Monit monitoring? Linux Installation and Uninstallation of Monit Tutorial" will help you.

Welcome to share the link of this article:https://www.chenweiliang.com/cwl-159.html

Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!

🔔 Be the first to get the valuable "ChatGPT Content Marketing AI Tool Usage Guide" in the channel top directory! 🌟
📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
Share and like if you like!
Your sharing and likes are our continuous motivation!

 

Comment

Your email address will not be published. Required fields * Callout

scroll to top