NPC 2.0.4 on CentOS 6.3

If you figure out how to do something interesting/cool in Cacti and want to share it with the community, please post your experience here.

Moderators: Developers, Moderators

Post Reply
rmelissari
Posts: 1
Joined: Wed Jan 23, 2013 5:25 pm

NPC 2.0.4 on CentOS 6.3

Post by rmelissari »

It seems like I have successfully installed NPC after struggling with it for some time and thought I would share the steps I took to get it working.

This was done using a Minimal install of CentOS 6.3 64-bit, but any RHEL based distribution should work. This should help setting up a nagios + cacti install through the cacti NPC plugin.

Install prerequisites:

Code: Select all

$ su -

Code: Select all

# yum install -y mysql-server.x86_64 mysql-devel.x86_64 php-mysql.x86_64 php-devel.x86_64 php.x86_64 php-snmp.x86_64 httpd.x86_64 net-snmp.x86_64 net-snmp-devel.x86_64 net-snmp-utils.x86_64 rrdtool.x86_64 rrdtool-devel.x86_64 ruby-rrdtool.x86_64 gcc.x86_64 make.x86_64 wget.x86_64
Download Cacti from http://www.cacti.net/ and extract in root:

Code: Select all

# cd /root/ ; wget http://www.cacti.net/downloads/cacti-0.8.8a.tar.gz 
# tar -xvf /root/cacti-0.8.8a.tar.gz
Configure mysql and set root password to P@ssw0rd (set this to a better password):

Code: Select all

# service mysqld start ; chkconfig mysqld on 
# mysqladmin -u root password 'P@ssw0rd'
# mysql_secure_installation
    Set root password? [Y/n] n
    Remove anonymous users? [Y/n] Y
    Disallow root login remotely? [Y/n] Y
    Remove test database and access to it? [Y/n] Y
    Reload privilege tables now? [Y/n] Y    

Import the cacti database (Change P@ssword to your password. This sed syntac is just putting the necessary commands into the .sql file so we can import the database structure in the right database and give the cacti user the right permissions):

Code: Select all

# sed -i -e '1i USE cacti;' /root/cacti-0.8.8a/cacti.sql ; sed -i -e '1i CREATE DATABASE cacti;' /root/cacti-0.8.8a/cacti.sql ; echo "CREATE USER cacti;" >> /root/cacti-0.8.8a/cacti.sql ; echo "GRANT ALL ON cacti.* TO 'cacti'@'localhost' IDENTIFIED BY 'P@ssw0rd';" >> /root/cacti-0.8.8a/cacti.sql ; mysql -u root -p < /root/cacti-0.8.8a/cacti.sql

Create a cacti user and make it apart of the apache group. Also gave it nologin shell for security:

Code: Select all

# useradd -s /sbin/nologin -M -N -G apache cacti
Move the source files to web directory with correct permissions:

Code: Select all

# mkdir -p /var/www/html/cacti ; cp -R /root/cacti-0.8.8a/. /var/www/html/cacti ; chown -R cacti:apache /var/www/html/cacti

Attach mysql to cacti, changing the password to what you set earlier:

Code: Select all

# vi +/database_username /var/www/html/cacti/include/config.php
$database_username = "cacti";
$database_password = "P@ssw0rd";

Configure iptables:

Code: Select all

# vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

# service iptables restart

Turn on snmp:

Code: Select all

# service snmpd start ; chkconfig snmpd on

Enable php in Apache:

Code: Select all

# vi /etc/httpd/conf.d/php.conf
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps




Start Apache:

Code: Select all

# service httpd start ; chkconfig httpd on

Browse to http://localhost/cacti/

(click next)

New Installation:

(click next)
Finish Installation:

(click finish)

Log into http://localhost/cacti using default username/password:
login: admin
password: admin




Download Nagios from http://www.nagios.org/download/core/thanks/

Code: Select all

# cd /root/ ; wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.4.tar.gz ; tar -xvf nagios-3.4.4.tar.gz
Configure user accounts:

Code: Select all

# useradd -s /bin/bash nagios ; groupadd nagcmd ; usermod -G nagcmd nagios ; usermod -G nagcmd apache ; usermod -G nagcmd cacti

Compile & Install Nagios:

Code: Select all

# cd /root/nagios/ ; ./configure --with-command-group=nagcmd ;  make all ; make install ; make install-init ; make install-config ; make install-commandmode ; make install-webconf

Download Nagios-Plugins from http://nagiosplugins.org/ and extract:

Code: Select all

# cd /root/ ; wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gz ; tar -xvf nagios-plugins-1.4.16.tar.gz

Install Nagios-Plugins:

Code: Select all

# cd /root/nagios-plugins-1.4.16 ; ./configure --with-nagios-user=nagios --with-nagios-group=nagios ; make ; make install
NRPE:

Code: Select all

# cd /root ; wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz ; tar -xvf nrpe-2.13.tar.gz ; cd /root/nrpe-2.13 ; ./configure ; make ; make install
Enable nrpe check for nagios (Add to the bottom of define commands):

Code: Select all

# vi /usr/local/nagios/etc/objects/commands.cfg
#NRPE
define command{
    command_name    check_nrpe
    command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
    }
Start Nagios:

Code: Select all

# /etc/rc.d/init.d/nagios start

