NAGIOS (Network monitoring tool)

Source: Internet
Author: User
Tags http authentication rrdtool snmp snmp module

Nagios is an open-source, free network monitoring tool that effectively monitors Windows, Linux and UNIX host status, switches, routers and other network devices, printers, and more.
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.

Network Monitoring Tool NAGIOS

Defined
Nagios is a monitoring system that monitors the system's operational status and network information.
Nagios can monitor the specified local or remote host and service, as well as provide exception notification functionality.
Nagios can be run on the Linux/unix platform,
An optional browser-based web interface is also available to allow system administrators to view network status, various system issues, and logs.

function Introduction
The features that Nagios can monitor are:
1, monitoring network services (SMTP, POP3, HTTP, NNTP, ping, etc.);
2, monitor the host resources (processor load, disk utilization, etc.);
3, simple plug-in design allows users to easily expand their services to detect methods;
4, parallel service inspection mechanism;
5, with the ability to define the hierarchical structure of the network,
The "parent" host definition is used to express the relationship between the network hosts, which can be used to discover and clarify the host outage or unreachable state;
6, when the service or host problems arise and resolve the alarm sent to the contact person (via email, SMS, user-defined mode);
7, can define some processing procedures, so that it can be in service or host failure to play a preventive role;
8, automatic log scrolling function;
9, can support and implement redundant monitoring of the host;
10, the optional web interface for viewing the current network status, notification and fault history, log files and so on;
11, can be viewed through the mobile phone system monitoring information;
12, can specify the custom event processing controller;



System Requirements
Nagios requires that the machine must be able to run Linux (or a UNIX variant) and have a C language compiler.
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 a CGI program,
You have to install the following software ... A Web service (preferably Apache)

System Installation
1. Install the Base Support kit and add users
Nagios requires some basic support packages to run, such as APACHE,GCC,GLIBC,GD libraries.
Add a user named Nagios to run Nagios specifically
Set Password
Add a Nagcmd user group to submit an external control command via a Web page
Joining Nagios users to the Nagcmd group
Adding Apache users to the Nagcmd group
2. Install Nagios
Now that Nagios is basically installed, it's no problem that the default installation profile is used to start Nagios.
Modify Nagiosadmin This line where the email address is your email address to send the alert email to your mailbox
Installing the Nagios Web interface
Set the password for HTTP authentication when landing the Web interface
3. Installing Nagios-plugins
Nagios-plugins is a plug-in program officially provided by Nagios,
The capabilities of the Nagios monitoring host are actually implemented by the execution of the Plug and Go program.
4. Installing Nagios-snmp-plugins
Nagios-snmp-plugins is a set of plug-in programs written in Perl that monitor hosts via SNMP.
Configuring the use of these plug-ins requires configuration Cpan,cpan is the abbreviation for comprehensive Perl Archive network.
It is a huge collection of Perl software, with a large collection of useful Perl modules (modules) and their associated files.
This is mainly the use of the PERL-NET-SNMP module. There are two ways of installing:
A) installation via CPAN
B) Manual Installation
First go to the official website to download the following several modules
Crypt::D es
Digest::md5
Digest::sha1
Digest::hmac
Net::snmp
After downloading, install the following for each module in turn
Indicates the module name, please replace the module as mentioned above
Note: The NET::SNMP module must be installed at the end. This NET::SNMP manual installation is complete
Executes the Nagios-snmp-plugins installation script and installs the plug-in command to/usr/local/nagios/libexec after execution
5. Other Settings
Nagios is basically installed, but you can't start nagios right away, and you need the following settings.
Add Nagios to the service
Set the service to self-boot
To detect if the Nagios configuration is correct, we need to constantly execute this command to check the configuration file in order to detect the correctness of the configuration after the Nagios process is configured.
#service Nagios start to start Nagios
It is important to note that CentOS is turned on by default for SELinux and is running in forced security mode.
This will cause Internet Server error errors to occur when you open the Nagios Web interface.
To see if it is running in force mode,
The result for 1 is to change the SELinux run in tolerant mode
However, this setting will fail after reboot,
If you need to change the/etc/sysconfig/selinux after rebooting,
Change the selinux= enforcing to selinux= permissive and restart the system.
Of course you can also change to disable disable SELinux.
You can also do this without changing the operating mode of SELinux, with the following workaround:
6. Implement MSN Alarm
To implement MSN Alarm requires the use of Phpmsnclass, which is a PHP implementation of the MSN Robot Program.
Download Phpmsnclass, this file is in 7zip compression format,
Need to install 7zphpmsnclass requires PHP support, install PHP,
The installation of the lamp environment is done directly here for convenience
Install MySQL database and install cacti later
For security reasons, set MySQL to listen only on the 127.0.0.1,
and delete all the default in MySQL library except for all the users, related settings see previous about Postfix installation in the settings.
Installing PHP-related modules
MSN Alarm There are 2 ways, one is to use PHP directly to the login verification to send messages, the other is the form of MSN robot sent, the message stored in the directory.
The second type is used here.
Now copy the msnbot.php, config.php and msn.class.php to the/var/spool/msnbot/.
How this robot works is if you want to send a message,
Just call PHP to generate the message file into the/var/spool/msnbot/spool directory.
The sender checks that the directory has a new file that simulates the MSN login and sends the message out.
Set up MSN's account number and password in the configuration file (after the alarm is sent via MSN)
Plus Execute permissions
PHP (with space after PHP) to execute PHP files in the startup function
Start the MSN Robot
Let's send a message and test it.
If you successfully receive a message stating that the configuration is correct, this step ends with the ability to let Nagios use MSN to alert you to Nagios settings.
If you need to support offline messages when you are offline, you can also receive information about the robot, you need to use the MSNP15 protocol, modify the relevant PHP file will declare the new class where the first parameter of MSN changed to MSNP15
System Configuration
Nagios directory structure is clear, after installation of the following a total bin etc libexec Sbin share var several directories, where the configuration files are stored in the ETC directory, the bin is stored in the Nagios related commands,
Sbin is stored in the Web-based external execution of cgi,libexec storage is all plug-ins,
Var, however, stores log and PID files. Implementation of the monitoring is based on the implementation of plug-ins to achieve.
To implement monitoring, you need to define a service in Nagios that specifies monitoring objects and monitoring commands, as well as alarm mechanisms, in this service. The configuration relationship for Nagios can be described as follows:
Nagios configuration is also clear, the ETC directory is the default objects directory and some configuration files, where objects is the main configuration file nagios.cfg included in the configuration file.
In Nagios.cfg, you can either specify a single CFG, or you can specify an include directory in which all the CFG files in the directory are included.
First we configure the main configuration file, in order to clear the directory of our own set up some directory to store the relevant configuration files,
For example, the establishment of commands directory Storage command, the establishment of services directory hosting service, the establishment of the hosts directory host, the Nagios.cfg file found in the Cfg_file section, the following is an example, the actual deployment can be set according to your own situation:
NAGIOS cfg_file=/usr/local/nagios/etc/objects/commands.cfg contains configuration files,
Same below
First of all, the monitoring is to rely on plug-ins to complete,
For example, if we want to monitor the virtual memory of the 60.222.111.83 server, when it reaches 70%, the state is a warning, and when it reaches 90%, it is a serious one. This depends on the plugin to complete.
-
Where the-h parameter represents the host address, the-c parameter represents the SNMP community name, and 2 indicates the threshold value of the SNMP V2 protocol,-W is the warning (warning) state, and-C is the threshold for the critical (critical) state
To monitor a host with Nagios is to implement a command called this with Nagios.
Configuration resource.cfg, File contents:
[email protected] etc]# cat resource.cfg |grep-v ' # ' | Sed/^$/d//view RESOURCE.CFG configuration
$USER 1$=/usr/local/nagios/libexec
$USER 7$=-c mypublic-2
This is actually the definition of two variables $user1$ and $user7$, because the path of the plugin is the absolute path when the command is defined later,
In order to save the input directly you can replace/usr/local/nagios/libexec with $user1$.
The parameters in the command line of the SNMP plug-in need to set SNMP-related information,
To save the input here use $user7$ instead of-C mypublic-2.
You can understand this by comparing the example of virtual memory detected 60.222.111.83 above.
Let's define a command to monitor, and still use the virtual memory of the host to monitor 60.222.111.83 in Nagios as an example.
For the clarity of the directory structure, we put the command definition in the commands directory.
Create a cfg suffix file under commands
The $user1$ and $user7$ are the two variables we defined in the above resource.cfg,
$HOSTADDRESS $ for the host we want to define below.
So we complete the definition of a service, we define the monitoring object here we define 3 groups,
All hosts that belong to these 3 groups will detect virtual memory (note: Groups must be defined beforehand in other files).
Of course you can also use HOST_NAME to target the host as a detection object (multiple hosts separated by commas).
Monitoring cycles and alarm cycles we set up 24x7, and this is defined later.
The definition of W in the alarm state indicates that the warning,u indicates that the UNKNOWN,C represents critial,r for recovery (i.e. whether notification is sent after recovery);
Alarm options The W,C,R can be set in general production environment.
Finally we see the main part of implementing monitoring
Check_command check_snmp_storage!-m "^virtual memory$"!70!90
Define the command that implements this detection, Check_snmp_storage is the command name we defined above in commands,
! Represents the parameters brought in, here are three! Represents three parameters into the command, with each parameter used! Delimited, this indicates that the first parameter is-M "^virtual memory$", the second parameter is 70, and the third parameter is 90.
The $arg1$ here represents the parameter 1, $ARG 2 means the parameter 2, $ARG 3$ means the parameter 3
And $hostaddress$ is our definition of the detection object, its value is our host IP address, $USER 1$ and $user7$ for the definition in the resource.cfg.
And this command is the command that we implement to monitor 83 of virtual memory!
Set 3 parameters for the flexible call for different host, if you set different thresholds for different host, only need to define different service for different hosts, command can be universal!
The parameter 1 here is also set to achieve different functions, the script can also detect physical memory,
If we set the value of parameter 1 to "^phisical memory$", we can detect the physical memory!
When you define the command, you can set the number of parameters as you want.
You only need to be able to put the parameter values into the command in the back service and eventually implement the commands you want to detect.
So far you can feel the flexibility of nagios.
We have basically implemented Nagios's monitoring function here, so let's continue to look at the other settings.
When we define the host, we have a set of hosts template, the definition of this setting is defined in Object/template.cfg, this is a system comes with the configuration file, about the template that we use Windows-server definition content is:
Above I added two alarm commands for NOTIFY-SERVICE-BY-MSN and notify-service-by-msn in this configuration file
And the alarm period is set in the objects under the timeperiods.cfg, as we have defined in the service above the 7x24 alarm cycle setting content is
Here we can flexibly set the alarm time to combine with the alarm mode, such as weekend and rest time set alarm for sending SMS and mail, working time set to send mail and MSN alarm mode.
4 Kinds of ALARM commands are defined, and two kinds of MSN alarms are added by me; Email alerts are sent using the system's own sendmail (note to start the SendMail service), and the MSN Alert is the alarm message sent using the MSN Robot we configured above.
The entire Nagios monitoring and alerting mechanism is now complete. Note that any changes we make during the configuration process are remembered to go through the/usr/local/nagios/bin/nagios–c/usr/local/nagios/etc/ Nagios.cfg to check if the configuration file is correct, you can restart Nagios to load the new configuration if it is correct (service Nagios restart)
Part III installation cacti
Cacti operation requires amp (Apache + MySQL + PHP), RRDTool, NET-SNMP, AMP Environment which we have configured above.
Installation Rrdtool,rrdtool cannot be installed directly through Yum and can be joined to Dag RPM repository so that Yum can find RRDtool
Installing cacti
To begin importing the database below, the basic security configuration of the MySQL database is not described here, please refer to the MySQL Settings section in the previous Postfix mail installation documentation.
Mysql>create Databasecacti; Create a database for cacti use
mysql>usecacti;
Mysql>source/usr/local/cacti/cacti.sql//import MySQL Database
Mysql>grant all Privileges oncacti.* [e-mail protected] by ' cactipass ';
Add a Database account cacti password is cactipass to access the cacti library
Mysql>flush privileges; Refresh Permission Information
Apache Settings
#vi/etc/http/conf.d/cacti.conf//Edit the configuration file of the cacti site with the following file contents:
Alias/cacti "/usr/local/wwwroot/cacti"
Options FollowSymLinks MultiViews
AllowOverride None
Order Allow,deny
Allow from all
Modify the Cacti configuration file
Modify the database connection information, set the database host address, user, password information.
At this point the installation is complete, access is prompted to install cacti (IP for your corresponding host IP address)
Next install cacti plug-in management
Copy related files to cacti
Part IV consolidates cacti and Nagios
Integrating cacti and Nagios is a plugin of cacti, nagios for cacti, which works by importing Nagios data through ndo2db into the MySQL database (the cacti library). Then cacti reads the database information and displays the results of Nagios.
1. Installing Ndoutils
First, you need to install Ndoutils to import Nagios data into the MySQL database.
Modifying the Nagios master configuration file
Add the following content
Check_external_commands=1
Command_check_interval=-1
Event_broker_options=-1
BROKER_MODULE=/USR/LOCAL/NAGIOS/BIN/NDOMOD.O config_file=/usr/local/nagios/etc/ndomod.cfg
Process_performance_data=1
Add content to this end
2. Installing Php-json
NPC Display part JSON, need to install Php-json support in PHP, CentOS 5 PHP version by default is 5.1.6 without JSON support, can not be easily installed through the Yum install Php5-json mode.
#cd ~/downloads
Initializing the PHP environment before compiling
Restart Apache
In order to verify success, you can use Phpinfo to see if JSON is supported
3. Install NPC
Enable the cacti plug-in function, with the Admin user login cacti, in the console user Management in the admin users to edit, tick plugin Management, and then to the plug-in management center to install and enable NPC. This completes the integration of Nagios and cacti.

Note: The contents of the essay are from the online data collation, for reference only.

NAGIOS (Network monitoring tool)

Related Article

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.