Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Server \ How to use Monit to deploy a server to monitor the system     - How to modify the Emacs Major Mode Shortcuts (Linux)

- How to convert images, audio and video formats on Ubuntu (Linux)

- Oracle bug Ora-04043 (Database)

- Linux / Unix: chroot command examples to explain (Linux)

- CentOS 6.4 compiler installed MySQL 5.6.14 (Database)

- Spark local development environment to build (Server)

- New experience Budgie (Budgerigar) desktop environment (Linux)

- How to update the Linux kernel to improve system performance (Linux)

- Use backup-manager system backup on Linux (Linux)

- Vim simple configuration (Linux)

- Ganglia Python plug-in the process of writing notes (Linux)

- Use IF NOT EXISTS create a data table (Database)

- Security of data to create a safe .mdb database (Linux)

- Linux system security configuration (Linux)

- Ubuntu way of decompressing files (Linux)

- To explore the Android ListView caching mechanism again (Programming)

- Ubuntu 14.04 Solution login interface infinite loop (Linux)

- C ++ Supplements - Smart Pointers (Programming)

- The Concept and Semantics of Java Memory Model (Programming)

- Linux Command Tutorial: cat command to view the contents of the file (Linux)

  How to use Monit to deploy a server to monitor the system
  Add Date : 2017-08-31      
  Many Linux system administrators rely on a centralized remote monitoring system (such as Nagios or Cacti) to check the health of their network infrastructure. While centralized monitoring makes life easier for administrators, a dedicated monitoring center is clearly a single point of failure when dealing with many machines and services. If the monitoring center hangs up or for whatever reason (such as a hardware or network failure) Once you have visited, you will lose any information about the entire network infrastructure situation.

One way to add redundancy to your monitoring system is to install standalone monitoring software (as a backup), at least on the critical / core server in the network. So that the centralized monitoring system hangs, you still have the ability to monitor the backup to get through the core server health.

Monit is a cross-platform tool for monitoring Unix / Linux systems (such as Linux, BSD, OSX, Solaris). Monit is particularly easy to install, and very lightweight (only 500KB in size), and does not rely on any third-party programs, plug-ins or libraries. However, Monit is well suited for scenarios such as full monitoring, process status monitoring, file system change monitoring, email notifications, and custom actions on core services. Easy to install, lightweight implementation and powerful features, Monit become an ideal backup monitoring tool.

I've been using Monit for a few years on some machines, and I'm very happy with its reliability. Even as a comprehensive monitoring system, for any Linux system administrator Monit is also very useful and powerful. In this tutorial, I'll show you how to deploy Monit on a local server (as a back-up monitoring system) to monitor common services. In the deployment process, I will only show the parts we use.

Install Monit on Linux

Monit has been included in the majority of the Linux distribution of the software warehouse.

Debian, Ubuntu or Linux Mint:

$ Sudo aptitude install monit
Fedora or CentOS / RHEL:

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

# 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, can also use the HTTP / HTTPS page to display. We first use the following configuration web status page bars:

Monit listens on port 1966.
Access to the web status page is encrypted via SSL.
Log in as monituser / romania as the username / password.
Only allowed through localhost, myhost.mydomain.ro and within the LAN ( access.
Monit uses SSL certificates in pem format.
After the steps, I will use a Red Hat-based system. The steps in a Debian-based system are similar.

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

# Mkdir / var / certs
# Cd / etc / pki / tls / certs
# ./make-dummy-cert monit.pem
# Cp monit.pem / var / certs
# Chmod 0400 /var/certs/monit.pem
Now place the following code snippet in Monit's main configuration file. You can create an empty configuration file, or modify it based on its own configuration file.

Set httpd port 1966and
PEMFILE /var/certs/monit.pem
Allow monituser: romania
Allow localhost
Allow myhost.mydomain.ro

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

Then, we set up Monit's mail notification. We need at least one available SMTP server to let Monit send mail. So you can (in accordance with the actual situation you modify):

The mail server machine name: smtp.monit.ro
Monit The sender used: monit@monit.ro
The recipient of the message: guletz@monit.ro
SMTP port used by the mail server: 587 (default is 25)
With the above information, e-mail notification can be configured:

Set mailserver smtp.monit.ro port 587
Set mail-format {
From: monit@monit.ro
Subject: $ SERVICE $ EVENT at $ DATE on $ HOST
Yours sincerely,
Set alert guletz@monit.ro
As you can see, Monit provides several internal variables ($ DATE, $ EVENT, $ HOST, etc.), and you can customize the message content to suit your needs. If you want to send mail from Monit's machine, you will need an already installed sendmail-compatible program (such as postfix or ssmtp).


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

Next, configure the Monit daemon. It can be set up like this:

The first test was performed after 120 seconds.
The service is tested every 3 minutes.
Use syslog to log the logs.
The following code snippet can meet the above requirements.

Set daemon 120
With start delay 240
Set logfile syslog facility log_daemon
We need to define "idfile", a unique ID file for the Monit daemon, and "eventqueue" where the message will be stored temporarily if the mail for monit can not be sent out due to SMTP or network failure, and that the / var / monit path is present of. Then use the following configuration on it.

Set idfile / var / monit / id
Set eventqueue
Basedir / var / monit

Test the global configuration

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

# Global Section
# Status webpage and acl's
Set httpd port 1966and
PEMFILE /var/certs/monit.pem
Allow monituser: romania
Allow localhost
Allow myhost.mydomain.ro
# Mail-server
Set mailserver smtp.monit.ro port 587
# Email-format
Set mail-format {
From: monit@monit.ro
Subject: $ SERVICE $ EVENT at $ DATE on $ HOST
Yours sincerely,
Set alert guletz@monit.ro
# Delay checks
Set daemon 120
With start delay 240
Set logfile syslog facility log_daemon
# Idfile and mail queue path
Set idfile / var / monit / id
Set eventqueue
Basedir / var / monit
Now is the time to verify our work, you can run the following command to verify the existence of the configuration file (/ etc / monit.conf):

# Monit -t
Control file syntax OK
If monit prompts for any errors, check the configuration file again. Fortunately, the error / warning message can help you find the problem, such as:

Monit: Can not stat the SSL server PEM file '/var/certs/monit.pem'--No such file or directory
/ Etc / monit / monitrc: 10: Warning: hostname did not resolve 'smtp.monit.ro'
Once you confirm that the configuration file is okay, start the monit daemon and wait 2 to 3 minutes:

# Service monit start
If you are using systemd, run:

# Systemctl start monit
Now open a browser window and go to https: // < monit_host>: 1966. Replace < monit_host> with the machine name or IP address of the machine where Monit is installed.

If you are using a self-signed SSL certificate, you will see a warning message in your browser. Continue to visit.

In the remainder of this tutorial, we demonstrate ways to monitor a local server and common services. You'll find many useful examples on the official wiki page. Most of which can be directly copied and pasted!

Service Configuration: CPU / Memory Monitoring (Service Configuration: CPU, Memory Monitor)

We first to monitor the local server CPU, memory footprint. Copy the following code snippet into the configuration file.

Check system localhost
If loadavg (1min)> 10then alert
If loadavg (5min)> 6then alert
If memory usage> 75% then alert
If cpu usage (user)> 70% then alert
If cpu usage (system)> 60% then alert
If cpu usage (wait)> 75% then alert
You can easily understand the configuration above. The top of the check is that each monitoring cycle (global configuration settings 120 seconds) on the machine are the following operations. If any of the conditions are met, the monit daemon uses the message to send an alarm.

If a monitoring item does not need to be checked every cycle, the following format can be used, which checks the average load every 240 seconds.

If loadavg (1min)> 10for2 cycles then alert

Service Configuration: SSH Service Monitoring (Service Configuration: SSH Service Monitoring)

First check whether our sshd is installed in / usr / sbin / sshd:

Check file sshd_bin with path / usr / sbin / sshd
We also want to check if the sshd startup script exists:

Check file sshd_init with path /etc/init.d/sshd
Finally, we want to check if the sshd daemon is alive and listening on port 22:

Check process sshd with pidfile /var/run/sshd.pid
Start program "/etc/init.d/sshd start"
Stop program "/etc/init.d/sshd stop"
If failed port 22 protocol ssh then restart
If5 restarts within 5 cycles then timeout
We can explain the above configuration: We check whether there is a process named sshd, and there is a file to save its pid (/var/run/sshd.pid). If any one does not exist, we use the startup script to restart sshd. We check to see if there are processes listening on port 22 and are using the SSH protocol. If not, we restart sshd. If the last 5 monitoring cycles (5x120 seconds) to restart at least 5 times, sshd is considered to be useless, we will not check.

Service Configuration: SMTP Service Monitoring (Service Configuration: SMTP Service Monitoring)

Now we have to set up a remote SMTP server to check (such as monitoring. Assume that the SMTP server is running SMTP, IMAP, SSH services.

Check host MAIL with address
If failed icmp type echo within 10 cycles then alert
If failed port 25 protocol smtp then alert
Elseif recovered thenexec "/ scripts / mail-script"
If failed port 22 protocol ssh then alert
If failed port 143 protocol imap then alert
We check whether the remote host responds to the ICMP protocol. If we do not receive an ICMP response within 10 cycles, we send an alarm. If the SMTP protocol on port 25 is detected as abnormal, an alarm is sent. If monitoring is successful after a failure, run a script (/ scripts / mail-script). If you check the SSH port on port 22 or 143 IMAP protocol on the port is not normal, the same alarm.

to sum up

In this tutorial, I showed you how to set up Monit on a local server, but that's just the tip of the Monit feature. You can take a moment to read Monit's man page (well-written). Monit can do a lot of things for any Linux system administrator, and has a very beautiful and easy to understand syntax. If you use a centralized remote monitoring system with Monit, you will get a more reliable monitoring system. How do you feel about Monit?
- Permissions and attributes of files and directories under Linux (Linux)
- Zabbix installation under Linux (Server)
- SSH automatic disconnection problem solving (Linux)
- Struts2 : combobox label use (Programming)
- CentOS 6.5 install VNC-Server (Linux)
- Linux file time Comments ctime mtime atime (Linux)
- Java String type time compare the size (Programming)
- Ubuntu Server (Ubuntu 14.04 LTS 64-bit) installation libgdiplus 2.10.9 error solution (Linux)
- MySQL flip-flop (Database)
- Sysdig: system troubleshooting tool (Linux)
- Linux batch copy data script (Linux)
- Python maketrans () method (Programming)
- Chrome plug-in management, online-offline installation, part of the plug presentations (Linux)
- Generic mechanism C11 standard (Programming)
- Remote installation of Net-SNMP whole process (Linux)
- MyCAT read and write separation of MySQL (Database)
- Security: Unix operating system intrusion tracking Strikes Back (Linux)
- 20 Advanced Java interview questions summary (Programming)
- Linux System Getting Started Learning: modify environment variables in Linux PATH (Linux)
- The Linux OOM Terminator (Server)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.