Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

CentOS7.2 deployment Nagios4.4.3

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Nagios is an open source computer system and network monitoring tool, which can effectively monitor the host status of windows,linux,Uninx, switches, routers and other network settings, printers and so on. When the system or service status is abnormal, send an email or SMS alarm to notify the operation and maintenance personnel as soon as possible, and send out a normal email or SMS alarm notice after the status is restored.

Nagios Core is an open source system, and Nagios XI is free of charge. We install the former here.

I. Nagios structure description

Structurally speaking, Nagios can be divided into two parts: core and plug-in. The core part of Nagios only provides few monitoring functions, so in order to build a perfect IT monitoring and management system, users also need to install the corresponding plug-ins on the Nagios server. The plug-ins can download http://www.nagios.org/ from the official Nagios website, or you can write the required plug-ins according to actual requirements.

Features that can be achieved by Nagios:

Monitor network services (SMTP, POP3, HTTP, FTP, PING, etc.)

Monitor local and remote host resources (CPU load, disk utilization, processes, etc.)

Allows users to write their own plug-ins to monitor specific services, easily extend their detection methods for services, and support multiple development languages (Shell, Perl, Python, PHP, etc.)

Have the ability to define the hierarchical structure of the network, and use the "parent" host definition to express the relationship between the network hosts, which can be used to discover and clarify the downtime or unreachable state of the host.

Send alerts to contacts (via EMail, SMS, user-defined methods) when service or host problems are generated and resolved.

Redundant monitoring of hosts can be supported and realized.

The WEB interface can be used to view current network status, notification and failure history, log files, etc.

II. Nagios working principle

The function of Nagiosq is to monitor the service and host, but it does not include this part of the function. All the monitoring and detection functions are completed through various plug-ins.

After starting Nagios, he will periodically automatically call the plug-in to check the server status. At the same time, Nagios will maintain a queue, and all the status information returned by the plug-in will enter the queue. Nagios will read the information from the head of the queue every time, and process it, and display the status result through the web result.

Nagios provides many plug-ins, which can easily monitor the status of many services. After installation, all plug-ins that can be used by nagios are placed in / libexec under the Nagios home directory, for example, check_disk is a plug-in to check disk space, check_load is to check CPU load, and so on. Each plug-in can view usage and functionality by running. / check_xxx-h

Nagios can recognize four status return messages: 0 (OK) indicates normal / green, 1 (WARNING) indicates warning / X color, 2 (CRITTCAL) indicates very serious error / red, and 3 (UNKNOWN) indicates unknown error and dark X color. Nagios judges the status of the monitoring object according to the value returned by the plug-in, and displays it through web to provide the administrator with timely fault detection.

In addition, the alarm function is meaningless if the monitoring system finds that the problem can not be reported to the police, so the alarm is also one of the very important functions of nagios, but, similarly, the Nagios industry does not have the code for the alarm part, or even a plug-in, but gives it to the user or other relevant open source project team to complete.

Nagios installation refers to the basic platform, that is, the installation of Nagios software package, which is the framework of the monitoring system and the basis of all monitoring.

Nagios manages services remotely through NRPE

Nagios executes the check_nrpe plug-in installed in it and tells check_nrpe which services to detect.

Connect the NRPE daemon on the remote computer through SSL,check_nrpe

NRPE runs various local plug-ins to detect local services and status

Finally, NRPE sends the test result to the host side check_nrpe,check_nrpe and sends the result to the Nagios status queue

Nagios reads the information in the queue in turn, and then displays the results.

II. Nagios deployment

Note: Nagios does not have a database by default, so you can install NDOUtils to save Nagios data to the Mysql database.

1. Environmental preparation

Set or stop the firewall:

[root@localhost ~] # systemctl stop firewalld.service [root@localhost ~] # systemctl disable firewalld.service

Turn off selinux:

Temporary shutdown: [root@localhost ~] # setenforce 0 permanently closed (modify configuration file): [root@localhost ~] # vi / etc/selinux/config changed to SELINUX=disabled [root@localhost ~] # rpm-qa httpd* [root@localhost ~] # rpm-e-- nodeps package name has multiple httpd*, with script to delete for name in `rpm-qa httpd* `; do rpm-e-- nodeps $name Done [root@localhost ~] # rpm-Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm[root@localhost ~] # yum install wget lrzsz vim lynx lsof netstat-tools unzip-y

Time zone settings:

[root@localhost ~] timedatectl [root@localhost ~] timedatectl list-timezones # this command lists all time zones [root@localhost ~] timedatectl set-timezone Asia/Shanghai # this command sets the time zone to Shanghai

Time synchronization:

[root@localhost ~] # ntpdate time.nist.gov # if you don't have yum to install this command, [root@localhost ~] # / usr/sbin/ntpdate time.nist.gov [root@localhost ~] # crontab-ecards * / usr/sbin/ntpdate time.nist.gov > / dev/null 2 > & 1

2. Install nagios core with source code (main program)

Reference: https://support.nagios.com/kb/article/nagios-core-installing-nagios-core-from-source-96.html#_ga=2.130440076.2034626946.1559144380-1378811618.1556870555[root@localhost ~] # yum install-y gcc glibc glibc-common wget unzip httpd php gd php-gd gd-devel perl postfix [root@localhost ~] # cd / tmp [root@localhost tmp] # wget-O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4 .3.tar.gz [root@localhost tmp] # tar zxvf nagioscore.tar.gz [root@localhost tmp] # cd / tmp/nagioscore-nagios-4.4.3/ [root@localhost nagioscore-nagios-4.4.3] #. / configure [root@localhost nagioscore-nagios-4.4.3] # make all [root@localhost nagioscore-nagios-4.4.3] # make install-groups-users [root@localhost nagioscore-nagios-4.4.3] # usermod-a-G nagios apache

# install the main program

[root@localhost nagioscore-nagios-4.4.3] # make install [root@localhost nagioscore-nagios-4.4.3] # make install-daemoninit [root@localhost nagioscore-nagios-4.4.3] # systemctl enable httpd.service

# configure directory permissions

[root@localhost nagioscore-nagios-4.4.3] # make install-commandmode

# install sample configuration file

[root@localhost nagioscore-nagios-4.4.3] # make install-config

# install the web interface of nagios and create a nagios.conf file in the / etc/httpd/conf.d directory

[root@localhost nagioscore-nagios-4.4.3] # make install-webconf

After doing this, the following directory will be created under the / usr/local/nagios directory:

The directory where the bin:nagios executor is located, and the nagios file is the main program.

Etc:nagios configuration file directory, when make install-config is finished, the default configuration file will appear under etc.

The directory where the sbin:nagios CGI file is located, where some external command execution programs are stored.

Share:nagios web page file directory, storing some html files.

Directory of var:nagios log files, pid, and other files.

Libexec: the storage location of the system default plug-in

Modify the email address of the nagios warning message

