The Nagios of Linux monitoring system

Source: Internet
Author: User

Nagiosnagios working principle of Linux monitoring system

Nagios's function is to monitor the service and host, but it does not include this part of the function, all the monitoring, detection functions have heard a variety of plug-ins to complete. After starting 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-in is queued, and Nagios reads the information from the team header each time, processing it, and then displaying the status results over the web.

Nagios mode

Passive mode: As shown, the client Nrpe process, the server through the Check_nrpe plug-in to send commands to the client, the client according to the instructions of the server to invoke the corresponding plug-in, the plug-in can obtain the relevant information of the machine, and the obtained results sent to the server. Because you need to call the client's plugin to wait for the information returned with the client, it is called passive mode

Active mode: The active mode does not need to invoke the client's plug-in, but instead proactively detects the client's information through its own plug-in.
Well, because of the difference between active and passive modes, the services that both modes are good at monitoring are also different.

Nagios Features
    • Monitor network Services (SMTP, POP3, HTTP, NNTP, ping, etc.);
    • Monitor host resources (processor load, disk utilization, etc.);
    • Simple plug-in design allows users to easily expand their services to detect methods;
    • Parallel service check mechanism;
    • With the ability to define the network hierarchy, 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;
    • When a service or host problem arises and is resolved, the alarm is sent to the contact person (via email, SMS, user defined mode);
    • Some handlers can be defined so that they can play a preventive role in the event of a service or host failure;
    • Automatic log scrolling function;
    • Can support and implement redundant monitoring of the host;
    • Optional web interface for viewing current network status, notification and fault history, log files, etc.;
    • can view the system monitoring information through the mobile phone;
    • Custom event-handling controller can be specified
Test environment
role IP Address
Monitoring host 192.168.58.146
Monitored host 192.168.58.149
Experimental implementation

First of all, we need to set up lamp service, which has been introduced before, here do not repeat

Install the dependent packages required for Nagios

[[email protected] ~]# yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel

Add a process user to manage Nagios

[[email protected] ~]# useradd -s /sbin/nologin nagios

Create a directory to install Nagios

[[email protected] ~]# mkdir /usr/local/nagios

Change the owner and group of the Nagios installation directory

[[email protected] ~]# chown -R nagios.nagios /usr/local/nagios

Compile and install the Nagios below

[[email protected] ~]# tar xf nagios-4.0.1.tar.gz -C /opt/#将安装包解压到/opt目录下面[[email protected] ~]# cd /opt/nagios-4.0.1/#切换至解压路径下[[email protected] nagios-4.0.1]# ./configure --prefix=/usr/local/nagios#配置Nagios安装路径[[email protected] nagios-4.0.1]# make all由于nagios分很多单独的文件,所以使用make all来编译所有的的单独的文件[[email protected] nagios-4.0.1]# make install#这是编译安装主程序包括CGI和HTML文件[[email protected] nagios-4.0.1]# make install-init#编译安装一些初始化脚本[[email protected] nagios-4.0.1]# make install-commandmode#这是为外部命令文件所在的目录安装和配置权限[[email protected] nagios-4.0.1]# make install-config#这是安装一些配置的模板文件,主要在/usr/local/nagios/etc目录下面[[email protected] nagios-4.0.1]# chkconfig --add /etc/rc.d/init.d/nagios#将nagios添加到chkconfig系统管理中[[email protected] nagios-4.0.1]# chkconfig --level 35 nagios on#设置nagios在35级别开启自启动


At this time we can go to the/usr/local/nagios/directory to see if the relevant file directory is generated

[[email protected] nagios-4.0.1]# ls /usr/local/nagios/bin  etc  libexec  sbin  share  var

Installing the Nagios-plugins Service

[[email protected] ~]# tar xf nagios-plugins-1.5.tar.gz -C /opt/[[email protected] ~]# cd /opt/nagios-plugins-1.5[[email protected] nagios-plugins-1.5]#  ./configure --prefix=/usr/local/nagios#将它安装到nagios目录下[[email protected] nagios-plugins-1.5]# make && make install#编译安装

Modify the Apache service configuration file

[[email protected] ~]# vim /etc/httpd.conf  




Create a httpd account verification file

[[email protected] ~]# htpasswd -c /usr/local/nagios/etc/htpasswd jack[[email protected] ~]# cat /usr/local/nagios/etc/htpasswd jack:$apr1$cTieBr/D$vWomztP4eURmUTxxv1WFv0#可以看到我们添加的账户以及密码

