Nagios Introduction and Installation (1)

Source: Internet
Author: User
Tags snmp disk usage

It is a complicated process to build nagios, first of all it requires the reader to have a Linux foundation, the most important thing is to spend a lot of energy and time, there is patience and careful. I mainly refer to this article on the Internet, I think the writing is very good.

Original:

Http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html

http://www.ibm.com/developerworks/cn/linux/1309_luojun_nagios/


I. About Nagios

650) this.width=650; "title=" Nagios logo "src=" http://images.cnitblog.com/blog/370046/201301/ 30172011-56b472de18914a4b90065e303e02e0f0.png "alt=" Nagios logo "width=" 212 "height=" "border=" 0 "style=" margin : 6px 0px 0px 19px;padding:0px;border:0px;float:right;background-image:none; "/>

Nagios is an open source computer system and network monitoring tool that can effectively monitor Windows, Linux and UNIX host status, switch routers and other network settings, printers, etc. Send mail or SMS alarm when the system or service status is abnormal the first time to notify the site operators, after the status of the resumption of normal mail or SMS notification.

    nagios is a plug-in structure, it does not have any monitoring function, all the monitoring is through the plug-in, it is highly modular and flexible. The objects that Nagios monitors can be divided into two categories: Hosts and services. A host typically refers to a physical host, such as a server, router, workstation, printer, and so on. A service typically refers to a particular feature, such as a httpd process that provides an HTTP service. For the convenience of management, the host and service can also be planned as the main unit and service group. Nagios does not monitor any specific numerical indicators (such as the size of the traffic, the number of processes, etc.) simply by analyzing the returned status value, which describes the state of the monitored object using only four abstract attributes: OK, WARNING, CRITICAL, UNKNOWN. As a result, administrators only need to focus on and define the thresholds for the warning and critical of a monitored object. Nagios passes the thresholds of the warning and critical states to the plug-in, and the plug-in is responsible for monitoring and analyzing the results of a specific object, which is output as state information (ok, WARNING, CRITICAL, UNKNOWN ).

Nagios, formerly known as Netsaint, was developed and maintained by Ethan Galstad. Nagios is an abbreviated form: "Nagios Ain t gonna insist on sainthood" sainthood translated into saints, while "Agios" is the Greek representation of "saint". Nagios is developed for use under Linux, but it works very well under UNIX.

Key Features

    • Network Service Monitoring (SMTP, POP3, HTTP, NNTP, ICMP, SNMP, FTP, SSH)

    • Host resource monitoring (CPU load, disk Usage, system logs), and also includes Windows hosts (using nsclient++ plugin)

    • Can specify the plugin you write to collect data over the network to monitor any situation (temperature, warning ...).

    • Can execute scripts remotely by configuring the Nagios remote execution plug-in

    • Remote monitoring supports SSH or SSL plus channel monitoring

    • The simple plugin design allows users to easily develop their own inspection services, supporting many development languages (shell scripts, C + +, Perl, Ruby, Python, PHP, C #, etc.)

    • Contains many graphical data plugins (Nagiosgraph, Nagiosgrapher, Pnp4nagios, etc.)

    • Can be parallel service check

    • Can define the hierarchy of network hosts, Allow step-by-step checks, starting from the parent host to check for

    • When a service or host issue occurs, you can notify by email, pager, SMS or any user-defined plugin

    • Ability to customize event handling to reactivate a problematic service or host

    • Automatic log loop

    • Support for redundant monitoring

    • Includes web interface to view current network status, notifications, problem history, Log files, etc.

II. Nagios Structure

Nagios is structurally divided into two parts of the core and plugin . The core of Nagios only provides very little monitoring, so to build a complete it monitoring management system, users also need to install the appropriate plugin on the Nagios server, plug-ins can be downloaded from the Nagios official website http://www.nagios.org/, You can also write your own required plugins according to the actual requirements.

Nagios Core: It basically does not do any monitoring work, all the monitoring functions are completed by plugins.


Iii. working principle of Nagios

Nagios's function is to monitor the service and host, but he does not include this part of the function, all the monitoring, detection functions are through a variety of plug-ins to complete.

After you start Nagios, it periodically automatically calls the plug-in to detect the server state, while Nagios maintains a queue, all the status information returned by the plug-ins goes into the queue, and Nagios reads the information from the beginning of the team and processes it, displaying the status results over the web.

Nagios provides a number of plug-ins that allow you to easily monitor many service statuses. After the installation is complete, there are all the plugins available in Nagios's/libexec in the Nagios home directory, such as Check_disk is the plug-in that checks the disk space, Check_load checks the CPU load, and so on. Each plugin can be used to view its usage and functionality by running the./check_xxx–h.

Nagios can identify 4 status return information, 0 (OK) indicates that the status is normal/green, 1 (WARNING) indicates a warning/***, 2 (CRITICAL) indicates a very serious error/red, 3 (UNKNOWN) indicates an unknown error/deep. Nagios determines the state of the monitored object based on the value returned by the plug-in, and displays it through the Web for administrators to detect faults in a timely manner.

Four monitoring states

650) this.width=650; "title=" 2 "src=" http://images.cnitblog.com/blog/370046/201301/ 30172016-8d40420c5c50475cb6ee600cd5305716.jpg "alt=" 2 "width=" 640 "height=" 123 "border=" 0 "style=" margin:0px; Padding:0px;border:0px;background-image:none; "/>

Besides the alarm function, if the monitoring system found that the problem can not be reported that there is no meaning, so the alarm is also nagios is one of the most important features. But, again, Nagios does not have the code for the alarm part, or even the plugin, but to the user or other relevant open source project team to do it.

Nagios software needs to be installed on a separate server, called the Monitoring Center, the Monitoring Center server can use Linux or Unix operating system; each monitored hardware host or service runs a Nagios software daemon that communicates with the Monitoring Center server, It can also be understood as either an agent or a plug-in. The Monitoring Center server reads the instructions in the configuration file to communicate with the remote daemon and instructs the remote daemon to perform the necessary checks. Although Nagios software must run on a Linux or Unix operating system, the remotely monitored machine can be any host that can communicate with it.

Figure 1. Nagios monitoring schematic diagram

650) this.width=650; "alt=" Nagios monitoring schematic "src=" http://www.ibm.com/developerworks/cn/linux/1309_luojun_nagios/ Image003.jpg "width=" 547 "style=" margin:0px;padding:0px;border:0px;font-size:13px;vertical-align:baseline; Font-family:arial, Sans-serif;line-height:15.359999656677246px;white-space:normal;background-color:rgb ( 255,255,255); "/>

Objects that can be monitored (close links between objects, references to each other)

    • Host object physical host, router, switch, printer, etc., can be categorized as a group

    • Services/Resources are collectively referred to as services and can be categorized as groups

    • Contact person and Contact Group

    • Period of time for the above three types of objects to monitor the way

    • The command (template) is applied to a monitored object for specific monitoring

Nagios is highly resilient, and its monitoring capabilities can be performed exactly as administrators expect. All of these features are implemented based on a well-structured object definition system and a few object types.

Command (commands)

Commands are used to define how Nagios performs a specific monitoring work. It is a layer of abstraction that is defined based on a particular Nagios plug-in, and typically contains a set of actions to be performed.

Period (time periods)

A period is used to define a date and time span that an action can or cannot perform, such as a daily 8:00-18:00 within a weekday.

Contacts and Contacts group (contacts and contact groups)

A contact is used to define a notification object for a monitoring event, the information to be notified, and when and how those recipients receive notifications; One or more contacts can be defined as contact groups, and one contact can belong to more than one group.

Hosts and host groups (host and hosts groups)

A host usually refers to a physical host, which includes the recipient (contact) of the notification information associated with this host, and how and when the definition of the monitoring is made. Hosts can also be grouped, and a host can belong to more than one group at a time.

Service (services)

A service usually refers to a specific feature or resource that can be monitored on the host, including the recipient of the notification information associated with the service, how and when it is monitored, and so on. Services can also be grouped, and service groups, and a service can belong to multiple service groups at the same time.

Multiple monitored objects if you have multiple properties that can be defined as templates (template), you can apply a template to an object, and then define its own unique properties. It sounds familiar.

Yes. This is the view of object-oriented (OOP) . We can abstract things like properties into a class, and then we can instantiate an object through this class.


Relationships between individual objects

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/42/C0/wKioL1PYtwXSgbKhAADaLKMSTsM841.jpg "title=" Cache.png "alt=" Wkiol1pytwxsgbkhaadalkmstsm841.jpg "/>

How do i add a monitored device?

The process of creating a monitored object that instantiates an object from a template.

How to monitor an object?

by command, a command is the process of instantiating a plug-in.

How to notify, to whom?

This is the contact person.


Dependencies between objects

Why do you need to define dependencies?

For example, a routing device failure will inevitably cause the other hosts associated with it can not be properly accessed, if the dependency between these devices can not be defined, then the monitoring system will inevitably appear a large number of device failure information. Nagios describes the topology of network devices through dependency relationships, and it can realize the detection of other devices that are no longer dependent on this device when a device fails, thus avoiding unnecessary fault information and convenient for the administrator to locate and troubleshoot in time.



Four, Nagios monitoring mode

As can be seen, plug-ins are mainly divided into 5 categories, and its monitoring methods also have 5 major categories.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/42/C0/wKioL1PYsubCGmc-AAGAKypInWs312.jpg "title=" 1.png " alt= "Wkiol1pysubcgmc-aagakypinws312.jpg"/>

    1. Nrpe mode (dedicated for monitoring the Unix/linux class of the host)

      The Nrpe daemon and additional plugins need to be installed on the monitored side, and the Nrpe plugin will be installed on the Nagios server side.

      650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/42/C0/wKioL1PYtTHgoaLwAADb5V2h0hw602.jpg "title=" 1.png " alt= "Wkiol1pytthgoalwaadb5v2h0hw602.jpg"/>

    2. Ssh

      The remote host is the client of SSH on the Nagios server, and the server installed on the client is SSH service-side sshd. The implementation process is: from the SSH to the server sshd send the request command, and return the results to the CHECK_BY_SSH plug-in, the plug-in to return the results of analysis, the analysis of the results back to the plug-in core, from the core to determine whether the results of the alarm.

    3. Snmp

      The communication mechanism based on SNMP and SNMPD

    4. NSCA

      Allow Nagios to implement passive monitoring, and the client proactively sends information to Nagios

    5. Check_xyz

      Users can define their own name plug-in type, direct access to remote host data


Five, Nagios installation

System Requirements

Nagios requires that the machine be able to run Linux (or a UNIX variant) and have C compiler gcc. You must properly configure the TCP/IP stack so that most service detections can be performed over the network.

You need but do not have to properly configure the CGIs program in Nagios, and once you want to use the CGI program, you have to install the following software ...

    • A Web service (preferably Apache)

    • The GD library version produced by Thomas Boutell should be 1.6.3 or higher (this library is required in the two modules of the CGIs program module STATUSMAP and trends)


Nagios is typically comprised of a main program (Nagios Core), a plug-in program (Nagios-plugins), and four optional addon (NRPE, NSCA, nsclient++,ndoutils).

Nagios's monitoring work is done through plugins. Therefore, Nagios and nagios-plugins are the necessary components for server-side work.

In addon

    • The Nrpe is used to execute script plugins on monitored remote Linux/unix hosts to monitor these host resources.

    • NSCA is used to proactively notify the Nagios server of a monitored remote host

    • nsclient++, a component that is installed on Windows when it is used to monitor Windows hosts

    • The ndoutils is used to store the configuration information of Nagios and the data generated by each event into a database for fast retrieval and processing of these data. Compiling requires specifying the --enable-event-broker option.

Of these four addon, Nrpe and nsclient need to be installed on the monitored side, doutils work on the Nagios side, and NSCA need to be installed both on the Nagios server side and on the monitored side.


Server-side: At least Nagios core, Nagios Plugins, Optional (NRPE, NSCA, SNMP)

Monitored: If linux, you need to install Nagios plugins, NRPE (because NRPE relies on the former)

If it is windows, install nsclient++.


1, prerequisites

[[email protected] ~]# yum-y install wget httpd php gcc glibc glibc-common gd gd-devel make NET-SNMP

2. Download Nagios Core and Nagios Plugins Tarballs

[Email protected] ~]# wget [[email protected] ~]# wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz

3. Adding the Nagios User and Group

# Nagcmd Group is used to execute external commands from the web interface [[email protected] ~]# groupadd nagcmd[[email protected] ~]# useradd-g nagcmd-c ' Nagios Admin ' na Gios[[email protected] ~]# passwd nagios# append Apache to the Nagcmd group to allow sufficient permissions to operate Nagios via web interface [[email protected] ~] # usermod-a-G Nagcmd Apache

4. Compile and Install

[[Email protected] ~]# tar xf nagios-4.0.7.tar.gz -c /usr/local/src[[email  protected] ~]# tar xf nagios-plugins-2.0.3.tar.gz -c /usr/local/src[[email  protected] ~]# cd /usr/local/src[[email protected] src]# cd  nagios-4.0.7/# --enable-event-broker  is preparing for ndoutils [[email protected] nagios-4.0.7]# . /configure --sysconfdir=/etc/nagios --with-command-group=nagcmd --enable-event-broker# all  systems:# make all# make install # make install-init # make  install-config # make install-commandmode # make install-webconf#  Nagios web Theme # make install-exfoliation  or  make install-classicui#  cp -r contrib/eventhandlers/ /usr/local/nagios/libexec/# chown -r nagios: Nagios /usr/local/nagios/libexec/eventhandlers###  /usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg#  service nagios start# service httpd start### nagios service setup#  chkconfig --add nagios# chkconfig nagios on# chkconfig --add  Httpd# chkconfig httpd on

5. Create a Default User for Web Access

# htpasswd-c/etc/nagios/htpasswd.users nagiosadmin## Note htpasswd.users This file is best placed in the Nagios configuration directory

By default, when Nagios is installed, a configuration file is created in the Apache profile directory, usually nagios.conf. It defines Nagios's directory aliases, access control, and so on.


6. Nagios Plugin Installation

The various monitoring functions provided by Nagios are basically done via plug-ins, and the core of Nagios only provides minimal monitoring capabilities, so installing plugins is essential. The Nagios official website offers a number of plug-in applications for different tiles, with no connection between the plugin version and the Nagios version.

[[email protected] ~]# Cd/usr/local/src[[email protected] src]# CD Nagios-plugins-2.0.3/[[email protected] nagios-plugins-2.0.3]#./configure--with-nagios-user=nagios--with-nagios-group=nagios[[email protected] nagios-plugins-2.0.3]# make && make install

In this way, the plug-in is installed, by looking at the Nagios installation directory,/usr/local/nagios/libexec directory, you can see a lot of external plug-ins.

7. SELinux and Iptables

If the SELinux service is turned on, the run of the Nagios Web CGI program is denied by default.

# # # Temporary close Selinux[[email protected] ~]# getenforceenforcing[[email protected] ~]# Setenforce 0### permanent shutdown selinux# If you want to completely turn off SELinux, you can edit the/etc/sysconfig/selinux file and change the selinux=enforcing to # to selinux=disabled. But need to reboot # # # change SELinux behavior # chcon-r-T httpd_sys_content_t/usr/local/nagios/sbin# chcon-r-T Httpd_sys_content_t/usr/loca l/nagios/share### iptables# service iptables stopor# iptables-i input-p TCP--dport 80-m State--state new,established -j ACCEPT


8. Nagios Web Interface

After correctly following the procedures your should now being able to access your Nagios Core installation from a Web browser .

Simply Use the following: Http://<your.nagios.server.ip>/nagios

and log in with the credentials chose when adding the Nagiosadmin uesr to the Htpasswd.users file.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/42/CA/wKiom1PYyVnQRgqdAAGy8-JBE3c934.jpg "title=" 9.png " alt= "Wkiom1pyyvnqrgqdaagy8-jbe3c934.jpg"/>



This article is from the "Share Your Knowledge" blog, so be sure to keep this source http://skypegnu1.blog.51cto.com/8991766/1532948

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.