Setup Web User for Nagios (Create Nagios web password):

Code: Select all

# htpasswd -c /usr/local/nagios/etc/htpasswd.users admin
New password: 
Re-type new password: 

Prerequistes to NPC (ndoutils 1.4b7):

Code: Select all

# cd /root/ ; wget http://sourceforge.net/projects/nagios/files/ndoutils-1.x/ndoutils-1.4b7/ndoutils-1.4b7.tar.gz ; tar -xvf ndoutils-1.4b7.tar.gz ; cd /root/ndoutils-1.4b7 ; ./configure --disable-pgsql --with-mysql-lib=/usr/lib64/mysql --with-ndo2db-user=nagios --with-ndo2db-group=nagios ; make

Download NPC from http://www.mediafire.com/?iefyesb24ppsbwl (You will have to actually go and download it):

Code: Select all

# cd /root ; tar -xvf npc-2.0.4.tar.gz ; cp -R /root/npc /var/www/html/cacti/plugins

Copy plugins:

Code: Select all

# cp /root/ndoutils-1.4b7/src/ndomod-3x.o /usr/local/nagios/bin/ndomod.o ; cp /root/ndoutils-1.4b7/config/ndomod.cfg /usr/local/nagios/etc/ndomod.cfg ; cp /root/ndoutils-1.4b7/src/ndo2db-3x /usr/local/nagios/bin/ndo2db ; cp /root/ndoutils-1.4b7/config/ndo2db.cfg /usr/local/nagios/etc/ndo2db.cfg

Configure nagios to use tcp rather than udp:

Code: Select all

# vi +/output=127.0.0.1 /usr/local/nagios/etc/ndomod.cfg
output=127.0.0.1
#output=/usr/local/nagios/var/ndo.sock

Code: Select all

# vi +/output_type=tcpsocket /usr/local/nagios/etc/ndomod.cfg
output_type=tcpsocket
#output_type=unixsocket

Code: Select all

# vi +/socket_type=unix /usr/local/nagios/etc/ndo2db.cfg
#socket_type=unix
socket_type=tcp



Change some configuration options in nagios:

Code: Select all

# echo "broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg" >> /usr/local/nagios/etc/nagios.cfg ; sed -i 's/process_performance_data=0/process_performance_data=1/g' /usr/local/nagios/etc/nagios.cfg

More configuration changes to plugins (This is one block of code you can copy and paste into your shell):

Code: Select all

# sed -i 's/db_host=localhost/db_host=127.0.0.1/g' /usr/local/nagios/etc/ndo2db.cfg ; sed -i 's/db_name=nagios/db_name=cacti/g' /usr/local/nagios/etc/ndo2db.cfg ; sed -i 's/db_prefix=nagios_/db_prefix=npc_/g' /usr/local/nagios/etc/ndo2db.cfg ; sed -i 's/db_user=ndouser/db_user=cacti/g' /usr/local/nagios/etc/ndo2db.cfg ; sed -i 's/db_pass=ndopassword/db_pass=P@ssw0rd/g' /usr/local/nagios/etc/ndo2db.cfg ; chmod go+r /usr/local/nagios/etc/ndomod.cfg ; chmod go+r /usr/local/nagios/etc/ndo2db.cfg

Download cacti plugins:

Code: Select all

# cd /var/www/html/cacti/plugins ; wget http://docs.cacti.net/_media/plugin:settings-v0.7-1.tgz ; mv plugin\:settings-v0.7-1.tgz settings-v0.7-1.tgz ; tar -xvf settings-v0.7-1.tgz ; cd /var/www/html/cacti/plugins ; wget http://docs.cacti.net/_media/plugin:monitor-v1.2-1.tgz ; mv plugin\:monitor-v1.2-1.tgz monitor-v1.2-1.tgz ; tar -xvf monitor-v1.2-1.tgz
Browse to http://localhost/cacti and then Console -> Configuration -> Plugin Management. Then install and enable the NPC plugin:



Browse to http://localhost/cacti and then Console -> Configuration -> Settings -> NPC
Nagios Command File Path: /usr/local/nagios/var/rw
Nagios URL: http://localhost/nagios



Create the database tables for ndo2db:

Code: Select all

# cd /root/ndoutils-1.4b7/db/ ; ./installdb -u root -p "P@ssw0rd" -h localhost -d cacti

Create init.d script for ndo2db and configure to start at boot:

Code: Select all

# vi /etc/init.d/ndo2db
Copy Contents of: ndo2db script (Courtesy of Gaëtan from http://www.itpointofview.com/?p=191)

Code: Select all

# chmod gou+x /etc/init.d/ndo2db
# /etc/init.d/ndo2db start
# chkconfig ndo2db on
Add nagios to apache group:

Code: Select all

#usermod -a -G nagios apache

Set SELinx security for nagios:

Code: Select all

# chcon -R -t httpd_sys_content_t /usr/local/nagios

Set correct permissions on plugins:

Code: Select all

# chown -R nagios:apache /var/www/html/cacti/plugins ; chown -R nagios:nagios /usr/local/nagios

Restart and enable Nagios on boot:

Code: Select all

# chkconfig nagios on ; service nagios restart

Restart the box and test everything comes back up, you are done!

Code: Select all

# yum -y update ; shutdown -r now
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests