Cacti is a network graphing tool similar to MRTG. How do I install and configure common options to collect SNMP data and various other data (such as system load, network link status, hard disk space, logged in users etc) into an RRD?
From the official project site:
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:
- MySQL Server : Store cacti data.
- NET-SNMP server - SNMP (Simple Network Management Protocol) is a protocol used for network management.
- PHP with net-snmp module - Access SNMP data using PHP.
- Apache / lighttpd / ngnix webserver : Web server to display graphs created with PHP and RRDTOOL.
Install the software
First, login as root user and type the following command to install mysql, apache and php:
# yum install mysql-server mysql php-mysql php-pear php-common php-gd php-devel php php-mbstring php-cli php-snmp php-pear-Net-SMTP php-mysql httpd
Configure MySQL server
First, set root password:
# mysqladmin -u root password NEWPASSWORD
Create cacti MySQL database
Create a database called cacti, enter:
# mysql -u root -p -e 'create database cacti'
Create a user called cacti with a password called zYn95ph43zYtq, enter:
# mysql -u root -p
mysql> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'zYn95ph43zYtq'; mysql> FLUSH privileges; mysql> \q
Install snmpd
Type the following command to install net-snmpd
# yum install net-snmp-utils php-snmp net-snmp-libs
Configure snmpd, open /etc/snmp/snmpd.conf
# vi /etc/snmp/snmpd.conf
Append / modify it as follows (see snmpd.conf man page for details):
com2sec local localhost public group MyRWGroup v1 local group MyRWGroup v2c local group MyRWGroup usm local view all included .1 80 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:
# /etc/init.d/snmpd start
# chkconfig snmpd on
Make sure you are getting information from snmpd:
# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
Sample ouptut:
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
First, make sure EPEL repo is enabled. Type the following command to install cacti:
# yum install cacti
Install cacti tables
Type the following command to find out cacti.sql path:
# rpm -ql cacti | grep cacti.sql
Sample output:
/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):
# mysql -u cacti -p cacti < /usr/share/doc/cacti-0.8.7d/cacti.sql
Configure cacti
Open /etc/cacti/db.php file, enter:
# vi /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 = "zYn95ph43zYtq"; $database_port = "3306";
Save and close the file.
Configure httpd
Open /etc/httpd/conf.d/cacti.conf file, enter:
# 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
<Directory /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:
# service httpd restart
Setup cacti cronjob
Open /etc/cron.d/cacti file, enter:
# vi /etc/cron.d/cacti
Uncomment the line:
*/5 * * * * cacti /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1
Save and close the file.
Run cacti installer
Now cacti is ready to install. Fire a webbrowser 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 as follows:
Finally, click on Save button.
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.
How do I view graphs?
To view graphs click on Graphs tab. Here is sample graph from one my own box:
(Fig.02: Cacti in action)
Further readings:
- Cacti project
- man pages - yum, snmpd, snmpd.conf
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- My 10 UNIX Command Line Mistakes
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
- Email FAQ to a friend
- Download PDF version
- Printable version
- Comment RSS feed
- Last Updated: 06/26/09






