Nagios's function is to monitor the service and host, but it does not include this part of the function, all monitoring, detection functions are through a variety of plug-ins to complete. After you start Nagios, it periodically calls the plugin to detect the state of the server, while Nagios maintains a queue, all the status information returned by the plug-ins goes into the queue, and Nagios reads the information from the first team, processes it, and then displays the status over the Web.
This is the so-called 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 the 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 to be monitored by the host polling to obtain monitoring data, the biggest advantage is to avoid other than the data processing work is placed on the monitored host (including data transmission), to avoid the large number of monitored host, a polling time is too long and lead to monitoring reaction delay, This is also the key to the passive model being able to take on a greater amount of monitoring.
Nagios provides a number of plug-ins that allow you to easily monitor a number of service statuses, and after the installation is complete, all the plugins that you can use in/libexec in the Nagios directory, such as Check_disk, are plugins that check disk space Check_ Load is the plug-in that checks the CPU load. Each plugin can be used to view its usage and functionality by running the./check_xxx-h command.
First, the deployment environment
Host |
Operating System |
IP Address |
main software |
Nagios |
centos7.3 x86_64 |
192.168.144.112 |
Nagios4.0.1, nagios-plugins-1.5, lamp environment |
Monitored host |
centos7.3 x86_64 |
192.168.144.111 |
Second, Nagios Service Host Deployment 1, first prepare the lamp environment
- Because the passive mode data is processed through the Web interface, it is necessary to support the lamp environment on the Nagios service host.
yum install -y httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash
Vim/etc/httpd/conf/httpd.conf
ServerName www.yun.com...AddType application/x-httpd-php .phpAddType application/x-httpd-php-source .phps...DirectoryIndex index.html index.php
- Turn off the firewall and SELinux to start the service
Systemctl Stop Firewalld.service
Setenforce 0
Systemctl Start httpd
Systemctl Start Mariadb.service
2, prepare the Nagios service software related environment
Yum install-y gcc glibc glibc-common gd gd-devel xinetd openssl-devel
Useradd-s/sbin/nologin Nagios
Mkdir/usr/local/nagios
Chown-r Nagios.nagios/usr/local/nagios
ll-d/usr/local/nagios/View Permissions
3, unpack the package, perform the installation
Tar zxvf nagios-4.0.1.tar.gz-c/opt/
Cd/opt/nagios-4.0.1/
./configure--prefix=/usr/local/nagios
执行安装程序后,编译各模块的五大步骤make all //首先执行全部编译make installmake install-init //初始化命令位置make install-commandmode //编译安装控制模块make install-config //编译生成相关配置文件
Chkconfig--add/etc/rc.d/init.d/nagios
Chkconfig--level and Nagios on
Chkconfig--list Nagios
- To verify the complete success of the compilation, you need to check the existence of etc, bin, sbin, share, var five directories under/usr/local/nagios/
4. Compile and install the plugin module
Tar xvzf nagios-plugins-1.5.tar.gz-c/opt
cd/opt/nagios-plugins-1.5
./configure--prefix=/usr/local/nagios Install plug-in module, note into the Nagios installation directory
Make && make install
5. Modify the Apache configuration file to create a virtual directory for Nagios
Vim/etc/httpd/conf/httpd.conf
found: User Apache group Apache modified to user Nagios group Nagios ... For security reasons, it is common for Nagios's web monitoring pages to be authorized for access, which requires an additional authentication 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" >//Monitoring page CONTROL permission validation authtype Basic Opti ONS execcgi allowoverride None Order allow,deny allow from all AuthName "Nagios Access" Authuserf ILE/USR/LOCAL/NAGIOS/ETC/HTPASSWD//Verify account password storage location Require valid-user </Directory> alias/nagios "/usr /local/nagios/share "<directory"/usr/local/nagios/share ">//Monitoring page access verification authtype Basic Options None AllowOverride None Order Allow,deny allow from all AuthName "Nagios Access" authuserfile/usr/local/n AGIOS/ETC/HTPASSWD//Verify account password storage location Require valid-user </Directory>
- After setting the Access verification settings, you need to set the authentication account password
- Use HTPASSWD to generate a jack account and set a password in/USR/LOCAL/NAGIOS/ETC/HTPASSWD
Htpasswd-c/usr/local/nagios/etc/htpasswd Jack
cat/usr/local/nagios/etc/htpasswd
jack:$apr1$DR0SjMa5$trumMzpqj./BA15Iswx2g0
Systemctl Restart Httpd.service
Three, configuration Nagois each function module configuration file
1.TEMPLATES.CFI Nagios is primarily used to monitor host resources and services, called objects in the Nagios configuration, and in order to avoid having to repeatedly define some monitoring objects, Nagios introduces a template configuration file that defines some common attributes as templates for easy reference. Contact_groups the Contact Group property to TS will be defined in the following contacts.cfg file 2.resource.cfg file resource.cfg is a variable definition file for Nagios generally without changes $user1$=/usr/ Local/nagios/libexec3.commands.cfg file This file is present by default and can be used without modification, but if a new command needs to be added, you can add 4 to this file. Hosts.cfg file, if the creation location is not under the object, you need to be aware of the main group permissions, and the main configuration file is told as absolute path 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 the associated attribute information (no spaces) define host{use linux-server# reference the property information of the host Linux-server, The Linux-server host is defined in the Templates.cfg file. HOST_NAME nagios-linux# hostname alias nagios-linux# host alias address 1 92.168.144.111# the host address that is monitored, this address can be IP, or it can be a domain name. } #定义一个主机组 define hostgroup{hostgroup_name bsmart-servers# host group name, optionally specified. Alias Bsmart servers# host groups are members of the nagios-linux# host group, where "Nagios-linux" is the one defined above. }5.localhost.cfg files are used to monitor this machine generally without changing the 6.windows.cfg used to superviseControl Windows There is no need to use the 7.services.cfg. File This file does not exist by default and requires manual creation of services and host resources that are primarily used to define monitoring define service{uses L ocal-service# references the property values of the Local-service service, Local-service is defined in the Templates.cfg file. HOST_NAME nagios-linux# Specifies the service on which host to monitor, "nagios-server" is defined in the Hosts.cfg file. Service_description check-host-alive# describes the contents of the monitoring service for reference by maintenance personnel. Check_command check-host-alive# Specifies the command to check. 8.contacts.cfg file Contacts.cfg is a configuration file that defines contacts and contact groups (no spaces) define contact{contact_name jack# contacts The name of this place does not have a space use generic-contact# reference Generic-contact property information, where "generic-contact" is in templates. CFG file is defined in alias Nagios Admin email [email protecte D]}define contactgroup{contactgroup_name ts# Contact Group name, also cannot space alias Technical support# Contact Group describes members of members jack# contact groups, where "Jack" is the contact defined above, and if multiple contacts are separated by commas }9.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, so simply add this user's execute permission in the Cgi.cfg file at the end of the join 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,jack10. The Nagios.cfg file references the object configuration file in the Nagios.cfg file cfg_file=/usr/local/nagios/etc/objects/hosts.cfgcfg_file=/usr/local/ Nagios/etc/objects/services.cfgcommand_check_interval=10s This variable is used to set the time interval for Nagios to detect external commands
- Detection configuration file
/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg Authentication configuration file
- Web interface Display
Http://192.168.144.112/nagios
Nagios Monitoring System Environment deployment