[root@localhost ~] # vi / usr/local/nagios/etc/objects/contacts.cfg email 442102293@qq.com Check_tcp-rwxr-xr-x 1 root root 209501 May 31 11:54 check_hpjd-rwxr-xr-x 1 root root 375004 May 31 11:54 check_http-r-sr-xr-x 1 root root 227225 May 31 11:54 check_icmp-rwxr-xr-x 1 root root 169900 May 31 11:54 check_ide_smart-rwxr-xr-x 1 root root 15283 May 31 11:54 check_ifoperstatus-rwxr-xr-x 1 root root 13435 May 31 31 11:54 check_ifstatuslrwxrwxrwx 1 root root 9 May 31 11:54 check_imap-> check_tcp-rwxr-xr-x 1 root root 6992 May 31 11:54 check_ircdlrwxrwxrwx 1 root root 9 May 31 11:54 check_jabber-> check_tcp-rwxr-xr-x 1 root root 187685 May 31 11:54 check_load-rwxr-xr-x 1 root root 6673 May 31 11:54 check_log-rwxr-xr-x 1 root Root 22741 May 31 11:54 check_mailq-rwxr-xr-x 1 root root 173210 May 31 11:54 check_mrtg-rwxr-xr-x 1 root root 170431 May 31 11:54 check_mrtgtraf-rwxr-xr-x 1 root root 186817 May 31 11:54 check_nagioslrwxrwxrwx 1 root root 9 May 31 11:54 check_nntp-> check_tcplrwxrwxrwx 1 root root 9 May 31 11:54 check_nntps-> check_tcp-rwxr-xr-x 1 root root 219815 May 31 11:54 check_nt-rwxr-xr-x 1 root root 218463 May 31 11:54 check_ntp-rwxr-xr-x 1 root root 208212 May 31 11:54 check_ntp_peer-rwxr-xr-x 1 root root 207193 May 31 11:54 check_ntp_time-rwxr-xr-x 1 root root 250160 May 31 11:54 check_nwstat-rwxr-xr-x 1 root root 9461 May 31 11:54 check_oracle- Rwxr-xr-x 1 root root 193042 May 31 11:54 check_overcr-rwxr-xr-x 1 root root 223263 May 31 11:54 check_pinglrwxrwxrwx 1 root root 9 May 31 11:54 check_pop-> check_tcp-rwxr-xr-x 1 root root 224192 May 31 11:54 check_procs-rwxr-xr-x 1 root root 185576 May 31 11:54 check_real-rwxr-xr-x 1 root root 9687 May 31 11:54 check_ Rpc-rwxr-xr-x 1 root root 1537 May 31 11:54 check_sensorslrwxrwxrwx 1 root root 9 May 31 11:54 check_simap-> check_tcp-rwxr-xr-x 1 root root 268781 May 31 11:54 check_smtp-rwxr-xr-x 1 root root 269786 May 31 11:54 check_snmplrwxrwxrwx 1 root root 9 May 31 11:54 check_spop-> check_tcp-rwxr-xr-x 1 root root 185227 May 31 11: 54 check_sshlrwxrwxrwx 1 root root 9 May 31 11:54 check_ssmtp-> check_tcp-rwxr-xr-x 1 root root 166806 May 31 11:54 check_swap-rwxr-xr-x 1 root root 252843 May 31 11:54 check_tcp-rwxr-xr-x 1 root root 186950 May 31 11:54 check_timelrwxrwxrwx 1 root root 9 May 31 11:54 check_udp-> check_tcp-rwxr-xr-x 1 root root 199442 May 31 11:54 check_ups-rwxr-xr-x 1 root root 163288 May 31 11:54 check_uptime-rwxr-xr-x 1 root root 157647 May 31 11:54 check_users-rwxr-xr-x 1 root root 3040 May 31 11:54 check_wave-rwxr-xr-x 1 root root 157770 May 31 11:54 negate-rwxr-xr-x 1 root root 151307 May 31 11:54 urlize-rwxr-xr-x 1 root root 1914 May 31 11: 54 utils.pm-rwxr-xr-x 1 root root 2791 May 31 11:54 utils.sh

4. Install nrpe (deploy on the server to be monitored)

NRPE depends on nagios-plugins, so install it together.

Please refer to: https://support.nagios.com/kb/article.php?id=515

[root@localhost ~] # yum install-y gcc glibc glibc-common openssl openssl-devel perl wget [root@localhost ~] # cd / tmp [root@localhost ~] # wget-- no-check-certificate-O nrpe.tar.gz https://github.com/NagiosEnterprises/nrpe/archive/nrpe-3.2.1.tar.gz[root@localhost ~] # tar zxvf nrpe.tar.gz [root@localhost ~] # cd / tmp/nrpe-nrpe-3.2.1/ [root@localhost nrpe- Nrpe-3.2.1] #. / configure-- enable-command-args [root@localhost nrpe-nrpe-3.2.1] # make all [root@localhost nrpe-nrpe-3.2.1] # make install-groups-users [root@localhost nrpe-nrpe-3.2.1] # make install [root@localhost nrpe-nrpe-3.2.1] # make install-config [root@localhost nrpe-nrpe-3.2.1] # echo > > / etc/services [root@localhost nrpe -nrpe-3.2.1] # echo'# Nagios services' > > / etc/services [root@localhost nrpe-nrpe-3.2.1] # echo 'nrpe 5666 TCPP' > > / etc/services [root@localhost nrpe-nrpe-3.2.1] # make install-init [root@localhost nrpe-nrpe-3.2.1] # systemctl enable nrpe.service

# add nagios server IP, and run server connection nrpe

[root@localhost nrpe-nrpe-3.2.1] # vi / usr/local/nagios/etc/nrpe.cfgallowed_hosts=127.0.0.1192.168.146.128dont_blame_nrpe= 1 [root @ localhost nrpe-nrpe-3.2.1] # systemctl start nrpe.service [root@localhost ~] # cat / usr/lib/systemd/system/nrpe.service [root@localhost nrpe-nrpe-3.2.1] # / usr/local/nagios/libexec/check_nrpe-H 127.0. 0.1NRPE v3.2.1 [root@localhost nrpe-nrpe-3.2.1] # / usr/local/nagios/libexec/check_nrpe-H 192.168.146.128NRPE v3.2.1

Test plug-ins and NRPE

[root@localhost nrpe-nrpe-3.2.1] # vi / usr/local/nagios/etc/ nrpe.cfgcommand[ check _ load] = / usr/local/nagios/libexec/check_load-w 15 load1=0.060;0.150;0.300;0; load5=0.060;0.100 10 5-c 30 force 25 20 [root@localhost nrpe-nrpe-3.2.1] # / usr/local/nagios/libexec/check_nrpe-H 127.0.0.1-c check_loadWARNING-load average: 0.06,0.06,0.09 | load1=0.060;0.150;0.300;0; load5=0.060;0.100 0.250T0; load15=0.090;0.050;0.200;0 [root@localhost ~] # netstat-tnlpActive Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0 tnlpActive Internet connections 22 0.0.0.0 Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp * LISTEN 1062/sshd tcp 0 0 127.0.1 15 0 .0.0: * LISTEN 1372/master tcp 00 0.0.0.0 LISTEN 57918/httpd tcp6 5666 0.0.0.0 LISTEN 57918/httpd tcp6 00: 80: 0 0: 22: * LISTEN 1062/sshd tcp6 0 0:: 1:25: * LISTEN 1372/master tcp6 0 0: 5666:: * LISTEN 60275/nrpe

5. Install the PNP plug-in (the monitoring function is completed through the plug-in)

Please refer to: https://www.cnblogs.com/caoguo/p/5022230.html

[root@localhost] # yum-y install rrdtool librrds-perl perl-rrdtool-y [root@localhost ~] # tar zxvf pnp4nagios-0.6.26.tar.gz [root@localhost ~] # cd pnp4nagios-0.6.26 [root@localhost pnp4nagios-0.6.26] #. / configure-- with-nagios-user=nagios-- with-nagios-group=nagios [root@localhost pnp4nagios-0.6.26] # make all [root@localhost pnp4nagios-0.6.26] # make install [root@localhost Pnp4nagios-0.6.26] # make install-webconf [root@localhost pnp4nagios-0.6.26] # make install-config [root@localhost pnp4nagios-0.6.26] # make install-init [root@localhost pnp4nagios-0.6.26] # cd. / sample-config [root@localhost pnp4nagios-0.6.26] # make install-webconf

Configure pnp4nagios

[root@localhost pnp4nagios-0.6.26] # cd / usr/local/pnp4nagios/etc/ [root@localhost etc] # mv misccommands.cfg-sample misccommands.cfg [root@localhost etc] # mv rra.cfg-sample rra.cfg [root@localhost etc] # mv nagios.cfg-sample nagios.cfg [root@localhost etc] # cd pages/ [root@localhost pages] # mv web_traffic.cfg-sample web_ traffic.cfg [root @ localhost pages] # cd. / check_commands/ [root @ localhost Check_commands] # mv check_all_local_disks.cfg-sample check_all_local_ disks.cfg [root @ localhost check_commands] # mv check_nrpe.cfg-sample check_ nrpe.cfg [root @ localhost check_commands] # mv check_nwstat.cfg-sample check_ nwstat.cfg [root @ localhost check_commands] # / etc/init.d/npcd start [root@localhost check_commands] # chkconfig npcd on configure Nagios data output interface (running in BULK mode) details Refer to the official website https://docs.pnp4nagios.org/pnp-0.6/config#bulk_mode: [root@localhost ~] # vi / usr/local/nagios/etc/nagios.cfgprocess_performance_data=1 # default is 0 Modify it to 1 and add the following to the file: # # service performance data#service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdataservice_perfdata_file_template=DATATYPE::SERVICEPERFDATA\ tTIMET::$TIMET$\ tHOSTNAME::$HOSTNAME$\ tSERVICEDESC::$SERVICEDESC$\ tSERVICEPERFDATA::$SERVICEPERFDATA$\ tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\ tHOSTSTATE::$HOSTSTATE$\ tHOSTSTATETYPE::$HOSTSTATETYPE$\ tSERVICESTATE::$SERVICESTATE$\ tSERVICESTATETYPE::$SERVICESTATETYPE$service_perfdata_file_mode=aservice_perfdata_file_processing_interval=15service_perfdata_file_processing_command=process-service-perfdata -file## host performance data starting with Nagios 3.0#host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdatahost_perfdata_file_template=DATATYPE::HOSTPERFDATA\ tTIMET::$TIMET$\ tHOSTNAME::$HOSTNAME$\ tHOSTPERFDATA::$HOSTPERFDATA$\ tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\ tHOSTSTATE::$HOSTSTATE$\ tHOSTSTATETYPE::$HOSTSTATETYPE$host_perfdata_file_mode=ahost_perfdata_file_processing_interval=15host_perfdata_file_processing_command=process-host-perfdata-file

Configure command.cfg:

[root@localhost ~] # vi / usr/local/nagios/etc/objects/commands.cfg add the following to the file: define command {command_name process-service-perfdata-file command_line / usr/local/pnp4nagios/libexec/process_perfdata.pl-- bulk=/usr/local/pnp4nagios/var/service-perfdata} define command {command_name process-host-perfdata-file command_line / usr/local/pnp4nagios / libexec/process_perfdata.pl-- bulk=/usr/local/pnp4nagios/var/host-perfdata}

Add a chart icon template to the template profile:

[root@localhost ~] # vi / usr/local/nagios/etc/objects/templates.cfg add the following to the file: define host {name host-pnp action_url / pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_ register 0} define service {name service-pnp action_url / pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$ register 0}

Invoke the chart template in the monitoring host and service (add a new template after the host and service):

[root@localhost ~] # vi / usr/local/nagios/etc/objects/localhost.cfg

Modify (not add) the file as follows

Define host {use linux-server,host-pnp host_name localhost alias localhost address 127.0.0.1} define service {use local-service Service-pnp host_name localhost service_description PING check_command checklists pingling 100.010% 500.0160} define service {use local-service Service-pnp host_name localhost service_description Root Partition check_command checkpoints localizations disk20% "10%" /}

Restart nagios and apache:

[root@localhost ~] # systemctl restart nagios.service [root@localhost ~] # systemctl restart httpd.service

Visit the nagios interface to see the small icon of the chart:

If you want to be all green, follow the instructions if you are not green.

[root@localhost check_commands] # mv / usr/local/pnp4nagios/share/install.php / tmp/

Refresh after full green, normal as follows:

Monitor the local machine

=

[root@localhost ~] # cd / usr/local/nagios/etc/objects [root@localhost ~] # vim localhost.cfgdefine host {use linux-server host_name localhost alias localhost address 127.0.0.1} # Define An optional hostgroup for Linux machinesdefine hostgroup {hostgroup_name linux-servers The name of the hostgroup alias Linux Servers; Long name of the group members localhost; Comma separated list of hosts that belong to this group} # Define a service to "ftp" the local machinedefine service {use local-service Name of service template to use host_name localhost service_description FTP check_command check_ftp} # Define a service to "nfs" the local machinedefine service {use local-service Name of service template to use host_name localhost service_description NFS check_command check_tcp!2049}

Monitor remote host

=

[root@localhost] # cd / usr/local/nagios/etc/objects [root@localhost ~] # cp localhost.cfg 192.168.0.164.cfg [root@localhost ~] # vim 192.168.0.164.cfgdefine host {use linux-server host_name testserver alias host196 address 192.168. 0.164} # define hostgroup {# hostgroup_name testserver The name of the hostgroup# alias host; Long name of the group# members localhost Comma separated list of hosts that belong to this group#} define service {use local-service host_name testserver service_description PING check_command checkpointing pingling 100.0, 20% 500.0, 60%} define service {use Local-service host_name testserver service_description HTTP check_command check_http# notifications_enabled 0} define service {use local-service host_name testserver service_description NFS check_command check_tcp!2049# notifications_enabled 0}

=

Change the master profile

[root@localhost ~] # vim / usr/local/nagios/etc/nagios.cfg add a line cfg_file=/usr/local/nagios/etc/objects/192.168.122.100.cfg to check whether the new configuration file is correct [root@localhost ~] # / usr/local/nagios/bin/nagios-v / usr/local/nagios/etc/nagios.cfgTotal Warnings: 0Total Errors: 0Things look okay-No serious problems were detected during the pre-flight check

Restart the nagios,web login to confirm whether a new host has been added.

Monitor local and remote host references:

Https://blog.51cto.com/1585654/1386857

Nagios does not use mysql storage by default, and you can use the NDOUtils plug-in to implement mysql storage:

Https://support.nagios.com/kb/article/ndoutils-installing-ndoutils-406.html

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report