Install and configure the Nagios Monitoring Service

Source: Internet
Author: User
Tags unix domain socket

Nagios is an open-source free network monitoring tool that can effectively monitor the status of windows, Linux and UNIX hosts, network settings such as vswitches and routers, and printers. If the system or service status is abnormal, an email or text message alert will be sent immediately to the website O & M personnel. After the status is restored, a normal email or text message notification will be sent. I am working on this stuff in our department recently. By the way, I will share some of my experiences on my blog. (Note that the following Article is not original to the author. I have added my own experiences and excluded some error information on the basis of my predecessors)

1. install and configure Nagios 1. Nagios introduction Nagios is an open-source network monitoring software that complies with gplv2 and can be used to monitor hosts and services of a specified variety of systems, you can also notify the Administrator when their working status changes. Its features include: 1) Monitoring Network Services (HTTP, POP3, SMTP, ping, MySQL, etc.) 2) monitoring host resources (disk space utilization, memory utilization, CPU load, etc) 3) Simple plug-in interface design, allowing users to easily develop the required detection script 4) Parallel service mode 5) easy description of the network structure, and the ability to distinguish between "down" and "host inaccessible" 6) notify the administrator of the changes in the working status of the host or service by email or user-defined means 7) automatic Log rolling (8) support for host monitoring in redundancy mode (9) allows you to visually view the current network status, notification and problem history, log files, and so on through the Web, this component is optional. Nagios generally consists of a main program (Nagios), a plug-in program (Nagios-plugins), and four optional addon (nrpe, NSCA, nsclient ++, and ndoutils. Nagios monitoring is implemented through plug-ins. Therefore, Nagios and Nagios-plugins are necessary components for server work. Among the four addon instances, nrpe is used to execute script INS on the monitored remote Linux/Unix hosts to monitor these host resources; NSCA is used to allow the monitored remote Linux/Unix host to send monitoring information to the Nagios server (this is especially used in redundant monitoring mode ); nsclient ++ is a component used to monitor Windows hosts installed on Windows hosts, while ndoutils is used to store Nagios configuration information and data generated by various events into the database, to quickly retrieve and process the data. In the four addon (attachments), nrpe and nsclient ++ work on the client, ndoutils work on the server, and NSCA must be installed on both the server and the client. The relationship diagram of Nagios components provided by the author based on his own understanding, hoping to help readers understand. If you disagree with the relationship in this diagram, you are welcome to communicate with the author in various ways.

Currently, Nagios can only be installed on a Linux host, and GCC is required for compiling. At the same time, if you want to use the web interface management tool, you also need support for the Apache server and Gd graphics library. 2. Preparations before installation (1) solve the dependency between Nagios installation: the running of the basic Nagios components depends on httpd, GCC, and GD. Run the following command to check whether the RPM package on which Nagios depends is fully installed: # rpm-Q httpd GCC glibc-common GD Gd-devel for missing RPM packages, you can use the RPM command to mount the disk for installation. If you do not want to be always troubled by rpm dependencies, you can use Yum with local sources to manage RPM packages. For the establishment of the local source, you can refer to the author's other article on yum. Note: You can also install the software package by compiling the source code, but the path of many related files to be used must be modified one by one according to the configuration during installation of your source code. (2) Add the users and groups required for running Nagios: # groupadd nagcmd # useradd-M Nagios # usermod-a-g nagcmd Nagios adds Apache to the nagcmd group, so that you can have sufficient permissions to operate Nagios through web interface: # usermod-a-g nagcmd Apache 3. Compile and install Nagios: # tar zxf nagios-3.1.2.tar.gz # cd nagios-3.1.2 #. /configure -- With-command-group = nagcmd # Make all # make install-init # make install-config # make install-commandmode specifies for email that you want to receive Nagios warnings email Address of the information, default Is the native Nagios User: # vi/usr/local/Nagios/etc/objects/contacts. CFG email Nagios @ localhost # This is the default setting in the httpd configuration file directory (Conf. d) Create a Nagios web program configuration file: # make install-webconf creates a user logging on to the Nagios web program. This User Account will be used to log on to Nagios for authentication in the future: # htpasswd-C/usr/local/Nagios/etc/htpasswd. after the configuration is complete, you need to restart httpd: # service httpd restart 4. Compile and install Nagios-plugins Nagios. Therefore, before starting Nagios, you also need to install official plug-ins for it. # Tar zxf nagios-plugins-1.4.13.tar.gz # cd nagios-plugins-1.4.13 #. /configure -- With-Nagios-user = Nagios -- With-Nagios-group = Nagios # Make # make install 5. Configure and start Nagios (1) add Nagios as a system service and add it to the auto-start service queue: # chkconfig -- add Nagios # chkconfig Nagios on (2) check whether the syntax of the main configuration file is correct: #/usr/local/Nagios/bin/Nagios-V/usr/local/Nagios/etc/Nagios. CFG (3) if the above syntax check is correct, then you can officially start the Nagios service: # service Nagios start (4) Configure Selin If the SELinux service is enabled for your system, the system rejects the running of the Nagios Web cgi program by default. You can run the following command to check whether SELinux is enabled on your system: # getenforce. If the result of the preceding command shows that the SELinux service is enabled, you can temporarily disable SELinux using the following command: # setenforce 0 if you want to completely disable SELinux in the future, you can edit the/etc/sysconfig/SELinux file, change the value "force" after SELinux to "Disable. Of course, you can also run the Nagios CGI program in SELinux/targeted mode without disabling SELinux: # chcon-r-t httpd_sys_content_t/usr/local/Nagios/sbin # chcon-r-t httpd_sys_content_t/usr/local/Nagios/share (5) view Nagios on the web interface:

Http: // your_nagios_ip/Nagios

You must specify the Web Authentication account and password you have set before logon. Note: To ensure the security of Nagios, we recommend that you use the strong information digest Authentication Mode (such as MD5) and use the Web TSL/SSL secure communication mode, in addition, the access control list is used to set the client address that can access the Nagios web interface. II. Introduction to Nagios plug-ins Nagios does not contain any monitoring mechanism, and all its monitoring work is implemented through plug-ins. These plug-ins are usually Perl scripts or shell scripts (usually in the/usr/local/Nagios/libexec directory) that monitor the working status of hosts or services through command lines ), nagios calls the SDK on demand and returns the execution result to Nagios. Nagios determines whether to "take some action" (such as running event handlers and sending notifications) based on the returned values ). Shows the relationship between the agent and the Nagios process and the Monitored object.

