Deploying the Nagios Monitoring System

Source: Internet
Author: User

About Nagios
    • Nagios is an open-source, free network monitoring tool that effectively monitors Windows, Linux and UNIX host status, network devices such as switch routers, 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.
    • Nagios itself does not have the ability to monitor, all the monitoring is done by the plug-in, the plug-in will monitor the results returned to the Nagios,nagios analysis of these results in the web to show us, while providing the corresponding alarm function (this alarm function is also done by the corresponding plug-in.)
How Nagios Works

Nagios's active mode and passive 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.
    The difference between active mode and passive mode the services that both modes are good at monitoring are also different.
  • Active Mode: Host alive and Alive, port, HTTP service, MySQL service ...
  • Passive mode: Client host load, hard disk space, memory ...

Nagios can identify 4 status return information, 0 (OK) indicates that the status is normal/green, 1 (WARNING) indicates that a warning appears/xxx, 2 (CRITICAL) indicates a very serious error/red, 3 (UNKNOWN) indicates an unknown error/deep xxx. 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.

?

Operation Steps

?

    • Case Environment
Host IP main software
Nagios Monitoring Side 192.168.200.131 httpd, PHP, Nagios, Nagios-plugins, Nrpe,
Monitored side 192.168.200.132 .

?

  • Download the installation package environment

    # wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.1.tar.gz # wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz# wget https://sourceforge.net/projects/nagios/files/nrpe-3.x/nrpe-3.1.0.tar.gz# yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel# yum intall httpd php
  • installation

    # useradd -s /sbin/nologin nagios# mkdir /usr/local/nagios# chown -R nagios.nagios /usr/local/nagios# tar -zxvf nagios-4.3.1.tar.gz -C /opt# cd /opt/nagios-4.3.1# ./configure --prefix=/usr/local/nagios# make all# make install# make install-init# make install-commandmode# make install-config# make install-webconf      //生成apache配置文件# chkconfig --add /etc/rc.d/init.d/nagios# chkconfig --level 35 nagios on# chkconfig --list nagios# ls /usr/local/nagios    检查 是否存在etc、bin、sbin、share、var 这五个目录
  • Installing plugins

    # tar xvzf nagios-plugins-2.2.1.tar.gz -C /opt# cd /opt/nagios-plugins-2.2.1/# ./configure --prefix=/usr/local/nagios# make && make install
  • Modifying the httpd configuration file

    # vim /etc/httpd/conf/httpd.conf User nagios        //修改Group nagios       //修改<IfModule dir_module>     DirectoryIndex index.html index.php       //修改</IfModule> ........AddType application/x-httpd-php .php    //添加
  • For security reasons, it is common for nagios web monitoring pages to be authorized for access,
  • This requires an additional validation configuration, i.e. the following information is added at the end of the httpd.conf file:

      #setting for Nagios scriptalias/nagios/ Cgi-bin "/usr/local/nagios/sbin" <directory "/usr/local/nagios/sbin" > AuthType Basic Options EXECC          GI allowoverride None Order allow,deny allow from all AuthName "Nagios Access" AUTHUSERFILE/USR/LOCAL/NAGIOS/ETC/HTPASSWD Require valid-user </Directory> Alias/nagios "/          Usr/local/nagios/share "<directory"/usr/local/nagios/share "> AuthType Basic Options None AllowOverride None Order Allow,deny allow from all AuthName "Nagios Access" Authuserf ILE/USR/LOCAL/NAGIOS/ETC/HTPASSWD Require valid-user </Directory> # systemctl Restart Httpd.service//Restart Service Service  
  • Create an authentication Access file

    # htpasswd -c /usr/local/nagios/etc/htpasswd zkc    //接着输入密码
  • Configure Nagois

    Configuration files are typically under directory/usr/local/nagios/etc/

  • RESOURCE.CFG: A variable definition file that is Nagios generally does not need to change $USER 1$=/usr/local/nagios/libexec
  • Commands.cfg: This file is present by default and can be used without modification, if a new command needs to be added, you can add it in this file.
  • LOCALHOST.CFG: Used to monitor the machine generally do not need to change
  • WINDOWS.CFG: Used to monitor windows
    • Templates.cfi
      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.

      # vim templates.cficontact_groups       ts        //联系组属性改成 ts(5个) 将在后面的contacts.cfg文件中定义
  • Hosts.cfg
    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 attribute information (no spaces)

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

?

    • Services.cfg
      This file does not exist by default and needs to be created manually, primarily for defining monitored services and host resources

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

?

    • Contacts.cfg
      Contacts.cfg is a configuration file that defines contacts and contact groups (no spaces)

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

?

    • cgi.cfg
      This file is used to control the associated CGI script
      Because the Nagios Web monitoring interface verifies that the user is ZKC, simply add the user's execute permission in the Cgi.cfg file
      At the end of the join

      # vim /usr/local/nagios/etc/cgi.cfg default_user_name=zkcauthorized_for_system_information=nagiosadmin,zkc  authorized_for_configuration_information=nagiosadmin,zkc  authorized_for_system_commands=zkcauthorized_for_all_services=nagiosadmin,zkc  authorized_for_all_hosts=nagiosadmin,zkcauthorized_for_all_service_commands=nagiosadmin,zkc  authorized_for_all_host_commands=nagiosadmin,zkc

?

    • nagios.cfg

      # vim /usr/local/nagios/etc/nagios.cfg将对象配置文件在Nagios.cfg文件中进行引用cfg_file=/usr/local/nagios/etc/objects/hosts.cfgcfg_file=/usr/local/nagios/etc/objects/services.cfgcommand_check_interval=10s  //添加   该变量用于设置nagios对外部命令检测的时间间隔
    • Test monitoring

      # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 验证配置文件# systemctl restart nagios.service # systemctl restart httpd

    • Verify: Open Browser input

      http://192.168.200.131/nagios/


Deploying the Nagios 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.