Configure Cacti in Linux


Cacti is a complete frontend to RRDTool, it stores all of the necessary information to create graphs and populate them with data in a MySQL database. The frontend is completely PHP driven. Along with being able to maintain Graphs, Data Sources, and Round Robin Archives in a database, cacti handles the data gathering. There is also SNMP support for those used to creating traffic graphs with MRTG.

Required software(s)

You need to install the following software on RHEL / Fedora / CentOS Linux:

  1. MySQL Server : Store cacti data.
  2. NET-SNMP server – SNMP (Simple Network Management Protocol) is a protocol used for network management.
  3. PHP with net-snmp module – Access SNMP data using PHP.
  4. Apache / lighttpd / ngnix webserver : Web server to display graphs created with PHP and RRDTOOL.

Install the software

[root@server~]# yum install mysql-server

[root@server~]# yum install mysql

[root@server~]# yum install php-mysql  php-pear php-common

 [root@server~]#  yum install php-gd  php-devel  php

[root@server~]# php-mbstring php-cli php-snmp

 [root@server~]# yum install php-pear-Net-SMTP php-mysql

Configure MySQL server

[root@server~]# mysqladmin -u root password NEWPASSWORD

Create cacti MySQL database

[root@server~]# mysql -u root -p -e 'create database cacti'

Create a user called cacti with a password called jktech,
[root@server~]#  mysql -u root -p

mysql> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY ‘jktech’;

mysql> FLUSH privileges;

mysql> \q

 Install snmpd

Type the following command to install net-snmpd
[root@server~]# yum install net-snmp-utils php-snmp net-snmp-libs

Configure snmpd, open /etc/snmp/snmpd.conf
[root@server~]# vi /etc/snmp/snmpd.conf
Append / modify it as follows (see snmpd.conf man page for details):

#           sec.name         source          community
com2sec     local          localhost           public

#        groupName        securityModel          securityName
group    MyRWGroup            v1                      local
group    MyRWGroup            v2c                     local 
group    MyRWGroup            usm                     local

# Make at least  snmpwalk -v 1 localhost -c public system fast again.
#                   name         incl/excl     subtree         mask(optional)
 view               all            included       .1                 80

# Finally, grant the group read-only access to the systemview view.
#              group        context s  ec.model   sec.level   prefix  read   write  notif
access        MyRWGroup       ""        any        noauth     exact   all     all    none

syslocation  Unknown (edit /etc/snmp/snmpd.conf)
syscontact    Root  (configure /etc/snmp/snmp.local.conf)
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat
Save and close the file.

Turn on snmpd service:
[root@server~]#service snmpd start
[root@server~]# chkconfig  snmpd on

Make sure you are getting information from snmpd:
[root@server~]# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex

IP-MIB::ipAdEntIfIndex.10.10.29.68 = INTEGER: 2

IP-MIB::ipAdEntIfIndex.67.yy.zz.eee = INTEGER: 3

IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1

Install cacti

[root@server~]# yum install cacti

Install cacti tables

Type the following command to find out cacti.sql path:
[root@server~]# rpm -ql cacti | grep cacti.sql
/usr/share/doc/cacti-0.8.7d/cacti.sql

Type the following command to install cacti tables (you need to type the cacti user password):
[root@server~]# mysql -u cacti -p cacti < /usr/share/doc/cacti-0.8.7d/cacti.sql

Configure cacti

[root@server~]# vim /etc/cacti/db.php
Make changes as follows:

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

Configure httpd
[root@server~]# vi /etc/httpd/conf.d/cacti.conf
You need to update allow from line. Either set to ALL or your LAN subnet to allow access to cacti:
# Cacti: An rrd based graphing tool
#
Alias /cacti    /usr/share/cacti
 
usr/share/cacti/>
        Order Deny,Allow
        Deny from all
        Allow from 10.0.0.0/8
</Directory>

Another option is create /usr/share/cacti/.htaccess file and password protect the 
directory. Finally, restart httpd:

[root@server~]# service httpd restart

Setup cacti cronjob
[root@server~]# vi /etc/cron.d/cacti
Uncomment the line:
*/5 * * * *     cacti   /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1

Run cacti installer

Now cacti is ready to install. Fire a web browser and type the url:
http://your.example.com/cacti/  or http://your.server.ip.address/cacti/

Just follow on screen instructions. The default username and password for cacti is admin / admin. Upon first login, you will be force to change the default password.

How do I configure SNMP data collection?

SNMP can be used to monitor server traffic. Once installed login to cacti.
=> Click on Devices

=> Select Localhost

=> Make sure SNMP options are selected

How do I create SNMP graphs?

Click on “Create Graphs for this Host” link on top right side. Select SNMP – Interface Statistics. Select a graph type (such as In/Out bytes with total bandwidth)finally, click on Create button.

About Alex Hunt

Hi All I am Manish Kumar Jha aka Alex Hunt. I am currently working in VMware Software India Pvt Ltd as Operations System Engineer (vCloud Air Operations). I have around 5 Years of IT experience and have exposure on VMware vSphere, vCloud Director, RHEL and modern data center technologies like Cisco UCS and Cisco Nexus 1000v and NSX. If you find any post informational to you please press like and share it across social media and leave your comments if you want to discuss further on any post. Disclaimer: All the information on this website is published in good faith and for general information purpose only. I don’t make any warranties about the completeness, reliability and accuracy of this information. Any action you take upon the information you find on this blog is strictly at your own risk. The Views and opinions published on this blog are my own and not the opinions of my employer or any of the vendors of the product discussed.
This entry was posted in Monitoring. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s