The official website provides some plug-ins to monitor basic system resources (such as CPU load, disk utilization, and Ping rate. To monitor the status of other types of resources (such as CPU voltage, CPU fan speed, and network traffic), you can use other official plug-ins or third-party plug-ins. Of course, you can also compile the required plug-ins. The Nagios plug-in Project: Register/

Nagiosexchange.org

The official Nagios plug-ins usually provide simple help. You can use "-h" or "-- Help" after each script to obtain the help information. To learn the help information of the plugin script check_nt, run the following command: #./check_nt -- help 3. Overview of the Nagios configuration file:

Main config file: The main configuration file, usually Nagios. cfg, contains many commands that indicate the working attributes of the Nagios daemon. This configuration file will be used by Nagios daemon and CGIS. Resource file (s): A resource file, which is often used to store custom "macros (macro)", such as sensitive information such as passwords, this avoids direct exposure to CGIS source files. Object definition files: object definition files, which are often used to define the objects to be monitored and how to monitor these objects, such as hosts, services, host groups, service groups, contacts, contact groups, and commands. These object definition files can be included in the main configuration file through the cmd_file command. If there are many object definition files, they can be stored in a directory, then, the primary configuration file is read at one time using the cmd_dir command. These files are usually located in the/usr/local/Nagios/etc/objects directory. CGI configure file: CGI configuration file, which contains many commands that determine the CGIS operating attributes and a reference pointing to the main configuration file.

Iv. Overview of common Nagios objects


Objects (objects) are the basic logical components of Nagios's "monitoring" and "notification" mechanisms. They mainly include:
  • Service
  • Service groups
  • Hosts
  • Host groups
  • Contacts
  • Contact Groups
  • Commands
  • Time Periods
  • Notification escalations
  • Notification and excution dependenicies
  •  

     

Host and Host group: a host is usually a physical device on the network and has at least one type of access address (host name, IP address, or MAC address ); each host usually provides one or more services. A parent/child relationship can be formed between hosts, it is used to describe the "subordinate" or "include" Relationship between hosts ("Network accessibility" relationship ). A host group usually refers to a combination of one or more hosts.


Service/Service Group: "service" is the core of Nagios's monitoring logic, usually from a host, it can be host attributes (such as CPU load, disk space, and swap space usage), or a "service" (such as POP3, HTTP, and SSH) provided by the host ), you can even use DNS resources to record such host resources. A Service Group usually refers to a combination of up to service definitions. Contact and Contact Group (contacts/contack groups): "Contact" refers to the recipient of "notification. A contact usually has one or more "notification" methods (such as mobile phones, emails, and instant messaging accounts) to receive notifications from hosts or services within the scope of his/her responsibilities. A contact group is a collection of one or more contacts. Time period (timeperiods): a time period is generally defined as the effective time period used to control when hosts and services are monitored and when contacts receive notifications.

Command (commands): used to define programs and scripts that can be called by Nagios. It also includes the calling formats of these programs or scripts. 5. installation and configuration of ndoutils: 1. ndoutils introduction ndoutils addon is mainly used to store the configuration information of Nagios and the data generated by the event into the database (currently the beta version supports MySQL and pgsql, stable version only supports MySQL) to facilitate rapid data retrieval and processing, and to provide other protection for managing the data through web interface programs. In a large application, multiple independent or distributed Nagios servers may exist. Each Nagios server in this environment is usually called a Nagios instance. In the environment of multiple Nagios instances, you can either store the data of all instances in one database or store the data of each instance separately. In an environment with only one Nagios instance, the Instance name is usually "default". In a multi-instance Environment, you must name each Nagios instance. Ndo utils consists of the following four parts: 1) ndomod event broker module (ndomod. o): Used to output data (data and logic) generated by Nagios processes. The premise is that Nagios enables the event broker function during compilation. In addition, the ndomod module can export Nagios configuration information (including the dynamic data generated by the runtime environment of the Nagios monitoring process) to files, Unix domain sockets, or TCP sockets. Ndo2db obtains data about Nagios in the preceding three methods. 2) ndo2db: used to receive and store information output by ndomod and log2ndo components in the database. At startup, The ndo2db process will create a TCP socket or Unix domain socket to listen to client (output end) connection requests. Currently, only MySQL databases are supported. Multiple Clients can output data to an ndo2db daemon at the same time. In this case, ndo2db establishes a connection process for each connected client (Nagios instance, to achieve independent storage, retrieval and processing of data on each client. 3) log2ndo: Used to output historical Nagios logs to the database through the ndo2db process. The methods for log2ndo to communicate with the ndo2db process are still standard files, Unix domain sockets, or TCP sockets. 4) file2sock: reads data from a standard file or standard input and outputs the data to a Unix or TCP socket. When ndomod or log2ndo outputs data to a standard file, this tool can read the data in these standard files and send the data to the TCP socket or Unix domain socket listened by the ndo2db process.

