Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save anamorph/dadeb22340ca4deec5f2 to your computer and use it in GitHub Desktop.
Save anamorph/dadeb22340ca4deec5f2 to your computer and use it in GitHub Desktop.
HOWTO Install Cacti on AWS EC2 Instance running Amazon Linux

0. First install the pre-reqs

0.1 Installing

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 -y

0.2 Configuring services

chkconfig mysqld on
chkconfig httpd on
service mysqld start
service httpd start

0.3 Configuring MYSQLD

mysqladmin -u root password %your_password%
mysql -uroot -p mysql
mysql> create database cacti;
mysql> grant all on cacti.* to cacti identified by 'cacti';
mysql> flush privileges;
mysql> quit

1. Installing and configuring SNMPD

1.1 Installing

yum install net-snmp-utils php-snmp net-snmp-libs -y

1.2 Configuring

vi /etc/snmp/snmpd.conf (modify to match as follows):

####
# First, map the community name "public" into a "security name"

#       sec.name  source          community
com2sec local     localhost       public

####
# Second, map the security name into a group name:

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

####
# Third, create a view for us to let the group have rights to:

# 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 sec.model sec.level prefix read   write  notif
access  MyRWGroup      ""      any       noauth    exact  all    all    none    

###############################################################################
# System contact information
#

# It is also possible to set the sysContact and sysLocation system
# variables through the snmpd.conf file:

syslocation "Running from above, in the Cloud"
syscontact "me@nuage.ninja"    

Then close the config file and save modifications. Now onto running SNMPD as a service.

/etc/init.d/snmpd start
chkconfig snmpd on

Let's check everything is working fine

snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex

You should get an output as such

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

2. Installing and configuring CACTI

2.1 Installing

yum install cacti -y

Now, let's create the cacti tables from the provided SQL. As I usually don't remember where litterally EVERYTHING is stored in a package, I'll search for it

find / -name cacti.sql

Which will get you something like this

/usr/share/doc/cacti-0.8.8b/cacti.sql

Let's run this now

mysql -uroot -p cacti < /usr/share/doc/cacti-0.8.8b/cacti.sql

2.2 Configuring

2.2.1 CACTI

vi /usr/share/cacti/include/config.php

Make sure the information here matches what we edited in 0.3, close the config file and save modifications.

2.2.2 HTTPD

vi /etc/httpd/conf.d/cacti.conf

I modified that file to be able to log on from anywhere, but you could limit that either by using security groups or CIDR notation in the IfModule section

<Directory /usr/share/cacti/>
        <IfModule mod_authz_core.c>
                # httpd 2.4
                # Require host localhost
                Require host any
        </IfModule>
        <IfModule !mod_authz_core.c>
                # httpd 2.2
                Order deny,allow
                Deny from all
                # Allow from localhost
                Allow from all
        </IfModule>
</Directory>

Then close the config file and save modifications. Now onto running CACTI's poller in crontab.

vi /etc/cron.d/cacti

Let's check the config is ok, then remove the leading # as follows:

before

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

after

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

Then close the config file and save modifications. Restart cron to start polling into Cacti, and restart httpd to take all our modifications into account.

service crond restart
service httpd restart

2.2.3 WEB INTERFACE

Now that everything is configured, you can access the web interface at http://%your_host%/cacti/ The default login/password is admin/admin; you will be asked to change it upon the first login.

Enjoy !

@saulojg
Copy link

saulojg commented Aug 13, 2015

Thanks a lot!

@seachle
Copy link

seachle commented Aug 18, 2015

Thanks a lot!! It really helped!!

@jmodjeska
Copy link

jmodjeska commented Apr 13, 2018

Outstanding — thanks very much for this.

Some notes and troubleshooting steps that may help others:

Changes to username and password are required in 2.2.1

Although implied by the document, it bears calling out explicitly that in 2.2.1 you need to change the login credentials from cactiuser to cacti. Thus, config.php should say:

$database_username = 'cacti';
$database_password = 'cacti';

MySQL TimeZone database error

I encountered the following error upon launching the Cacti web interface:

ERROR: Your Cacti database login account does not have access to the MySQL TimeZone database. Please provide the Cacti database account "select" access to the "time_zone_name" table in the "mysql" database, and populate MySQL's TimeZone information before proceeding.

With help from this issue, I resolved the error as follows:

sudo mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql

mysql -u root -p
[enter password]
use mysql;
GRANT SELECT ON mysql.time_zone_name TO cacti;
flush privileges;
quit

sudo mysqld restart

Don't forget to select a template!

The very last step of the web UI setup offers some templates to choose from. If you're flying through setup, you can easily miss the fact that you have to tick a box here, else you don't get any graph templates. Select "Local Linux Machine" unless you know you want something different.

ERROR: opening '/usr/share/cacti/rra/*.rrd

As suggested here, this error, which appeared in the UI when I attempted to view a graph, can be cured by going (in the UI) to Utilities > System Utilities > Rebuild Poller Cache > Go.

MySQL Graphs

I couldn't figure out how to obtain/install Percona's MySQL graphs, but I found these, and they're nice (instructions here).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment