Monitor the Three Musketeers ' Nagios

Source: Internet
Author: User
Tags php software disk usage

Nagios is a popular computer system and network monitoring program that detects hosts and services and alerts users when an exception occurs and is released. It is open source software developed based on GPLV2 and is available for free and use.

How Nagios Works

Nagios's function is to monitor services and hosts, but it does not include these features, and all monitoring and detection functions are done through a variety of plugins. After you start Nagios, it periodically automatically calls the plug-in to detect the state of the server, while Nagios maintains a queue, all the status information returned by the plug-in is queued, and Nagios reads the information from the first team, processes it, and then displays the status results over the web. This is the passive mode, often used to monitor the host system resources, such as system load, disk utilization, memory utilization, network status, number of system processes and so on. The other is active mode, mainly Nagios server actively to obtain data, often used to detect URL monitoring and service status monitoring. Compared to the active mode of the server actively to be monitored by the monitoring machine to obtain monitoring data, a great advantage of this is to remove the data processing of the other work is placed on the monitor (including data transmission), to avoid the number of the monitoring machine is large when the polling time is too long and lead to monitoring reaction delay, This is also the key to the passive mode to assume a greater amount of monitoring. 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/libxec in the Nagios home directory.

Nagios Main Features
    • Network Service Monitoring (SMTP, POP3, HTTP, NNTP, ICMP, SNMP, FTP, SSH)
    • Host resource monitoring (CPU load, disk usage, system logs), also including Windows hosts (using nsclient++ plugin)
    • Specify the plugin you write to collect data over the network to monitor any situation (temperature, warning ...). )
    • Remotely execute scripts by configuring the Nagios remote execution plug-in
    • Remote monitoring supports SSH or SSL plus channel mode for monitoring
    • 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.)
    • Parallel service Check Available
    • Ability to define the hierarchy of network hosts, allowing for step-by-step checks, starting from the parent host
    • Notify when a problem occurs with a service or host, via email, pager, SMS or any user-defined plugin
    • Ability to customize the event handling mechanism to reactivate a faulty service or host
    • Automatic log Looping
    • Supports redundant monitoring
    • Web interface to view current network status, notifications, problem history, log files, etc.

This project focuses on how to deploy Nagios and how to configure Nagios so that it can monitor the specified host

Project environment ready to shut down firewall and SELinux system version: CentOS 7.4 Virtual machine Assignment role
This project only for the monitored side to do a simple test, so the monitor does not need to install the Nagios plugin.
software used by theIP address
Monitoring side 172.16.10.34 nagios-4.4.2, nagios-plugins-2.2.1
Monitored side 172.16.10.20
Monitored side 172.16.10.23
Deploying the Nagios Monitoring System

Because the Nagios Monitoring System Web page needs Dynamic Web support, so need to install httpd and PHP software, or directly installed in the lamp environment, so before the experiment to prepare the virtual machine environment, the lamp architecture, the building, here is not much to repeat.

Install the Environment pack
yum install -y -- gcc -- glibc -- glibc-common -- gd -- gd-devel -- xinetd -- openssl-devel
Create an administrative user
useradd -s /sbin/nologin nagios
Creating the installation directory, specifying the genus Master Group
mkdir /usr/local/nagioschown -R nagios.nagios /usr/local/nagios
Compiling and installing Nagios
tar -zxvf nagios-4.4.2.tar.gz -C /optcd /opt/nagios-4.4.2./configure --prefix=/usr/local/nagiosmake allmake installmake install-initmake install-commandmodemake install-config
Verifying the installation Results
ls /usr/local/nagios

Installing Nagios-plugins
tar xvzf nagios-plugins-2.2.1.tar.gz -C /optcd /opt/nagios-plugins-2.2.1./configure --prefix=/usr/local/nagiosmake && make install
Configuring the Nagios Monitoring system to modify httpd.conf
vim /etc/httpd/conf/httpd.conf User nagios Group nagios  //修改原用户名apache为nagios<IfModule dir_module>   DirectoryIndex index.html index.php    //增加index.php</IfModule>AddType application/x-httpd-php .php   //插入该句
Increase Security Authentication Configuration

