Linux Nagios Monitoring

Source: Internet
Author: User
Tags install openssl rrdtool snmp

Monitoring target
Monitoring target host is divided into four parts
Hardware Resources
Operating system
Database
Application software

Monitoring purpose:
Before server performance tuning, know what to adjust and where the system bottleneck is
must be monitored at the same time, including throughput, reaction time, utilization, etc.

Monitoring command:
Process monitoring
Ps
Top
Storage monitoring
Free
Swapon-s
Df-h
Network Monitoring
Ifconfig
Netstat
Ping
Traceroute
Performance monitoring
Common Performance Monitoring commands
Uptime CPU Load
Mpastat Viewing CPU status
Vmstat Viewing memory status
Iostat viewing hard disk status
Netstat Viewing network status
SAR view above four categories of information

——————————————————————————————————————————————————————————————————

Monitoring Services
Nagios
is an open source application for monitoring systems and networks that can be run on Linux or UNIX operating systems
With the use of many plug-ins to monitor the local and remote services, when the monitoring objects are abnormal, Nagios will promptly give managers alarm
Can customize shell scripts for monitoring
Monitor host resources and network services to monitor object status through Web pages

When the Nagios service is running, the plugins in the monitoring plug-in directory are automatically called to monitor the resources of the specified server
When invoking a plug-in, the administrator can configure, invoke the monitoring plug-in to monitor the value of the resource,

There are two types of values, a warning value (number, percentage), and an error value (number, percent)
If the monitor object's usage is less than the warning value is normal, display OK
Displays warning if the monitor object's usage is greater than the warning value and is less than the error value
Monitor object usage is greater than error value, error status, display crtual

Cacti
A set of graphical analysis tools for network traffic monitoring based on Php,mysql,snmp,rrdtool development
Cacti obtains data through Snmpget, uses RRDtool to draw graphics, and finally renders it through the web
Cacti three-tier architecture
Data acquisition layer: Data acquisition via SNMP or custom scripts
Data storage layer: Cacti templates and other data stored in MySQL
Data presentation layer: Web-based presentation

The difference between Nagios and cacti
Nagios: Better fault analysis, better alarm mechanism
Cacti: Better flow and graphic presentation

————————————————————————————————————————————————————————————————————

Setting up a monitoring server
Configuration ideas
1. Define the monitoring command:
[Email protected] objects]# vim commands.cfg
Define Command{
Command_name (command name)
Command_line (Set the plug-in used)
}
2. Invoke the defined Monitoring command in the configuration file of the monitoring server:
[Email protected] objects]# vim localhost.cfg
Define Service{
Use (the template used to monitor resources)
HOST_NAME (host name monitored)
Service_description (descriptive information for monitoring)
Check_command (monitor command)
}

3. Verify the Nagios configuration format:
/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg
4. Restart the Monitoring service:
/etc/init.d/nagios restart
5. Visit the Monitoring page to view monitoring information

Instance:
Deploying the Nagios monitoring service on ZHUJI1 servers

