Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Server \ How to use Monit to deploy a server to monitor the system     - MySQL rollback insert statement causes ibd file grows double (Database)

- Share Practical Tutorial GitHub (Linux)

- Linux server data backup (Server)

- To install HDRMerge 0.4.3 under ubuntu (Linux)

- Java Prototype Pattern (Programming)

- pscp use Detailed Windows and Linux each file transfer tool (Linux)

- Remote database using RMAN recovery test (RAC return to single-instance database) (Database)

- I use the desktop environment in GNU / Linux combination tool (Linux)

- Linux System Tutorial: Fix ImportError: No module named wxversion error (Linux)

- Simple to use multi-threaded programming under Linux mutex and condition variable (Programming)

- namespace mechanism Linux kernel analysis (Linux)

- MongoDB3.0.6 wiredtiger MMAPv1 (Database)

- Linux system on how to use rsync to synchronize data (Server)

- Preliminary understanding of SELinux security management (Linux)

- linux server security (Linux)

- Common Linux system performance monitoring command (Linux)

- Single Instance ASM under CRS-4124, CRS-4000 error handling (Database)

- Configuring Android NDK development environment for Mac OS X (Linux)

- Android working with Volley Comments (Programming)

- AngularJS achieve picture upload feature (Programming)

 
         
  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 (192.168.0.0/16) 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
SSL ENABLE
PEMFILE /var/certs/monit.pem
Allow monituser: romania
Allow localhost
Allow 192.168.0.0/16
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
Message: Monit $ ACTION $ SERVICE $ EVENT at $ DATE on $ HOST: $ DESCRIPTION.
Yours sincerely,
Monit
}}
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
SSL ENABLE
PEMFILE /var/certs/monit.pem
Allow monituser: romania
Allow localhost
Allow 192.168.0.0/16
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
Message: Monit $ ACTION $ SERVICE $ EVENT at $ DATE on $ HOST: $ DESCRIPTION.
Yours sincerely,
Monit
}}
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 192.168.111.102) monitoring. Assume that the SMTP server is running SMTP, IMAP, SSH services.

Check host MAIL with address 192.168.111.102
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?
     
         
       
         
  More:      
 
- SQL Beginner Guide (Database)
- Install Git on CentOS (Linux)
- Ubuntu 15.04 installed JDK and configured as the default JDK (Linux)
- Bubble Sort Algorithms (Programming)
- Terminal multiplexing tool tmux use (Linux)
- The sublime into IDE (Linux)
- Java memory analysis tool uses detailed MAT (Programming)
- Getting the Linux shell variable test (Programming)
- Approach the next Linux shared interrupts (Linux)
- CentOS 6.x and CentOS7 install MPlayer (Linux)
- Oracle 11g new features of the collection of multi-column statistics (Database)
- JavaScript cross-browser event object library (Programming)
- Android Studio utility plug organize, create sharp artifact (Programming)
- Android to determine whether the device to open WIFI, GPRS data connection (Programming)
- C language macro definition #define Usage (Programming)
- Linux / Raspberry Pi using the following command-line based web browser (Linux)
- HAProxy performance under high concurrency (Server)
- vector C ++ sequence containers (Programming)
- Java development specifications summary (Programming)
- LogStash log analysis display system (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.