Build Nagios Monitoring Server

Source: Internet
Author: User

Linux monitoring IDC Monitoring

Monitored objects: servers (operation and maintenance jobs)
What to monitor: (resources)
1. Usage of hardware (CPU memory storage)
2, monitoring the status of application services (running stop)
3. Operation of operating system (number of users in process quantity system)
4, network Interface data traffic (in and out)

How to monitor?
Execute a custom monitoring script using Crond
The system provides the corresponding commands to view
Monitoring using software to build monitoring services

Nagios Monitoring Server
Monitoring Server Environment 192.168.4.21
First, the Deployment lamp service
Yum installs httpd, mariadb, Mariadb-server, PHP, Php-mysql
[Email protected] ~]# vim/var/www/html/test.php
<?php
$x =mysql_connect ("localhost", "root", "123456");
if ($x) {echo "OK";} else{echo "err";};
?>

#################################################################
Ii. installation of Nagios (source package)
2.1 Installation Preparation: Compiling tools to create users and groups
[Email protected] ~]# rpm-q gcc gcc-c++
[Email protected] ~]# Useradd Nagios
[Email protected] ~]# Groupadd nagcmd
[Email protected] ~]# usermod-g nagcmd Nagios
2.2 Package: Unpacking configuration Compilation Installation View installation information
[Email protected] ~]# Tar XF nagios-4.2.4.tar.gz
[Email protected] ~]# CD nagios-4.2.4
[Email protected] nagios-4.2.4]#/configure--help | More
--with-command-user=

[Email protected] nagios-4.2.4]#/configure--with-nagios-user=nagios \

--with-nagios-group=nagcmd--with-command-user=nagios \
--with-command-group=nagcmd
[[email protected] nagios-4.2.4]# make all//compile
[[email protected] nagios-4.2.4]# make install//install Program
[[email protected] nagios-4.2.4]# make Install-init//install control script
# Vim/etc/rc.d/init.d/nagios Get this script
[[email protected] nagios-4.2.4]# make Install-commandmode//tune permissions
[[email protected] nagios-4.2.4]# make Install-config//installation configuration
[[email protected] nagios-4.2.4]# make install-webconf//deploy Web site Configuration
[[email protected] nagios-4.2.4]# make install-exfoliation//determine page style

2.3 Installation Directory Description
[Email protected] nagios-4.2.4]# ls/usr/local/nagios/
Bin (Executable command) Etc (config file) libexec (monitoring plug-in) sbin (CGI file) share (web file) var (log file status information file)
[Email protected] nagios-4.2.4]# cd/usr/local/nagios/
[[email protected] nagios]# ls bin
Nagios (Verify that the configuration is correct) nagiostats (Display monitoring status information)

2.4 Installing the monitoring plug-in
[[[email protected] ~]# tar-zxf nagios-plugins-2.1.4.tar.gz
[[email protected] ~]# CD NAGIOS-PLUGINS-2.1.4/
[[email protected] nagios-plugins-2.1.4]#./configure &&make &&make Install
[[email protected] nagios-plugins-2.1.4]# ls/usr/local/nagios/libexec/

2.5 Start the Nagios monitoring service
(1) Set the user (Nagiosadmin) and password (custom) of the Login monitoring page
[[email protected] nagios-plugins-2.1.4]# vim/ Etc/httpd/conf.d/nagios.conf viewing the user's path to the monitoring page
[[email protected] ~]# htpasswd-c/usr/local/nagios/etc/ Htpasswd.users nagiosadmin
[[email protected] ~]# ls/usr/local/nagios/etc/
Cgi.cfg htpasswd.users Nagios.cfg objects Resource.cfg
[[email protected] ~]# cat/usr/local/nagios/etc/htpasswd.users
Nagiosadmin: $apr 1$kgjigeh. $VTF 6vv.y7lrv4t7t48r7a1
[[email protected] ~]# systemctl Restart httpd//Restart website service
[[email protected] ~]#/etc/rc.d/init.d/nagios status//view Nagios status
No lock file found in/usr/local/nagios/ Var/nagios.lock
[[email protected] ~]#/etc/rc.d/init.d/nagios start/start Nagios service
Reloading systemd: [OK]
Starting Nagios (via Systemctl): [OK]

The default is to monitor the machine without any configuration:
CPU Load Check_load
Number of logged on system users check_users-w 1-c 3
Web Service Run Status check_http-h IP address [-p port]
PING check_ping
Root partition Check_disk
SSH Service Check_ssh
Swap partition Check_swap
Number of processes Check_procs
Connect the destination host's TCP protocol port check_tcp-h IP address-p port
###################################################################

Third, on the Client Access Monitoring page to view monitoring information
Ping-c 2 192.168.4.21
Firefox Http://192.168.4.21/nagios

###################################################################

Iv. Configuring the Nagios service
4.1 monitoring process
Monitoring status: Ok (normal) Warning (warning) Unknown (not known) Critical (Critical error) Pending (monitoring)
The Nagios service run is to load the master profile ngaios.cfg, call the monitoring plug-in in the configuration file, the OPS can set the plug-in's monitoring thresholds (warning values and error values); The Nagios service plug-in compares the monitored data to the monitoring thresholds, showing the monitoring status based on the comparison results:
Monitored data < warning values show OK
Data > Warning values that are monitored and < error values display warning
Monitored data > error value display critical
cannot find the called monitoring plug-in Unknown
is Get Data Pending
#################################################################
4.2 monitoring plug-in use
[[email  protected] libexec]# cd/usr/local/nagios/libexec
./plug-in Name-H//View the Help information of the plugin
[[email protected] libexec]# ./check_users-w 1-c 3//Set warning value 1, error value 3
Users WARNING-2 users currently logged in |users=2;1;3;0
[[email protected] libexec]#./check_ping-h 192.168.4.17-w 10,50%-C 20,75%
Ping ok-packet loss = 0, RTA = 0.48 ms|rta=0.476000ms;10.000000;20.000000;0.000000 pl=0%;50;75;0

###########################################################
4.3 Description of the configuration file
[Email protected] ~]# cd/usr/local/nagios/etc
[[email protected] etc# ls
Cgi.cfg htpasswd.users nagios.cfg Objects Resource.cfg

Nagios.cfg (master configuration file)
[[email protected] etc]#/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg//Verify Master Profile
[[email protected] etc]#/usr/local/nagios/bin/nagiostats-c/usr/local/nagios/etc/nagios.cfg//command line output monitoring statistics
Define aliases under/ETC/BASHRC: Alias checknagios= '/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg '

RESOURCE.CFG macro Definition file (sets the variables used by the Nagios service)
$USER 1$=/usr/local/nagios/libexec//default variable user1= plug-in Path

[Email protected] etc]# CD objects/
[[email protected] objects]# ls
Commands.cfg localhost.cfg switch.cfg timeperiods.cfg
Contacts.cfg printer.cfg templates.cfg windows.cfg
++++++++++++++++++++++++++++++++++++++
Commands.cfg defining a file for monitoring commands