Installation Environment:
[[email protected] ~]# Groupadd nagcmd (only this user group is available in Nagios config file)
[[email protected] ~]# useradd Nagios (add users)
[Email protected] ~]# usermod-g nagcmd Nagios (put in group)
[[email protected] ~]# yum-y install gcc gcc-c++ (source package installation, installation and compilation tools)
[[email protected] ~]# yum-y install httpd (monitoring is viewed via web page, so install httpd)
[[email protected] ~]# echo Hail Hydra >/var/www/html/index.html (Test page)
[[email protected] ~]# yum-y install PHP (the page is written by PHP, install PHP to parse the page)
[[email protected] ~]# vim/var/www/html/test.php (test page)
<?php
echo "Hail Hydra";
?>
[[email protected] ~]# yum-y install elinks (command line access tool)
Installing Nagios
[Email protected] ~]# Unzip Nagios.zip
[[Email protected] ~]# CD Nagios
[[email protected] nagios]# ls
Nagios-3.2.1.tar.gz nrpe-2.12.tar.gz
Nagios-plugins-1.4.14.tar.gz ntop-3.3.7.tar.gz
[Email protected] nagios]# TAR-XF nagios-3.2.1.tar.gz
[Email protected] nagios-3.2.1]#/configure--with-nagios-user=nagios--with-nagios-group=nagcmd-- With-command-user=nagios--with-command-group=nagcmd (users, user groups who can use this software)
Type ' make all ' to compile the main program and CGIs. (Prompt to do all)
[[email protected] nagios-3.2.1]# make all (Will prompt next after execution)
Make install (install)
Make Install-init (Install init startup script)
Make Install-commandmode (Modify access rights)
Make Install-config (installs the configuration file Lezivan pieces)
Make install-webconf (Install the Web page configuration file)
[[email protected] nagios-3.2.1]# make install
[email protected] nagios-3.2.1]# make Install-init
[email protected] nagios-3.2.1]# make Install-commandmode
[email protected] nagios-3.2.1]# make Install-config
[email protected] nagios-3.2.1]# make install-webconf
[[email protected] ~]# ls/usr/local/nagios/(installation directory)
Bin etc libexec Sbin share Var
Installing the Nagios Monitor plugin
[Email protected] nagios]# TAR-XF nagios-plugins-1.4.14.tar.gz
[Email protected] nagios-plugins-1.4.14]#./configure
[[email protected] nagios-plugins-1.4.14]# make
[[email protected] nagios-plugins-1.4.14]# make install
[[email protected] ~]# ls/usr/local/nagios/libexec/check_* (plugin directory)
Start the Nagios monitoring service: (default no configuration, Nagios service defaults to monitor native)
[[email protected] ~]#/etc/rc.d/init.d/nagios start
[[email protected] ~]# vim/etc/httpd/conf.d/nagios.conf (open config file)
Authuserfile/usr/local/nagios/etc/htpasswd.users (User-certified directory)
[[email protected] etc]# vim cgi.cfg (create user based on user information in this)
Authorized_for_system_information=nagiosadmin (see the name of the system certification information)
...... .......... ........... .....
[[email protected] ~]# htpasswd-c/usr/local/nagios/etc/htpasswd.users nagiosadmin (create user)
New Password: password
Re-type New password: Confirm password
Visit the Web page of the Nagios Monitoring service to view monitoring information
[Email protected] ~]#/etc/init.d/httpd restart
[email protected] ~]# Firefox Http://192.168.4.1/nagios
Resources for default monitoring
Current LOAD:CPU Load
Current users: Number of people logged in
HTTP: Web Services
PING: Online
Root Partition: System root Partition usage
SSH: Remote Service
Swap usage: usage of swap partition
Total Processes: Process count

Nagios Service configuration file description
[Email protected] ~]# cd/usr/local/nagios/etc/
[[email protected] etc]# ls
Cgi.cfg (defines the user name to access the CGI file) htpasswd.users nagios.cfg (master configuration file for Nagios Service) objects resource.cfg (defines the variables used by the Nagios service)
[[email protected] objects]# ls
COMMANDS.CFG (define monitoring command) localhost.cfg (monitor native configuration file) switch.cfg timeperiods.cfg (define monitoring time template)
Contacts.cfg (define the email address to receive the alert message) Printer.cfg templates.cfg (define the monitoring template) windows.cfg

Monitoring plug-in usage
[Email protected] ~]# cd/usr/local/nagios/libexec/
Monitoring users:
[Email protected] libexec]#./check_users
Format: Check_users-w <users>-C <users>
Options:
-W: Warning value, login user greater than this value
-C: Critical error, greater than this number error
[[email protected] libexec]#/check_users-w 3-c 5 (User login number is greater than 3, less than 5 warning,)
Users OK-2 users currently logged in |users=2;3;5;0
[[email protected] libexec]#./check_users-w 1-c 1 (user login is greater than 1, error)
Users CRITICAL-2 users currently logged in |users=2;1;1;0

Monitoring disk:
[Email protected] libexec]#./check_disk
Format:
Check_disk-w limit-c Limit [-W limit] [-K limit] {-P path |-X Device}
[-c] [-E] [-E] [-G Group] [-K] [-l] [-M] [-M] [-R Path] [-R Path]
[-t timeout] [-U unit] [-V] [-X Type]
Options:
-W: Warning value, login user greater than this value
-C: Critical error, greater than this number error
-P: Specify disk
Example:
[Email protected] libexec]#/check_disk-w 10%-C 5%-p/tmp
DISK ok-free Space:/43784 MB (96% inode=98%); |/=1568mb;43007;45396;0;47786

Monitoring process:
[Email protected] libexec]#./check_procs
Format:
Check_procs-w <range>-C <range> [-M metric] [-s state] [-P ppid]
[-u user] [-R RSS] [-Z vsz] [-P%CPU] [-A Argument-array]
[-C command] [-t timeout] [-V]
Options:
-W: Warning value, login user greater than this value
-C: Critical error, greater than this number error
--metric: The name of the process to monitor
Example:
[Email protected] libexec]#/check_procs-w 10-c--metric=cpu
CPU Warning:1 warn out of 101 processes

