Installing and setting up nagios on centos 7

Created - 06/11/2015

Last Tested - N/A

OS: Centos


Install httpd

Command= yum install httpd

Command= systemctl start httpd.service

–auto start http at boot–

Command= systemctl enable httpd.service

allow firewall ports

I'm going to disable firewalld and fall back to iptables.

Command= yum install -y iptables-services

Command= systemctl mask firewalld

Command= systemctl enable iptables

Command= systemctl stop firewalld

Command= systemctl start iptables

allow port 80.

Command= iptables -I INPUT -p tcp –destination-port 80 -j ACCEPT

save iptables using the following command.

Command= iptables-save>/etc/sysconfig/iptables


Installing php

Command= yum install -y php

restart the php service.

Command= systemctl restart httpd.service


Install nagios pre reqs

Command= yum install gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel

Add user and groups

Command= useradd nagios

Command= groupadd nagcmd

Command= usermod -a -G nagcmd nagios


Install Nagios Core

Command= cd ~

Download Nagios

Latest stable release
curl -L -O http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz
Latest release candidate
curl -L -O http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.1.0rc1.tar.gz

Extract the Nagios

Command= tar xvf nagios-*.tar.gz

Command= cd nagios-*

Configure Nagios / remove the space in the following command between the two - -

Command= ./configure - -with-command-group=nagcmd

Command= make all

Command= make install

Command= make install-commandmode

Command= make install-init

Command= make install-config

Command= make install-webconf

add apache user to the nagcmd group.

Command= usermod -G nagcmd apache


Install Nagios Plugins

Command= cd ~

curl -L -O http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz

Command= tar xvf nagios-plugins-*.tar.gz

Command= cd nagios-plugins-*

remove the space in the following command between the two - -

Command= ./configure - -with-nagios-user=nagios - -with-nagios-group=nagios - -with-openssl

Command= make

Command= make install


Install NRPE

Command= cd ~

curl -L -O http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz

Check for latest version here: http://sourceforge.net/projects/nagios/files/nrpe-2.x/

Command= tar xvf nrpe-*.tar.gz

Command= cd nrpe-*

remove the space in the following command between the two - -

Command= ./configure - -enable-command-args - -with-nagios-user=nagios - -with-nagios-group=nagios - -with-ssl=/usr/bin/openssl - -with-ssl-lib=/usr/lib/x86_64-linux-gnu

Command= make all

Command= make install

Command= make install-xinetd

Command= make install-daemon-config

edit xinetd startup script

Command= nano /etc/xinetd.d/nrpe

only_from = 127.0.0.1 ADD-IP-HERE

Save and Exit.

Command= service xinetd restart


Configure Nagios

Command= nano /usr/local/nagios/etc/nagios.cfg

Uncomment the following line.

#cfg_dir=/usr/local/nagios/etc/servers

Save and Exit.

Create the storage location for configuration files.

Command= mkdir /usr/local/nagios/etc/servers


Configure Nagios Contacts

Command= nano /usr/local/nagios/etc/objects/contacts.cfg

change [email protected] to your email address.

email                           [email protected]        ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

Save and Exit.


Configure check_nrpe Command

Command= nano /usr/local/nagios/etc/objects/commands.cfg

Add the following to the end of the config file.

define command{
      command_name check_nrpe
      command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

Save and Exit.


Configure Apache

You can change nagiosadmin that will be your username. This will require more config HERE.

Command= htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Enter a password.

Restart nagios and apache service.

Command= sudo systemctl start nagios.service

Command= sudo systemctl restart httpd.service

setting nagios to run at boot.

Command= sudo chkconfig nagios on


( ONLY IF YOU CHANGED THE USERNAME!)

changing user authorized for host.

change every nagiosadmin to your new username in the following file.

Comman= nano /usr/local/nagios/etc/cgi.cfg


ERRORS - FIXES


Error: Could not stat() command file '/usr/local/nagios/var/rw/nagios.cmd'!

Command= setenforce 0

Permanent fix.

Command= nano /etc/sysconfig/selinux

change SELINUX=enforce to SELINUX=permissive


Adding Remote Linux Host to Nagios Server