Define Command{
Command_name command name
Command_line Path/Plugin Name parameter
}
Vim Commands.cfg
Customize a monitoring command on the last line
Define Command{
Command_name Check_local_boot
Command_line/usr/local/nagios//libexec/check_disk-w 50%-C 25%-p/boot
}
+++++++++++++++++++++++++++++++++++++++++++++++++
Localhost.cfg Monitoring native configuration files
Monitoring host
Define Host{
Use Linux-server template Name
HOST_NAME Host Name
Address the IP addresses of the monitored hosts
}

Monitoring resources
Define Service{
Use Local-service template Name
HOST_NAME Host Name
Service_description Description Information
Check_command command name
}
+++++++++++++++++++++++++++++++++++++++++++++
CONTACTS.CFG designated to receive Monitoring alarm message email address
email [email protected]//34 email alert
Vim/etc/hosts//increase native hostname at 127.0.0.1, while testing whether native mail is working properly
[Email protected] ~]# mail-s "Csadfgas" Nagios </etc/hosts
[Email protected] ~]# Su-nagios
[[Email protected] ~]$ mail
+++++++++++++++++++++++++++++++++++++++++++
Timeperiods.cfg Defining a monitoring time template configuration file
Templates.cfg Defining a monitoring template profile

4.4 Configuring the remote host
4.4.1 Monitoring of public data (services)
4.4.2 Monitoring of private data (System operation)
4.5 Monitoring native Localhost.cfg
To add a new monitoring item to monitor the boot partition of this machine
Change the number of monitoring thresholds for existing monitoring items
Deleting an existing monitor does not monitor the swap partition
Vim Localhost.cfg
############## #my monitor############################
Define Service{
Use Local-service; Name of service template to use
HOST_NAME localhost
Service_description Boot
Check_command Check_local_boot
}





4.6 Monitoring Alarms
[[email protected] ~]# dd If=/dev/zero of=/boot/a.txt bs=1m count=240 make/boot capacity exceeded, if properly configured, there will be alarm message issued
[Email protected] ~]# Su-nagios
[[Email protected] ~]$ mail
N 3 [email protected] Mon Jan 8 06:08 31/897 " problem Service Al"
[[email protected] ~]# rm-rf/boot/a.txt//Delete the superscalar file, simulate the repair success
[[Email protected] ~]$ mail
N 4 [email protected] Mon Jan 8 06:18 31/881 "
RECOVERY Service A"
Monitoring page also displays normal
+++++++++++++++++++++++++++++++++++++++++++++++

Nagios Extended Content
1 invoking custom monitoring scripts when monitoring
2 sending alert messages using a third-party mail server
3 host-dependent monitoring
4 Service Dependent monitoring
5 Let Nagios monitor the data to draw pictures

Build Nagios Monitoring Server

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.