For security reasons, it is common for Nagios's web monitoring pages to be authorized for access, which requires an additional authentication configuration, where the following information is inserted at the end of the httpd.conf file:

vim /etc/httpd/conf/httpd.conf#setting for nagios ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" <Directory "/usr/local/nagios/sbin">      AuthType Basic      Options ExecCGI      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"      AuthUserFile /usr/local/nagios/etc/htpasswd      
Set login username and password
htpasswd -c /usr/local/nagios/etc/htpasswd chen
Configure Nagios

Configuration Nagois generally under directory/usr/local/nagios/etc/

Templates.cfg

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. Contact_groups the Contact group attribute to NP will be defined in the later contacts.cfg file

vim /usr/local/nagios/etc/object/templates.cfgcontact_groups                  np   //文中有五处都需修改
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 can be

Hosts.cfg file

This file does not exist by default and needs to be created manually, Hosts.cfg is mainly used to specify the host address to be monitored and related property information, note the writing format, do not have extra 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                 172.16.10.20     //被监控的主机地址,这个地址可以是ip,也可以是域名。        }   define hostgroup{                                 //定义一个主机组        hostgroup_name          bsmart-servers    //主机组名称,可以随意指定。        alias                   bsmart servers    //主机组别名        members                 Nagios-Linux      //主机组成员,其中“Nagios-Linux”就是上面定义的主机。             }
Localhost.cfg

Used to monitor the machine generally without changes

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 the contacts and contact groups, paying attention to the writing format.

vim /usr/local/nagios/etc/objects/contacts.cfgdefine contact{        contact_name                    chen            //联系人的名称,这个地方不要有空格        use                             generic-contact //引用generic-contact的属性信息,其中“generic-contact”在templates.cfg文件中进行定义        alias                           Nagios Admin        email                           46****[email protected] //填入真实可用邮箱,也可不写        }define contactgroup{        contactgroup_name       np                      //联系人组的名称,同样不能空格        alias                   Technical Support       //联系人组描述,言简意赅,能懂什么意思就行        members                 chen                    //联系人组成员,其中“chen”就是上面定义的联系人,如果有多个联系人则以逗号相隔        }
Cgi.cfg

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

default_user_name=chenauthorized_for_system_information=nagiosadmin,chen  authorized_for_configuration_information=nagiosadmin,chen  authorized_for_system_commands=chenauthorized_for_all_services=nagiosadmin,chen  authorized_for_all_hosts=nagiosadmin,chenauthorized_for_all_service_commands=nagiosadmin,chen  authorized_for_all_host_commands=nagiosadmin,chen             //配置文件末尾插入
Nagios.cfg

Referencing an object configuration file in a nagios.cfg file

vim /usr/local/nagios/etc/nagios.cfgcfg_file=/usr/local/nagios/etc/objects/hosts.cfgcfg_file=/usr/local/nagios/etc/objects/services.cfg    //合适的位置插入command_check_interval=10s  //该变量用于设置nagios对外部命令检测的时间间隔,插入即可。
Verifying profile accuracy
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Restart Service
systemctl restart httpd。servicesystemctl restart nagios.service
Visit the Nagios Web site

The site is set up for login verification, so you can log in to the website by entering the username and password you set before accessing the website.

http://172.16.10.34/nagios/


Increase the number of hosts modify the Hosts.cfg file

This file does not exist by default and needs to be created manually, Hosts.cfg is mainly used to specify the host address to be monitored and related property information, note the writing format, do not have extra 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                 172.16.10.20     //被监控的主机地址,这个地址可以是ip,也可以是域名。        }  define host{        use                     linux-server        host_name               Nagios-Linu        alias                   Nagios-Linu        address                 172.16.10.23        }define hostgroup{                                 //定义一个主机组        hostgroup_name          bsmart-servers    //主机组名称,可以随意指定。        alias                   bsmart servers    //主机组别名        members                 Nagios-Linux,Nagios-Linu      //主机组成员,其中“Nagios-Linux”就是上面定义的主机。             }
Restart Service
systemctl restart httpd。servicesystemctl restart nagios.service

Monitor the Three Musketeers ' Nagios

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.