{ 26 comments… read them below or add one }
Good post. Thanks for your great site.
You can find many more templates and help at the cacti forums.
The latest version of cacti (cacti-0.8.7d) requires that you edit include/config.php with the MySql details.
Thanks for details giving for “cacti” installation
Great details for doing this, definitely saved me some headaches with the snmp stuff.
First I had difficulties installing cacti on CentOS 5.3 as “yum install cacti” did not work. I resolved this by installing and enabling rpmforge-release packages.
Now I am not able to locate “db.php” file. Help!
Have you used locate to find it?
I don’t see db.php on my centos system. Maybe you’re missing something.
lol, as per my previous comment you need to edit include/config.php.
Thanks Guys! I had missed out on this: “First, make sure EPEL repo is enabled. Type the following command to install cacti”
It worked fine after disable the rpmforge-release packages and reinstalled cacti by enabling EPEL repo.
I got this information here: http://www.linuxquestions.org/questions/red-hat-31/yum-install-cacti-does-not-work-on-centos-5.3-any-suggestions-740509/
hi ive already installed cacti on my centos distro 5.xx – problem is i cant find the db.php on the cacti directories, what could be the problem with this..anyone have idea…?
@ruben,
Did you enabled EPEL repo and installed cacti?
Vivek, thanks for your tips however, the graph values always say “NAN”, is there any thing should i check ? I ran MRTG and nagios on the same machine where the cacti was installed.
I tried re-installing cacti on a fresh rhel 5.3 machine but still “NAN” as show on the graph value.
Thanks for this tips once again.
- Eric
Hi, when I go to change it to SNMP, it says “SNMP error” in red when I go back to the device to add graphs, etc. What did I do wrong? snmpd is running, etc. Thanks for the help.
I fixed the connect error, but when I try to use the OID to log network info, I get
snmpget -v 1 -c “public” localhost .1.3.6.1.4.1.4413.4.1
Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: SNMPv2-SMI::enterprises.4413.4.1
Also, in Cacti, it does not let me chose “SNMP – Interface Stats”, it only gives me an option for “SNMP – Generic OID Template”. Help please :)
(sorry if I sent this multiple times, it was not working :/)
I fixed the connect error, but when I try to use the OID to log network info, I get
http://pastebin.com/f15dbdb45
Also, in Cacti, it does not let me chose “SNMP – Interface Stats”, it only gives me an option for “SNMP – Generic OID Template”. Help please :)
(sorry if I sent this multiple times, it was not working :/ Also, pastebinned what happened as the site keeps not posting my comment?)
Sorry for flooding, I have no idea how to edit posts. I am using Ubuntu as my server, if it matters :/ I could not find any Ubuntu install guide for cacti.
Was a very helpful guide to install cacti.
I couldn’t find /etc/cacti/db.php as well – but, I have entered similar information in config.php file in the INSTALL directory. Seems to work. Am able to open the Web interface.
Hi,
I’m stuck at step:
“service httpd restart”
I got a error:
[root@DW init.d]# service httpd restart
Stopping httpd: [FAILED]
Starting httpd: httpd: Syntax error on line 161 of /etc/httpd/conf/httpd.conf: Cannot load /etc/httpd/modules/mod_ldap.so into server: /etc/httpd/modules/mod_ldap.so: undefined symbol: apr_ldap_ssl_init
[FAILED]
[root@DW init.d]#
I forgot to mention, on that server I have Oracle DB 10g running also.
[root@DW /]# find ./ -name httpd.conf
./usr/local/apache2/conf/httpd.conf
./usr/local/apache2/conf/original/httpd.conf
./root/app/httpd-2.2.9/docs/conf/httpd.conf
./root/app/backup/httpd/conf/httpd.conf
./etc/httpd/conf/httpd.conf
[root@DW /]#
As you can see I have few “htttpd.conf” file
Good post, do you have a follow up on how to configure remote machines for CACTI?
Hi all!
How to config to monitor many server linux with cacti?
Running: RedHat Enterp 6.0, 2.6.29.4-1.el6.i686.PAE
I have problem with installing Cacti, related to php-snmp/net-snmp-utils/xorg-X11
How I can solve this with redhat 6.0?
cacti-0.8.7e-1.el5.rf.noarch from rpmforge has depsolving problems
–> Missing Dependency: net-snmp-utils is needed by package cacti-0.8.7e-1.el5.rf.noarch (rpmforge)
cacti-0.8.7e-1.el5.rf.noarch from rpmforge has depsolving problems
–> Missing Dependency: php-snmp is needed by package cacti-0.8.7e-1.el5.rf.noarch (rpmforge)
rrdtool-1.3.8-2.el5.rf.i386 from rpmforge has depsolving problems
–> Missing Dependency: xorg-x11-fonts-Type1 is needed by package rrdtool-1.3.8-2.el5.rf.i386 (rpmforge)
Error: Missing Dependency: xorg-x11-fonts-Type1 is needed by package rrdtool-1.3.8-2.el5.rf.i386 (rpmforge)
Error: Missing Dependency: net-snmp-utils is needed by package cacti-0.8.7e-1.el5.rf.noarch (rpmforge)
Error: Missing Dependency: php-snmp is needed by package cacti-0.8.7e-1.el5.rf.noarch (rpmforge)
Note if you are using PHP 5.3, to generate the graphs you will need to edit some of the files or turn off all errors to suppress warnings about deprecated functions.
I already have a cacti installed on a debian enviroment working fine.
Now with Centos 5.3 under Apache 2.x with dependencies ok (cacti installed via rpmforge) cacti works BUT don’t generates any RRD graph ? What’s going on ?
I’ve algo installed the sources of cacti into a new vhost by myself with the same results, there are some problems related to safe mode = on. But they’re solved or it seems to be solved since a don’t see any erros at this point:
[root@ www]# php /var/www/cacti/cmd.php
12/18/2009 01:23:27 PM – CMDPHP: Poller[0] Host[1] DS[3] CMD: perl /var/www/cacti/scripts/linux_memory.pl MemFree:, output: 24404
12/18/2009 01:23:27 PM – CMDPHP: Poller[0] Host[1] DS[4] CMD: perl /var/www/cacti/scripts/linux_memory.pl SwapFree:, output: 1995568
12/18/2009 01:23:27 PM – CMDPHP: Poller[0] Host[1] DS[5] CMD: perl /var/www/cacti/scripts/loadavg_multi.pl, output: 1min:0.22 5min:0.24 10min:0.19
12/18/2009 01:23:27 PM – CMDPHP: Poller[0] Host[1] DS[6] CMD: perl /var/www/cacti/scripts/unix_users.pl , output: 1
12/18/2009 01:23:27 PM – CMDPHP: Poller[0] Host[1] DS[7] CMD: perl /var/www/cacti/scripts/unix_processes.pl, output: 148
12/18/2009 01:23:27 PM – CMDPHP: Poller[0] Time: 0.0422 s, Theads: N/A, Hosts: 1
[root@www]# php /var/www/cacti/poller.php
12/18/2009 01:19:13 PM – POLLER: Poller[0] NOTE: Poller Int: ‘300′, Cron Int: ‘300′, Time Since Last: ‘252′, Max Runtime ‘298′, Poller Runs: ‘1′
12/18/2009 01:19:13 PM – SYSTEM STATS: Time:0.4268 Method:cmd.php Processes:1 Threads:N/A Hosts:2 HostsPerProcess:2 DataSources:5 RRDsProcessed:0
SELinux is disabled.
PHP 5.1.6 (cli) (built: Apr 7 2009 08:00:04)
Still unable to get rrd data created and view default localhost graphs.
Any ideas ? Thanks in advance.
I forget, cacti version is Version 0.8.7e
thanx for the tutorial!
if someone had the same problema as i:
after the installation, i had to manually copy the files of cacti to the default folder of apache using the command:
# mkdir /var/www/html/cacti
# cp /usr/share/cacti/*.* /var/www/html/cacti/
(SO CentOS 5.4)
Hey after installing cacti using yum in my cent OS server…..I get a blank page when I try accessing http://myserver.com/cacti
All packages and configurations are done as per your post….. please help……..!!!!