Configuration and application of Nagios

Source: Internet
Author: User
Nagios is an application for system and network monitoring. It monitors hosts and services under the conditions you set

Control, and notify the administrator when the monitored object is alerted and restored based on the alarm threshold value and alarm method set by the administrator.

The following describes how to install Nagios.

Before installing Nagios, you must first create a LAMP environment. of course, you can not install MySQL.

For LAMP installation, refer to the previous blog or follow the steps below to install it.

First download the following software:

Libmcrypt-2.5.8.tar.gz

Apr-1.4.6.tar.gz

Libpng-1.5.10.tar.gz

Apr-util-1.4.1.tar.gz

Libxml2-2.7.2.tar.gz

Curl-7.28.0.tar.gz

Libxslt-1.1.0.tar.g

Freetype-2.4.9.tar.gz

Nagios-3.4.3.tar.gz

Gd-2.0.35.tar.gz

Nagios-plugins-1.4.16.tar.gz

Httpd-2.4.2.tar.gz

Pcre-8.30.zip

Php-5.4.3.tar.gz

Zlib-1.2.5.tar.gz

Jpegsrc.v8b.tar.gz

Install the GD Library (for PHP to support GIF, PNG, and JPEG)

A. install iis8 to create a directory:

# Mkdir-p/usr/local/limit 8

# Mkdir-p/usr/local/sort 8/bin

# Mkdir-p/usr/local/IPv8/lib

# Mkdir-p/usr/local/Release 8/include

# Mkdir-p/usr/local/Example 8/man

# Mkdir-p/usr/local/IPv8/man1

# Mkdir-p/usr/local/IPv8/man/man1

# Cd/usr/local/src

# Tar-zvxf restart src.v8b.tar.gz

# Cd Route 8

#./Configure -- prefix =/usr/local/defaults 6/-- enable-shared -- enable-static

# Make

# Make install

B. libpng package (PNG supported)

# Cd/usr/local/src

# Tar-zvxf libpng-1.5.10.tar.gz

# Cd libpng-1.5.10

#./Configure -- prefix =/usr/local/libpng

# Make

# Make install

C. install freetype

# Cd/usr/local/src

# Tar-zvxf freetype-2.4.9.tar.gz

# Cd freetype-2.4.9

# Mkdir-p/usr/local/freetype

#./Configure -- prefix =/usr/local/freetype

# Make

# Make install

D. install zlib

# Cd/usr/local/src

# Tar-zxvf zlib-1.2.3.tar.gz

# Cd zlib.1.2.3

# Mkdir/usr/local/zlib

#./Configure -- prefix =/usr/local/zlib

# Make

# Make install

E. install the GD Library

# Cd/usr/local/src

# Tar-zvxf gd-2.0.35.tar.gz

# Mkdir-p/usr/local/gd2

# Cd gd/gd-2.0.35.tar.gz

#. /Configure -- prefix =/usr/local/gd2 -- with-jpeg =/usr/local/defaults 8 -- with-zlib-dir =/usr/local/zlib -- with-png = /usr/local/libpng -- with-freetype =/usr/local/freetype

# Make

# Make install

E. install the Curl Library

# Cd/usr/local/src

# Tar-zxvf curl-7.28.0.tar.gz

# Mkdir-p/usr/local/curl

# Cdcurl-7.28.0

#./Configure -- prefix =/usr/local/curl

# Make

# Make install

Install php5. php5 must support libxml2!

F. install libxml2

# Cd/usr/local/src

# Tar-zvxf libxml2-2.7.2.tar.gz

# Cd libxml2-2.7.2

# Mkdir-p/usr/local/libxml2

#./Configure -- prefix =/usr/local/libxml2

# Make

# Make install

G. install libxslt (optional)

# Cd/usr/local/src

# Tar-zvxf libxslt-1.1.0.tar.g

# Mkdir-p/usr/local/libxslt

# Cd libxslt-1.1.0

#./Configure -- prefix =/usr/local/libxslt -- with-libxml-prefix =/usr/local/libxml2

# Make

# Make install

H. install apr

# Cd/usr/local/src

# Tar-zxvf apr-1.4.6.tar.gz

# Cd apr-1.4.6

#./Configure -- prefix =/usr/local/apr-httpd

# Make & make install

I. install apr-util

# Cd/usr/local/src

# Tar zxvf apr-util-1.4.1.tar.gz

# Cd apr-util-1.4.1

#./Configure -- prefix =/usr/local/apr-util-httpd \

> -- With-apr =/usr/local/apr-httpd

# Make

# Make install

Install apache2

# Cd/usr/local/src

# Tar-zxvf httpd-2.4.2.tar.gz

# Cd httpd-2.4.2

The compilation process is shown as follows:

# Make

# Make install

Start the Apache server and check whether the port is enabled. the Command Line for starting the Apache server is as follows:

#/Usr/local/apache2/bin/apachectl start

View the PORT command line as follows:

# Netstat-tnl | grep 80

Tcp 0 0 0.0.0.0: 80 0.0.0.0: * LIST

Test the installation result. open the browser and enter http: // your IP in the address bar.

If It works appears in the browser! It indicates that the Apache server can be used.

It is necessary for each type of server software to be automatically started upon startup, and the Apache server to be automatically started upon startup, as long as "/etc/rc. d/rc. local file, and add the startup command of the Apache server. You can directly open the "/etc/rc. d/rc. local" file, write the Apache startup command in the last line, or append it with the echo command, as shown in the following command line:

# Echo "/usr/local/apache2/bin/apachectl start">/etc/rc. d/rc. local

If the following error occurs during apache startup:

Modify/usr/local/apache2/conf/httpd. conf

Find # ServerName www.example.com: 80 and add

ServerName yourIP: 80!

Install PHP

# Cd/usr/local/src

# Tar-zvxf php-5.4.3.tar.gz

# Mkdir-p/usr/local/php

# Cd

Php-5.4.3

#./Configure -- prefix =/usr/local/php \

> -- With-config-file-path =/usr/local/php \

> -- With-apxs2 =/usr/local/apache2/bin/apxs \

> -- With-gd =/usr/local/gd2 \

> -- With-jpeg-dir =/usr/local/defaults 8 \

> -- With-zlib-dir =/usr/local/zlib \

> -- With-png-dir =/usr/local/libpng \

>-With-freetype-dir =/usr/local/freetype -\

> -- With-curl =/usr/local/curl \

> -- With-xsl =/usr/local/libxslt \

> -- Enable-trace-vars \

> -- Enable-mbstring = all \

> -- Enable-soap

# Make

# Make install

After installation, you need to create a PHP configuration file. When using the configure command to install the configuration, use the "-- with-config-file-path =/usr/local/php/etc/" option to specify the location of the configuration file. Copy the php. ini-development file under the source package to/usr/local/php/etc/and change it to php. ini. As shown below:

# Cp php. ini-development/usr/local/php. ini

The following error may occur during PHP installation.

Make: *** [ext/gd. lo] error

Solution:

Vi /Include/gd_io.h

Add void * data in the gdIOCtx structure;

The format is as follows:

Typedef struct gdIOCtx

{

Int (* getC) (struct gdIOCtx *);

Int (* getBuf) (struct gdIOCtx *, void *, int );

Void (* putC) (struct gdIOCtx *, int );

Int (* putBuf) (struct gdIOCtx *, const void *, int );

/* Seek must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek! */

Int (* seek) (struct gdIOCtx *, const int );

Long (* tell) (struct gdIOCtx *);

My GD is installed in the/usr/local/gd2 directory, so it is # vi/usr/local/gd2/include/gd_io.h

Then re-compile and install it.

Integrate Apache and PHP. before compilation, when we use the configure command to install the configuration, use the -- with-apxs2 =/usr/local/apache2/bin/apxs option to enable Apache 2 to use PHP as a functional module. However, we also need to modify the Apahce configuration file, add PHP support, and tell Apache which suffixes will be parsed as PHP. For example. php or. the phtml suffix is resolved to PHP. use vi to open the Apache configuration file/etc/httpd. conf, find AddType application/x-gzip. gz. tgz command option, and add a command below AddType application/x-httpd-php. php. phtml. You can also resolve any suffix file to PHP, as long as you add a separate space in the added statement, here to add a. phtml for example, as shown below:

# If the AddEncoding directives abve are commented-out, then you

# Probably shoshould define those extensions to indicate media types:

#

AddType application/x-compress. Z

AddType application/x-gzip. gz. tgz

AddType application/x-httpd-php. php. phtml

After modification, you must restart the Apache server to reload the configuration file for the modification to take effect.

After modification, you must restart the Apache server to reload the configuration file for the modification to take effect.

#/Usr/local/apache2/bin/apachectl stop

#/Usr/local/apache242/bin/apachectl start

Install Nagios

# Creating an account

[Root @ Nagios src] # useradd nagios

[Root @ Nagios src] # passwd nagios

# Create a user group named nagcmd to execute external commands from the Web interface.

[Root @ Nagios src] # groupadd nagcmd

# Add nagios and apache users to this group

[Root @ Nagios src] # usermod-a-G nagcmd nagios

[Root @ Nagios src] # usermod-a-G nagcmd daemon

# Daemon is the account for running apache

[Root @ Nagios src] # tar zxvf nagios-3.4.3.tar.gz

[Root @ Nagios src] # cd nagios-3.4.3

[Root @ Nagios nagios-3.4.3] #./configure -- with-command-group = nagcmd \

> -- With-nagios-user = nagios \

> -- With-nagios-group = nagios \

>-With-gd-lib =/usr/local/gd2/lib /\

>-With-gd-inc =/usr/local/gd2/include/

[Root @ Nagios nagios-3.4.3] # make all

# Use make install to install the main program, CGI and HTML files

[Root @ Nagios nagios-3.4.3] # make install

# Use make install-init to install the startup script in/etc/rc. d/init. d.

[Root @ Nagios nagios-3.4.3] # make install-init

# Use make install-commandmode to configure directory permissions

[Root @ Nagios nagios-3.4.3] # make install-commandmode

# Use make install-cofig to install the sample configuration file. the installation path is/usr/local/nagios/etc.

[Root @ Nagios nagios-3.4.3] # make install-config

# Generate an apache configuration file

[Root @ Nagios nagios-3.2.3] # make install-webconf

In this step, httpd is under the sample-config/directory in the Nagios source code package. content in conf, append to/usr/local/apache2/conf/httpd. in conf, the above method is sometimes not appended. we recommend that you use the following manual method.

[Root @ Nagios nagios] # cat sample-config/httpd. conf>/usr/local/apache2/conf/httpd. conf

# Create a login user for apache. Note that the user name is nagiosadmin, which is used by default in cgi. cfg.

Account name, about CGI permission settings.

Note: The-c option is used to add users for the first time. after that, do not use this option to overwrite all previous users.

[Root @ Nagios nagios-3.4.3] # htpasswd-c/usr/local/nagios/etc/htpasswd. users nagiosadmin

Add automatic start upon startup

To enable automatic startup of Nagios and Apache, we add Nagios and Apache to the startup management program.

[Root @ Nagios ~] # Chkconfig -- add nagios

[Root @ Nagios ~] # Chkconfig -- level 35 nagios on

Install Nagios plugin nagios-plugins

Before starting Nagios, we also need to install the Nagios Plugins. This package contains a lot of Nagios

The commands and scripts used to execute the detection are required by Nagios.

[Root @ Nagios ~] # Cd/usr/local/src

[Root @ Nagios src] # tar zxvf nagios-plugins-1.4.16.tar.gz

[Root @ Nagios src] # cd nagios-plugins-1.4.16

[Root @ Nagios nagios-plugins-1.4.16] #./configure -- prefix =/usr/local/nagios

-- With-nagios-user = nagios -- with-nagios-group = nagios

[Root @ Nagios nagios-plugins-1.4.16] # make & make install

Start Nagios

If no error occurs during the installation process, we can start Nagios and Apache normally. If an error occurs

Check the installation according to the error prompt. Generally, the dependent library file is not installed.

[Root @ Nagios ~] #/Etc/init. d/nagios start

Starting nagios: done.

Then you can use http: // Nagios server IP/nagios/

Enter your account nagiosadmin and password to log on to Nagios. Nagios adds local monitoring by default, as shown in:

During the login process, You may report the error "You don't have permission to access/nagios/on this server". Google and Baidu checked the error and said that PHP was not installed, yum-install php can solve the problem. The actual solution is as follows:

First of all, check nagios. log under/usr/local/nagios/var. the error log in the content will show that the php page cannot be parsed by apache.

Solution:

Modify httpd. conf in apache configuration file

 
  
DirectoryIndex index.html
 Modify
 
  
DirectoryIndex index. php index.html
 You can. In some PHP versions, you may need to add LoadModule php5_module modules/libphp5.so AddType application/x-httpd-php. php. phtml AddType applicatoin/x-httpd-php-source. we have already added the last two lines of phps. The first line of php5.4 does not need to be added. Now, Nagios installation is complete!

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.