Modify the Nagios configuration file, the profile is generally under/usr/local/nagios/etc/objects

    • TEMPLATES.CFI file

Primarily for monitoring host resources and services, known as objects in Nagios configuration, Nagios introduces a template configuration file that defines common properties as templates for multiple references, in order to avoid having to define some of the monitoring objects repeatedly.

[[email protected] etc]# cd /usr/local/nagios/etc/objects/[[email protected] objects]# lscommands.cfg  hosts.cfg      printer.cfg   switch.cfg     timeperiods.cfgcontacts.cfg  localhost.cfg  services.cfg  templates.cfg  

    • Resource.cfg file

Resource.cfg is Nagios's variable definition file generally without changes

    • Commands.cfg file

This file is present by default and can be used without modification, but if new commands need to be added, this file will add.

    • Hosts.cfg file

This file does not exist by default and needs to be created manually, Hosts.cfg is used primarily to specify the host address to be monitored and related property information.

[[email protected] objects]# vim hosts.cfg define host{           use                     linux-server#引用主机linux-server的属性信息,linux-server主机在templates.cfg文件中进行了定义。        host_name               Nagios-Linux#主机名        alias                   Nagios-Linux#主机别名        address                 192.168.58.149#被监控的主机地址,这个地址可以是ip,也可以是域名。        }   #定义一个主机组   define hostgroup{              hostgroup_name          bsmart-servers#主机组名称,可以随意指定。        alias                   bsmart servers#主机组别名        members                 Nagios-Linux#主机组成员,其中“Nagios-Linux”就是上面定义的主机。             }
    • Localhost.cfg file

Used to monitor the machine generally without changes

    • Windows.cfg file

Used to monitor windows here without using

    • Services.cfg file

This file does not exist by default, and you need to manually create the services and host resources that are primarily used to define monitoring.

[[email protected] objects]# vim services.cfgdefine service{          use                     local-service#引用local-service服务的属性值,local-service在templates.cfg文件中进行了定义。        host_name               Nagios-Linux#指定要监控哪个主机上的服务,“Nagios-Linux”在hosts.cfg文件中进行了定义。        service_description     check-host-alive#对监控服务内容的描述,以供维护人员参考。        check_command           check-host-alive#指定检查的命令。        
    • Contact.cfg file

Contacts.cfg is a configuration file that defines contacts and contact groups.

[[email protected] objects]# vim contacts.cfg define contact{        contact_name                    jack#联系人的名称,这个地方不要有空格        use                             generic-contact#引用generic-contact的属性信息,其中“generic-contact”在templates.cfg文件中进行定义        alias                           Nagios Admin        email                           [email protected]        }define contactgroup{        contactgroup_name       ts#联系人组的名称,同样不能空格        alias                   Technical Support#联系人组描述        members                 jack#联系人组成员,其中“jack”就是上面定义的联系人,如果有多个联系人则以逗号相隔        }
    • Cgi.cfg file

This file is used to control the associated CGI script
Because the Nagios Web monitoring interface verifies that the user is Jack, you simply add the user's execute permission in the Cgi.cfg file.

[[email protected] objects]# cd ../[[email protected] etc]# lscgi.cfg  htpasswd  nagios.cfg  objects  resource.cfg[[email protected] etc]# vim cgi.cfg 在最后加入default_user_name=jackauthorized_for_system_information=nagiosadmin,jack  authorized_for_configuration_information=nagiosadmin,jack  authorized_for_system_commands=jackauthorized_for_all_services=nagiosadmin,jack  authorized_for_all_hosts=nagiosadmin,jackauthorized_for_all_service_commands=nagiosadmin,jack  authorized_for_all_host_commands=nagiosadmin,jack
    • Nagios.cfg file

Referencing an object configuration file in a nagios.cfg file

cfg_file=/usr/local/nagios/etc/objects/hosts.cfgcfg_file=/usr/local/nagios/etc/objects/services.cfgcommand_check_interval=10s  #该变量用于设置nagios对外部命令检测的时间间隔

It's all configured. We can detect it with the relevant commands.

[[email protected] objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If the following response appears, the configuration is successful.

Finally turn on Nagios service

[[email protected] ~]# /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

Restart MySQL and httpd services for Web test access Http://192.168.58.146/nagios



The Nagios of Linux monitoring system

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.