Installing the Cacti software

Installing the prerequisites

The net-analyzer/cacti package has several prerequisites which must be fulfilled before we can begin the installation process.

  1. A syslog daemon.

    We would recommend the syslog-ng daemon. If you require more information the System logging with syslog-ng guide may be of interest.

  2. A cron daemon.

    We would recommend the vixie-cron daemon. If you require more information the Scheduling tasks using Cron guide may be of interest.

  3. The sudo application.

    The Cacti poller should ideally not be run as the root user. The sudo application will allow us to execute the Cacti poller as the apache user, or any other user of your choice.

  4. A MySQL database server.

    The Cacti application stores its configuration and data in a MySQL database. If you require more information the Database server using MySQL guide may be of interest.

  5. An Apache web server with PHP integration.

    If you require more information the Web virtual-hosting system using Apache 2 guide may be of interest, especially the Integrating PHP with Apache section.

  6. An SNMP daemon (or internal SNMP support) running on the target hosts.

    If you require more information the Simple Network Management Protocol (SNMP) guide may be of interest.

Installing the Cacti packages

Before we install any packages we should ensure that the correct use-flags are specified so that all required functionality is made available and unnecessary functionality is not included. The net-analyzer/cacti package provides a variety of use-flags only some of which will be discussed further here. As usual feel free to add and remove use-flags at will although the minimum set which are required for using this guide in its entirety are shown below.

lisa emerge -pv cacti
 
These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild      ] x11-libs/pixman-0.22.0  USE="mmx sse2 -static-libs"
[ebuild      ] media-fonts/dejavu-2.32  USE="-X -fontforge"
[ebuild      ] dev-php/adodb-5.11
[ebuild      ] app-admin/webapp-config-1.50.16-r1
[ebuild      ] virtual/ttf-fonts-1
[ebuild      ] media-libs/fontconfig-2.8.0-r1  USE="-doc"
[ebuild      ] app-admin/eselect-fontconfig-1.0
[ebuild      ] x11-libs/cairo-1.10.2-r1  USE="glib svg -X -debug -directfb -doc -opengl -qt4 -static-libs -xcb"
[ebuild      ] x11-libs/pango-1.28.4  USE="introspection -X -debug -doc -test"
[ebuild      ] net-analyzer/rrdtool-1.3.8  USE="nls perl python -doc -rrdcgi -ruby -tcl"
[ebuild      ] net-analyzer/cacti-0.8.7g  USE="snmp vhosts -doc"

Once you are confident that the correct use-flags are set for the net-analyzer/cacti package, and any dependencies it may require, you can proceed with the installation by issuing the emerge command shown below.

lisa emerge cacti

Installing the Cacti web application

Now that we have installed the net-analyzer/cacti package we can install the Cacti web application into our web server using the webapp-config utility, as shown below. More information on using the webapp-config utility may be found in the Deploying web applications section of the Web virtual-hosting system using Apache 2 guide.

lisa webapp-config -I -h localhost -d cacti cacti 0.8.7g

Assuming that you have chosen to deploy web applications separately from the static content served by the virtual server instance, as recommended in the Web virtual-hosting system using Apache 2 guide, then you will need to alias the desired application path to the directory where the application was actually deployed, as shown in the example below.

/etc/apache2/vhosts.d/default_vhost.include
<Directory "/var/www/localhost/webapps/cacti">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

<IfModule alias_module>
Alias /cacti /var/www/localhost/webapps/cacti/
</IfModule>

As the Cacti web application will require the ability to write to the cacti/log directory to maintain a log of activity write access to this directory needs to be granted to the apache user. This can be easily accomplished using the chown utility, as shown below.

lisa chown apache:apache /var/www/localhost/webapps/cacti/log

Creating the Cacti database

Finally, to complete the installation of the Cacti application, we need to create a MySQL database which will be used to store the Cacti configuration and data received from the client devices.

The Cacti web application includes an SQL file which can be used to create a database with the correct structure using the administration utilities provided with MySQL. As you can see from the example below, the first step is to create a new database which will be used by the Cacti application and poller. Once the new, empty, database has been created it can then be populated with tables and any other required structures.

lisa mysqladmin -p --user=root create cacti
lisa mysql -p --user=root cacti < /var/www/localhost/webapps/cacti/cacti.sql

For security reasons, and to allow the end user more freedom in deployment, the database creation script provided by the net-analyzer/cacti package does not create any users or grant any access rights to the newly populated database. As the Cacti web application and poller will need read and write access to the database we will need to create a new user and grant them access using the mysql client application.

lisa mysql -p --user=root mysql

Once the mysql client has been started we can issue the SQL commands to create a new user and grant that user access to the database. As you can see from the example below a single command is used to create the new user and grant access. To ensure that the privileges take immediate effect it is also a good idea to issue the flush command.

mysql> GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'password'; 
Query OK, 0 rows affected (0.00 sec) 
mysql> flush privileges; 
Query OK, 0 rows affected (0.00 sec) 
mysql> quit; 
Bye 

Now that we have created a new database and granted a user the appropriate access we can configure the Cacti web application to use the correct database and access credentials. The example below demonstrates how this can be accomplished for the user we created above. Clearly, in a real installation you would want to use a more difficult to guess password.

/var/www/localhost/webapps/cacti/include/config.php
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "password";