Source installation nagios-4.2 (centos 6.8)

Keywords: Apache yum vim iptables

Official documents
https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/quickstart-fedora.html

Dependency software
Before installing nagios, you need to install apache, php, gcc, gd-devel, which can be installed through yum.
This article is based on the source code build LAMP architecture (build LAMP)- http://blog.csdn.net/dinglinux/article/details/53926545 ) To deploy nagios monitoring, apache installation directory, configuration file directory and so on will be different from yum installation.

setup script
1. Create nagios-related users and groups

$ groupadd nagios
$ groupadd nagcmd
$ useradd -g nagios -G nagcmd nagios
$ passwd nagios

2. Download the nagios core package and plug-in package and decompress it

$ cd /usr/local/src
$ wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.2.1.tar.gz
$ wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.3.tar.gz
$ tar zxf nagios-4.2.1.tar.gz
$ tar zxf nagios-plugins-2.1.3.tar.gz

3. Compile and install nagios core

$ cd nagios-4.2.1
$ ./configure \
-prefix=/usr/local/nagios \
--with-command-group=nagcmd
$ make all
$ make install
$ make install-init
$ make install-config
$ make install-commandmode

When "make all" compiles successfully, there will be prompts on how to install it later. Here is an excerpt from it, which is a comment on "make install*".

make install
     - This installs the main program, CGIs, and HTML files

make install-init
     - This installs the init script in /etc/rc.d/init.d

make install-commandmode
     - This installs and configures permissions on the directory 
       for holding the external command file

make install-config
     - This installs *SAMPLE* config files in /usr/local/nagios/etc
       You'll have to modify these sample files before you can
       use Nagios.  Read the HTML documentation for more info
       on doing this.  Pay particular attention to the docs on
       object configuration files, as they determine what/how
       things get monitored!

make install-webconf
     - This installs the Apache config file for the Nagios
       web interface

"make install-webconf" is used to install nagios web-side configuration files and apache httpd for yum installation. If httpd is installed as the source code, the following error will occur:

$ make install-webconf
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
/usr/bin/install: cannot create regular file `/etc/httpd/conf.d/nagios.conf': No such file or directory
make: *** [install-webconf] Error 1

The alternative is to copy the sample-config/httpd.conf in the Nagios decompression directory to the / conf/extra/directory in the apache installation directory, renamed nagios.conf. Use the Include instruction in the apache master configuration file to make the configuration file effective.

$ cp /usr/local/src/nagios-4.2.1/sample-config/httpd.conf /usr/local/apache2/conf/extra/nagios.conf
$ vim /usr/local/apache2/conf/httpd.conf
# Add downlink
Include conf/extra/nagios.conf

4. Setting up alarm mailbox

$ vim /usr/local/nagios/etc/objects/contacts.cfg
# Example (email)
define contact{
        contact_name                    nagiosadmin            
        use                             generic-contact         
        alias                           Nagios Admin            
        email                           xxxx@163.com        
        }

5. Setting up web-end user control

$ htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

User files default to / usr/local/nagios/etc/htpasswd.users and need to be consistent with nagios.conf. After setting up, accessing the Nagios monitoring web interface requires entering a legitimate user name and corresponding password.

6. Compile and install nagios plug-ins

$ cd /usr/local/src/nagios-plugins-2.1.3
$ ./configure \
--with-nagios-user=nagios \
--with-nagios-group=nagios
$ make
$ make install

7. Set up nagios boot-up

$ chkconfig --add nagios
$ chkconfig nagios on

"make install-init" has placed the startup script in the / etc/rc.d/init.d / directory.

8. Close the firewall

$ iptables -F
$ service iptables save
$ vim /etc/selinux/config
# Change the following behavior:
SELINUX=disabled

9. Restart apache and start nagios

$ apachectl -t
$ apachectl graceful

$ /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 
$ service nagios start

$ ps aux | grep nagios

10.web-side login
windows Browser Input http://ip/nagios/ With user authentication, you can view monitoring information and start monitoring only nagios servers.

Posted by Julian on Fri, 05 Apr 2019 19:39:30 -0700