2. Install ndoutils # tar zxf ndoutils-1.4b8.tar.gz # cd ndoutils-1.4b8 #. /configure -- enable-mysql -- With-mysql-Lib =/usr/lib -- With-mysql-Inc =/usr/include -- disable-pgsql # Make # cp-V src/ {ndomod-3x.o, ndo2db-3x, file2sock, log2ndo}/usr/local/Nagios/bin the first two items in the file copied above are version-related, that is, if your Nagios master version is 2 series, you need to copy two files named ndomod-2x.o and ndo2db-2x. The last two items are common files and must be copied in any version. 3. Create a database for ndoutils # mysql-uroot-pmysql> Create Database ndodb; mysql> grant create, select, insert, update, delete on ndodb. * To ndouser @ localhost identified by '20140901'; mysql> flush privileges; the following two commands are used to generate database tables required by ndoutils. These tables are prefixed with "Nagios _" by default; the Install script command must be executed in the DB subdirectory: # cd dB #. /installdb-u ndouser-P 123456-H localhost-D ndodb the meanings of the options are as follows: -U is used to specify the MySQL user account used for import-P represents the MySQL user's password-h Represents the MySQL server address, if it is localhost, -D can be omitted to indicate the target database Description: If it is integrated with cacti, the NPC plug-in will automatically generate the required table for ndoutils In the cacti database, all these tables are prefixed with "NPC. We will continue to describe the integration later in the article. 4. Copy and edit the configuration file # CD .. # cp-V config/{ndo2db. CFG, ndomod. CFG}/usr/local/Nagios/etc # vi/usr/local/Nagios/etc/Nagios. CFG Add: broker_module =/usr/local/Nagios/bin/ndomod-3x.o config_file =/usr/local/Nagios/etc/ndomod in the file. cfg in addition, make sure that your/usr/local/Nagios/etc/Nagios. the following row appears in CFG. Otherwise, add event_broker_options =-1 // enable event broker for Nagios.

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.