Monitoring http:
[Email protected] libexec]#./check_http
Format:
Check_http-h <vhost> | -I <IP-address> [-u <uri>] [-P <port>]
Options:
-H: Monitored host
-I: Monitored IP address
-P: Monitored ports
-u: Monitored URL address
-W: Warning value, login user greater than this value
-C: Critical error, greater than this number error
Instance:
[Email protected] libexec]#/check_http-h 192.168.4.1-p 21
Connection denied (21 port not open)
HTTP critical-unable to open TCP socket


Configuring Monitoring for this machine
[Email protected] ~]# cd/usr/local/nagios/etc/objects/
LOCALHOST.CFG (monitor the configuration file for this machine)
[Email protected] objects]# vim localhost.cfg
Define Host{
Use Linux-server (monitor template name)
HOST_NAME localhost (define host name)
Alias localhost (host description information, aliases)
Address 127.0.0.1 (specifies IP addresses of monitored machines)
}
Define Service{
Use Local-service (template used for monitoring resources)
HOST_NAME localhost (host name monitored)
Service_description Swap Usage (descriptive information for monitoring)
CHECK_COMMANDCHECK_LOCAL_SWAP!20!10 (monitor command)
}

Custom Monitoring Resources Commands.cfg
[Email protected] ~]# cd/usr/local/nagios/etc/objects/
[Email protected] objects]# vim commands.cfg
Define Command{
Command_name check_http (command name)
Command_line $USER 1$/check_http-i $HOSTADDRESS $ $ARG 1$ (set up the plug-in used)
}


Instance:
Customize monitoring of native resources, monitor the boot partition of this machine, monitor the status of local FTP service, do not monitor swap partition
[Email protected] objects]# vim localhost.cfg
Define Service{
Use Local-service
HOST_NAME localhost
Service_description FTP
Check_command check_local_ftp
}

Define Service{
Use Local-service
HOST_NAME localhost
Service_description Boot
Check_command Check_local_boot
}
[Email protected] objects]# vim commands.cfg
Define Command{
Command_name Check_local_boot
Command_line $USER 1$/check_disk-w 60-c 20-p/boot
}

Define command{
Command_name check_local_ftp
command_line $USER 1$/check_ftp-h localhost
}

[[EMA Il protected] objects]#/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg (verify nagios configuration format)
[[ Email protected] objects]#/etc/init.d/nagios Restart (restart monitoring service)
[[email protected] objects]# Firefox http ://192.168.4.1/nagios (Access Test)

Configuring Monitoring Alarms
[Email protected] objects]# vim contacts.cfg
email [email protected]
[Email protected]
[[email protected] objects]# mail-u Nagios (view mail)
Heirloom Mail Version 12.4 7/29/08. Type? For help.
"/var/mail/nagios": 1 message 1 new
>n 1 [email protected] Thu SEP 15:26 31/869 "* * Problem Service Ale"
& 1
Message 1:
From [email protected] Thu SEP 14 15:26:30 2017
Return-path: <[email protected]>
x-original-to: [Email protected]
delivered-to: [Email protected]
Date:thu, Sep 2017 15:26:30 +0800
To: [Email protected]
Subject: * * Problem Service alert:localhost/ftp is CRITICAL * *
User-agent:heirloom MAILX 12.4 7/29/08
Content-type:text/plain; Charset=utf-8
From: [Email protected]
Status:r

Nagios * * * *

Example: monitoring FTP services and HTTP services for remote (192.168.4.2) servers
[Email protected] etc]# vim nagios.cfg
Cfg_file=/usr/local/nagios/etc/objects/192.168.4.2.cfg (Create a new monitor)
[[email protected] etc]# vim/usr/local/nagios/etc/objects/192.168.4.2.cfg (write config)
Define host {
Use Linux-server (monitoring template)
HOST_NAME Server2 (controlled by the host, casually write)
Alias this my server (monitored host identity)
Address 192.168.4.2 (monitored host IP addresses)
}

Define service {(Monitored services)
Use Local-service
HOST_NAME Server2
service_description ftp (monitored service name)
Check_command check_2_ftp (Monitoring command)
}

Define service {(Monitored services)
Use Local-service
HOST_NAME Server2
service_description httpd (monitored service name)
Check_command check_2_httpd (Monitoring command)
}
[Email protected] etc]# vim/usr/local/nagios/etc/objects/commands.cfg
Define Command{
Command_name check_2_ftp
Command_line $USER 1$/check_ftp-h 192.168.4.2
}

Define Command{
Command_name check_2_httpd
Command_line $USER 1$/check_httpd-h 192.168.4.2
[Email protected] objects]#/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg
[Email protected] objects]#/etc/init.d/nagios restart


Example: Configure monitoring of private data on the remote server (number of logged in users boot partition usage process quantity)

Monitored side configuration (zhuji2:192.168.4.2)
Installing the Monitoring plugin
[Email protected] ~]# TAR-XF nagios-plugins-1.4.14.tar.gz
[Email protected] nagios-plugins-1.4.14]#./configure
[[email protected] nagios-plugins-1.4.14]# make
[[email protected] nagios-plugins-1.4.14]# make install (installed in/usr/local/nagios directory by default)
[[email protected] ~]#/usr/local/nagios/libexec/check_users-w 3-c 5 (test run plugin)
Users OK-2 users currently logged in |users=2;3;5;0
[Email protected] ~]#/usr/local/nagios/libexec/check_disk-w 20%-C 10%-p/boot
DISK ok-free Space:/boot 415 MB (92% inode=99%); |/boot=35mb;380;428;0;476
Running the Nrpe service
[Email protected] ~]# TAR-XF nrpe-2.12.tar.gz
[Email protected] nrpe-2.12]# Useradd Nagios
[Email protected] nrpe-2.12]# Groupadd nagcmd
[Email protected] nrpe-2.12]# usermod-g Nagios Nagios
[[email protected] nrpe-2.12]# yum-y install openssl-devel (Install encrypted transfer)
[Email protected] nrpe-2.12]#./configure
[[email protected] nrpe-2.12]# make
[[email protected] nrpe-2.12]# make install
[[email protected] nrpe-2.12]# make install-plugin (install plugin, this plugin is dedicated to connect)
[email protected] nrpe-2.12]# make Install-daemon
[[email protected] nrpe-2.12]# make install-daemon-config (configuration file for this service)
[email protected] nrpe-2.12]# make install-xinetd
[[email protected] nrpe-2.12]# yum-y install xinetd (this service requires xinetd wake-up Nrpe)
[[email protected] nrpe-2.12]# Vim/etc/xinetd.d/nrpe (Nrpe's main profile)
Only_from = 127.0.0.1 192.168.4.1 (IP address of the monitoring server)
[[email protected] nrpe-2.12]# vim/etc/services (add port)
Nrpe 5666/tcp #nrpe
[Email protected] ~]#/etc/init.d/xinetd restart
Modify the configuration file for the NRP service nrpe.cfg, define the monitoring command
[Email protected] ~]# vim/usr/local/nagios/etc/nrpe.cfg
command[command name]= the plugin used
Command[check_2_users]=/usr/local/nagios/libexec/check_users-w 5-c 10
Command[check_2_load]=/usr/local/nagios/libexec/check_load-w 15,10,5-c 30, 25,20


Monitor-side configuration (zhuji1:192.168.4.1)
Define monitoring Commands
[[email protected] nagios]# tar-xf nrpe-2.12.tar.gz
[[email]  protected] nagios]# yum-y install openssl-devel
[[email protected] nrpe-2.12]#./configure
[[email& Nbsp;protected] nrpe-2.12]# make all
[[email protected] nrpe-2.12]# make install-plugin (install plugin)
Use plug-ins to connect the Nrpe service of the monitored host and test the defined monitoring commands
[[email protected] nrpe-2.12]#/usr/local/nagios/libexec/check_nrpe-h 192.168.4.2-c check_2_users (call Zhuji2 's monitoring command)
users OK-2 users currently logged in |users=2;5;10;0
[[EMAIL&NBSP;PR Otected] nrpe-2.12]#/usr/local/nagios/libexec/check_nrpe-h 192.168.4.2-c check_2_boot
DISK ok-free space:/Boot 4 (92% inode=99%)/boot=35mb;380;428;0;476
Define monitoring Commands
[[email protected] ~]# vim/usr/local/nagios/etc/ Objects/commands.cfg
Define command{
Command_name check_2_users
command_line $USER 1$/check_nrpe-h 192.168.4.2-c check_2_users
}

Define Command{
Command_name Check_2_boot
Command_line $USER 1$/check_nrpe-h 192.168.4.2-c check_2_boot
}

Define Command{
Command_name check_2_process
Command_line $USER 1$/check_nrpe-h 192.168.4.2-c Check_2_procs
}

Define Command{
Command_name check_2_zombieprocess
Command_line $USER 1$/check_nrpe-h 192.168.4.2-c Check_2_zombie_procs
}
[Email protected] objects]#/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg
[Email protected] objects]#/etc/init.d/nagios restart

Linux Nagios Monitoring

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.