How to deploy a server monitoring system using Monit

Source: Internet
Author: User
Tags google guava linux mint

How to deploy a server monitoring system using Monit

Many Linux system administrators rely on a centralized remote monitoring system (such as Nagios or Cacti) to check the health status of their network infrastructure devices. Although centralized monitoring makes life easier for administrators, dedicated monitoring centers become a single point of failure when dealing with many machines and services, if the monitoring center fails or is inaccessible for any reason (such as hardware or network failure), you will lose any information about the entire network infrastructure.

One way to increase redundancy for your monitoring system is to install independent monitoring software (as a backup), at least on the key/core servers in the network. In this way, when the centralized monitoring system fails, you can also obtain the running status of the core server through the backup monitoring method.

Nagios details: click here
Nagios: click here

What is Monit?

Monit is a cross-platform tool used to monitor Unix/linux systems (such as Linux, BSD, OSX, and Solaris. Monit is especially easy to install and is very lightweight (only KB) and does not rely on any third-party programs, plug-ins, or libraries. However, Monit can be used in scenarios such as comprehensive monitoring, Process status monitoring, file system change monitoring, email notification, and custom actions on core services. Easy to install, lightweight implementation, and powerful functions make Monit an ideal backup monitoring tool.

I have been using Monit on some machines for several years, and I am very satisfied with its reliability. Even as a comprehensive monitoring system, Monit is also very useful and powerful for any Linux system administrator. In this tutorial, I will show you how to deploy Monit (as a backup Monitoring System) on a local server to monitor common services. During the deployment process, I will only show what we use.

Use HeartBeat + Monit to implement master-slave dual-Hot Backup System

Monitor in Google Guava

Install Monit in Linux

Monit has been included in the software repositories of most Linux distributions.

Debian, Ubuntu, or Linux Mint:

  1. $ sudo aptitude install monit

Fedora or CentOS/RHEL:

In CentOS/RHEL, you must first enable EPEL or Repoforge software repository.

  1. # yum install monit

Monit comes with a well-documented configuration file, which contains many examples. The main configuration file is in/etc/monit. conf (Fedora/CentOS/RHEL), or/etc/monit/monitrc (Debian/Ubuntu/Mint ). The Monit configuration file has two parts: Global and Services ).

 

Global Configuration: Web Status Page (Global Configuration: Web Status Page)

Monit can use the mail service to send notifications, or use HTTP/HTTPS pages to display notifications. Use the following web status page:

  • Monit listens to port 1966.
  • Access to the web status page is encrypted through SSL.
  • Use monituser/romania as the user name/password to log on.
  • Only access through localhost, myhost. mydomain. ro, and within the LAN (192.168.0.0/16) is allowed.
  • Monit uses an SSL Certificate in pem format.

In the subsequent steps, I will use a Red Hat-based system. The steps In Debian-based systems are similar.

First, generate a self-signed certificate (monit. pem) in/var/cert ):

  1. # mkdir /var/certs
  2. # cd /etc/pki/tls/certs
  3. # ./make-dummy-cert monit.pem
  4. # cp monit.pem /var/certs
  5. # chmod 0400 /var/certs/monit.pem

Now, put the following code snippets in the main configuration file of Monit. You can create an empty configuration file or modify it based on the built-in configuration file.

  1. set httpd port 1966and
  2. SSL ENABLE
  3. PEMFILE /var/certs/monit.pem
  4. allow monituser:romania
  5. allow localhost
  6. allow 192.168.0.0/16
  7. allow myhost.mydomain.ro

 

Global Configuration: Email Notification (Global Configuration: Email Notification)

Then, set the Monit email notification. We need at least one available SMTP server for Monit to send emails. In this way, you can (modify according to your actual situation ):

  • Email server machine name: smtp. monit. ro
  • The sender used by Monit: [email protected]
  • Email Recipient: [email protected]
  • SMTP port used by the mail server: 587 (25 by default)

With the above information, mail notification can be configured as follows:

  1. set mailserver smtp.monit.ro port 587
  2. set mail-format {
  3. from: monit@monit.ro
  4. subject: $SERVICE $EVENT at $DATE on $HOST
  5. message:Monit $ACTION $SERVICE $EVENT at $DATE on $HOST : $DESCRIPTION.
  6. Yours sincerely,
  7. Monit
  8. }
  9. set alert guletz@monit.ro

As you can see, Monit provides several internal variables ($DATE,$EVENT,$HOST). You can customize the email content as needed. If you want to send emails from the machine where Monit is located, you need a program (such as postfix or ssmtp) that is compatible with sendmail ).

 

Global Configuration: Monit Daemon (Global Configuration: Monit Daemon)

Next, configure the Monit daemon. You can set it as follows:

  • Perform the first detection in 120 seconds.
  • The service is detected every 3 minutes.
  • Use syslog To record logs.

The following code segment can meet the above requirements.

  1. set daemon 120
  2. with start delay 240
  3. set logfile syslog facility log_daemon

We must define "idfile", a unique ID file of the Monit daemon, and "eventqueue". When monit emails cannot be sent due to SMTP or network faults, the email is saved here, And the/var/monit path exists. Then use the following configuration.

  1. set idfile /var/monit/id
  2. set eventqueue
  3. basedir /var/monit

 

Test global configuration

Now the "Global" part is complete. The Monit configuration file looks like this:

  1. # Global Section
  2. # status webpage and acl's
  3. set httpd port 1966and
  4. SSL ENABLE
  5. PEMFILE /var/certs/monit.pem
  6. allow monituser:romania
  7. allow localhost
  8. allow 192.168.0.0/16
  9. allow myhost.mydomain.ro
  10. # mail-server
  11. set mailserver smtp.monit.ro port 587
  12. # email-format
  13. set mail-format {
  14. from: monit@monit.ro
  15. subject: $SERVICE $EVENT at $DATE on $HOST
  16. message:Monit $ACTION $SERVICE $EVENT at $DATE on $HOST : $DESCRIPTION.
  17. Yours sincerely,
  18. Monit
  19. }
  20. set alert guletz@monit.ro
  21. # delay checks
  22. set daemon 120
  23. with start delay 240
  24. set logfile syslog facility log_daemon
  25. # idfile and mail queue path
  26. set idfile /var/monit/id
  27. set eventqueue
  28. basedir /var/monit

Now it is time to verify our work. You can run the following command to verify the existing configuration file (/etc/monit. conf ):

  1. # monit -t
  2. Control file syntax OK

If monit prompts any error, check the configuration file again. Fortunately, error/warning information helps you identify problems, such:

  1. monit:Cannot stat the SSL server PEM file '/var/certs/monit.pem'--No such file or directory
  2. /etc/monit/monitrc:10:Warning: hostname did not resolve 'smtp.monit.ro'

Once you confirm that the configuration file is okay, you can start the monit daemon and wait for 2 to 3 minutes:

  1. # service monit start

If you are using systemd, run:

  1. # systemctl start monit

Open a browser window and accesshttps://<monit_host>:1966. Set<monit_host>Replace it with the machine name or IP address of the machine where Monit is located.

If you are using a self-Signed SSL certificate, you will see a warning in the browser. Continue.

After you log on, you will see this page.

 

 

  • 1
  • 2
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.