Installing Cacti on Centos 6.3

Cacti requires the following packages to be installed:

  1. MySQL: A Database server to store cacti information.
  2. Apache: A Web server to display network graphs created by PHP and RRDTool.
  3. PHP: A script module to create graphs using RRDTool.
  4. PHP-SNMP: A PHP extension for SNMP to access data.
  5. NET-SNMP: A SNMP (Simple Network Management Protocol) is used to manage network.
  6. RRDTool: A database tool to manage and retrieve time series data like CPU load, Network Bandwidth etc.
  7. Cronie: This isn’t required by Cacti but is useful when wanting to schedule regular backups

Installing the Cacti Required Packages

Use this guide to configure YUM access through a proxy server
Use YUM to install the required packages:

Install MySQL
yum install mysql mysql-server -y
Install Apache
yum install httpd httpd-devel -y
Install PHP
yum install php-mysql php-pear php-common php-gd php-devel php php-mbstring php-cli php-mysql -y
Install PHP-SNMP
yum install php-snmp -y
Install NET-SNMP
yum install net-snmp-utils p net-snmp-libs php-pear-Net-SMTP -y
Install RRDTool
yum install rrdtool -y
Checking and Installing Crontab

Check to see if the crond service is installed and running:

service crond status

If the service cannot be found, install it:

yum install cronie -y

Starting Apache, MySQL, SNMP and Cronie Services

Once the required dependencies have been installed, start them:

Starting Apache
service httpd start
Starting MySQL
service mysqld start
Starting SNMP
service snmpd start
Starting Cron
service crond start
Configure Start-Up Links

Configuring Apache, MySQL, SNMP and Cron services to start on boot

/sbin/chkconfig --levels 345 httpd on
/sbin/chkconfig --levels 345 mysqld on
/sbin/chkconfig --levels 345 snmpd on
/sbin/chkconfig --levels 345 crond on

Installing Cacti

Install and enable the EPEL repository using wget. If wget is not installed, use the following command to install it. Use this guide to use wget through a proxy server

yum install wget -y
wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm

Once the repository is enabled, install the Cacti application:

yum install cacti -y

If the following error appears:

Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again

Edit the following file ‘/etc/yum.repos.d/epel.repo’ and modify the mirror list URLS so that they access them on http rather than https.

mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearc
mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch
mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=epel-source-6&arch=$basearch

Configuring MySQL Server for Cacti

MySQL Server for Cacti requires configuring.

Set the MySQL Root Password

To set a new password for MySQL server, use the following command: (NOTE: this is for a new MySQL installation only)

mysqladmin -u root password PASSWORD
Create MySQL Cacti Database

Log into the MySQL server with the password you created above and create the Cacti database and the Cacti user (along with password):

mysql -u root -p
mysql>create database cacti;
mysql>GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'PASSWORD';
mysql>FLUSH privileges;
mysql>quit;
Find and Install Cacti Tables

Use the following command to find the database file path using RPM:

rpm -ql cacti | grep cacti.sql

Install the tables into the Cacti database:

mysql -u cacti -p PASSWORD < PATH_PROVIDED_BY_PRECEDING_COMMAND
Configure Cacti with correct MySQL settings

Edit the file called ‘/etc/cacti/db.php‘, and make the following changes (highlighted in RED). Ensure the password is set correctly:

 /* make sure these values reflect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "PASSWORD";
$database_port = "3306";
$database_ssl = false;

Configuring Apache for Cacti

Enabling Access to Web Interface

To enabled access to the Cacti application from the local network or per IP level, edit the file called “/etc/httpd/conf.d/cacti.conf”. The configuration below allows access from all IP addresses. This can be viewed as an insecure option.

Alias /cacti /usr/share/cacti
<Directory /usr/share/cacti/>
Order Deny,Allow
Deny from none
Allow from all
</Directory /usr/share/cacti/>

As an example. the following configuration enable access to Cacti from the LAN 172.16.16.0/20:

Alias /cacti /usr/share/cacti
<Directory /usr/share/cacti/>
Order Deny,Allow
Deny from all
Allow from 172.16.16.0/20
</Directory /usr/share/cacti/>

In order for this change to take effect, the Apache service requires restarting:

service httpd restart
Setting the Timezone in PHP.ini

Edit the file “etc/php.ini”, locate and find the line “date.timezone” – change this so it reads

date.timezone = Europe/London

Restart the apache service

service httpd restart

Setting Cron for Cacti

Edit the file “/etc/cron.d/cacti” and uncomment the following line (delete the #)

*/5 * * * * cacti /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1

The poller.php script runs every 5mins and collects data of known host which is used by Cacti application to display graphs.

Setting up the IP Tables

Edit the file “/etc/sysconfig/iptables” and add the following line in RED:

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

In order for this to take effect, the iptable service requires restarting

service iptables restart

Installing SPINE

Use the following commands to download the packages required to compile and install spine:

yum install net-snmp-devel mysql mysql-devel openssl-devel ksh automake autoconf libtool gcc make –y
cd
wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.8a.tar.gz
tar -xvzf cacti-spine-0.8.8a.tar.gz
cd cacti-spine-0.8.8a
chmod 744 ./configure
autoconf
autoheader
automake
./configure
make
make install
cp /usr/local/spine/etc/spine.conf.dist /etc/spine.conf
cd /usr/local/spine/bin
chmod +s spine

edit ‘/etc/spine.conf’ to match cacti’s config.php. Within the cacti GUI, add the spine binary path in settings -> paths ‘/usr/local/spine/bin/spine’ and then under the poller tab, change the type from cmd.php to spine.