Cacti 0.8 Beginner's Guide

3 (2 reviews total)
By Thomas Urban
  • Instant online access to over 7,500+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. Installing Cacti

About this book

Cacti is a performance measurement tool that provides easy methods and functions for gathering and graphing system data. You can use Cacti to develop a robust event management system that can alert on just about anything you would like it to. But to do that, you need to gain a solid understanding of the basics of Cacti, its plugin architecture, and automation concepts.

Cacti 0.8 Beginner's Guide will introduce you to the wide variety of features of Cacti and will guide you on how to use them for maximum effectiveness. Advanced topics like the plugin architecture and Cacti automation using the command-line interface will help you build a professional performance measurement system.

Designed as a beginner's guide, the book starts off with the basics of installing and using Cacti, and also covers the advanced topics that will show you how to customize and extend the core Cacti functionalities. The book offers essential tutorials for creating advanced graphs and using plugins to create enterprise-class reports to show your customers and colleagues.

From data templates to input methods and plugin installation to creating your own customized plugins, this book provides you with a rich selection of step-by-step instructions to reach your goals. It covers all you need to know to implement professional performance measurement techniques with Cacti and ways to fully customize Cacti to fit your needs.

By the end of the book, you will be able to implement and extend Cacti to monitor, display, and report the performance of your network exactly the way you want.

Publication date:
March 2011
Publisher
Packt
Pages
348
ISBN
9781849513920

 

Chapter 1. Installing Cacti

Let's get right on with setting up Cacti. Take a look at what we will do next.

In this chapter, we are going to:

  • Install Cacti's prerequisites

  • Install Cacti on both a CentOS and a Windows system

  • Compile and install the spine poller

  • Upgrade an existing Cacti installation

  • Run Cacti for the first time

  • Provide a quick overview on the Cacti web frontend

Here we go….

 

Preparing the system—basic prerequisites


In order to install and run Cacti, we need to make sure that all system prerequisites are met. Here we'll give an overview of the different components needed.

Web server

As most of Cacti is built as a web interface, a web server is needed. This can be Apache's httpd or Microsoft's Internet Information Server (IIS) if installing on Windows, but in fact, any PHP-capable web server can be used to run the web interface. For optimal support, the use of Apache or IIS is suggested.

PHP

Cacti is built with the PHP programming language and therefore needs PHP to be installed on the system. Most Linux distributions already have a base PHP environment installed, but some might need additional packages for Cacti to function properly. In particular, the LDAP, SNMP, and MySQL extensions should be installed.

MySQL database

Cacti uses the freely available MySQL database engine as its database server and it is available on most operating systems. One should note that the database server does not need to be installed on the same host as Cacti. For best performance, MySQL version 5 should be used.

NET-SNMP package

The NET-SNMP package provides the SNMP binaries used by Cacti and supports SNMPv1, SNMPv2c, and SNMPv3.

The NET-SNMP package also provides the SNMP daemon for Linux.

 

Installing Cacti on a CentOS 5 system


You're now going to install Cacti from source on a CentOS 5 system. You should use at least Centos 5.5 as it is 100% binary compatible with RedHat Enterprise Linux 5, but in fact you can follow most of the installation processes on other Linux distributions, such as Ubuntu or SuSe Linux, as well. By installing from source you'll get some insight into the inner workings of Cacti, and it will also provide you with a system which most Cacti and plugin developers are used to. There are differences between a source installation and a Yum/APT installation, but they will be described later on. Let's get started.

Preparing the system

Assume that the CentOS system has been installed with only the "Server Package" selected and there is no graphical user interface installed.

This is the default installation for a CentOS system with no manual package selection.

 

Time for action – installing the missing packages


The default CentOS installation is missing several important packages. So, we are now going to install these.

  1. Install the RPMForge repository. For a 32bit CentOS installation this can be achieved by executing the following command (all on one line):

    rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
    
  2. The RPMForge repository includes an RRDtool version for CentOS.

  3. Issue the following command to install all required packages:

    yum install mysql-server php-mysql net-snmp-utils rrdtool php-snmp
    

What just happened?

You just gave the system a location to find the remaining packages needed for the Cacti installation and then installed them; therefore, you are now ready to start the next installation phase.

Downloading and extracting Cacti

Go to http://www.cacti.net and download the latest version of Cacti. In the top-left corner, under Latest Files, right-click on the tar.gz file and save the link address to the clipboard. You are going to need this link later. For simplicity we're assuming that your server has an Internet connection.

 

Time for action – downloading Cacti


It's now time to download the latest version of Cacti to your server. You will need your system username and password to login to your CentOS installation. If you have installed your CentOS system with the default settings, you should already have an SSH server running. If you're already logged on to the machine, you can ignore the first step.

  1. From a Windows machine, logon to your system using an SSH client such as Putty. If this is the first time you have connected to the server, Putty will display a security alert and ask you to accept the RSA key. By doing so, Putty will display the logon prompt where you can logon to the system.

  2. Maximize the window, so that long text lines do not break at the end of the line. This will make things easier.

  3. You'll need to become the root user in order to be able to setup Cacti properly. Should that not be an option, performing these steps with sudo should achieve the same results.

  4. Navigate to /var/www/html. This is the document root for Apache.

  5. To download Cacti you can use the wget command. Enter the following command to download Cacti. After entering the wget command, right-clicking into the window client using Putty will paste the URL you copied earlier after the command:

    wget http://www.cacti.net/downloads/cacti-0.8.7g.tar.gz
    

    You should see the following output on your screen:

  6. You now have the tar.gz file on your system, so let's move on and extract it. To do this, enter the following command:

    tar-xzvf cacti-0.8.7g.tar.gz
    
  7. This will extract the files and directories contained in the archive to the current directory.

  8. Finally you are going to create a symbolic link to this new Cacti directory. This will allow you to easily switch between different Cacti versions later, for example, when upgrading Cacti. To create a symbolic link, enter the following command:

    ln –s cacti-0.8.7g cacti
    
  9. This will create a link named cacti which points to the cacti-0.8.7g directory:

What just happened?

You downloaded the latest Cacti version to the root directory of the web server and created a symbolic link to the extracted directory. With the Cacti files in place, you are now ready for the next phase of the installation process.

Creating the database

The database isn't automatically created during the installation of Cacti. Therefore, you need to create it here. At the same time, a database user for Cacti should be created to allow it to access the database. It's also a good idea to secure the MySQL database server by using one of the included CentOS tools.

 

Time for action – creating the database


To keep it simple let's assume that you're going to host the database on the same server as Cacti.

  1. Execute the following command to logon to the MySQL CLI:

    mysql –u root mysql
    
  2. The default MySQL root account does not have a password set, so you can set one as follows:

    SET PASSWORD FOR [email protected] = PASSWORD('MyN3wpassw0rd');
    
  3. You can now also remove the example database, as it is not needed:

    DROP DATABASE test;
    
  4. Together with the example database, some example users may have been created. You can remove these with the following command:

    DELETE FROM user WHERE NOT (host = "localhost" AND user = "mydbadmin");
    
  5. On a CentOS distribution you can use the following command to guide you through the above steps:

    /usr/bin/mysql_secure_installation
    
  6. Now that MySQL is secured, let's create the Cacti database. Enter the following command:

    mysqladmin -u root -p create cacti
    

    This will ask for the MySQL root password which you provided in Setup Step 1. When finished, you will have an empty database called cacti .

  7. As the database is still empty, you need to create the tables and fill it with the initial data that comes with Cacti. The following command will do just that:

    mysql -p cacti < /var/www/html/cacti/cacti.sql
    
  8. Again it will ask for the MySQL root password. Once the command finishes you'll have a working Cacti database. Unfortunately Cacti is still unable to access it, therefore you are now going to create a database user for Cacti.

  9. Enter the following command:

    mysql -u root -p mysql
    
  10. You'll see the following on the screen:

  11. Type the next few lines in the MySQL prompt to create the user. Make sure to choose a strong password:

    GRANT ALL ON cacti.* TO [email protected] IDENTIFIED BY 'MyV3ryStr0ngPassword'; flush privileges; exit
    

What just happened?

You used some tools to secure the MySQL server and created a database. You also filled the Cacti database with the initial data and created a MySQL user for Cacti. However, Cacti still needs to know how to access the database, so let's move on to the next step.

In case you are not using CentOS to install Cacti, you can use some MySQL internal functions to secure your installation.

Configuring Cacti

You need to tell Cacti where to find the database and which credentials it should use to access it. This is done by editing the config.php file in the include directory.

 

Time for action – configuring Cacti


The database and some other special configuration tasks are done by editing the information in the config.php file.

  1. Navigate to the cacti directory:

    cd /var/www/html/cacti/include
    
  2. Edit config.php with vi:

    vi config.php
    
  3. Change the $database_username and $database_password fields to the previously created username and password.

  4. Change the line $config['url_path'] = '/' to $config['url_path'] = '/cacti/'

What just happened?

You changed the database configuration for Cacti to the username and password that you created earlier. These settings will tell Cacti where to find the database and what credentials it needs to use to connect to it. You also changed the default URL path to fit your installation. As you install Cacti to /var/www/html/cacti, a sub-directory of the document root, you need to change this setting to /cacti/, otherwise Cacti will not work correctly.

Creating the poller cron entry and Cacti's system user

For the poller to work correctly, Cacti needs a system user account. You are going to create one now and also set up the poller's cron entry.

 

Time for action – creating the poller's cron entry and Cacti's system account


  1. To create a Cacti system user called cactiuser, issue the following command as root:

    adduser cactiuser
    
  2. Navigate to the cacti directory:

    cd /var/www/html/cacti
    
  3. Change the ownership of the rra and log directory to the newly created user:

    chown –R cactiuser rra/ log/
    
  4. Add the poller cron entry. Edit the file cacti in /etc/cron.d:

    vi /etc/cron.d/cacti
    
  5. Add the following line to the file:

    */5 * * * * cactiuser /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1
    
  6. Save the file.

What just happened?

You just created a system user which runs the Cacti poller and scheduled the poller to run every 5 minutes. Five minutes is the default interval, but it can be changed to 1 minute if needed. For more information on how to do so, go the following post in the Cacti forums: http://forums.cacti.net/viewtopic.php?p=116403.

Installing the Spine poller

By default, Cacti comes with a poller written in PHP. For small-to-medium installations, this poller does its job just fine, but for larger installations, an alternative poller, spine, needs to be used. It is written in C and is much faster than the original poller, as it makes use of the multi-tasking capabilities of modern operating systems and hardware.

Here we will deep-dive into installing and configuring the spine poller.

 

Time for action – installing Spine


  1. You now need to prepare the development environment for Spine. On CentOS you can do this by issuing the following command:

    yum install gcc mysql-devel net-snmp-devel autoconf automake libtool
    
  2. Download the spine source code. For this, go to http://www.cacti.net and click on Download under the Spine (Cactid) section. Right-click on Spine Source in the tar.gz format and copy the link address.

  3. Navigate to /tmp/ and issue the following command:

    wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.7g.tar.gz
    
  4. Extract the file:

    tar –xzvf cacti-spine-0.8.7g.tar.gz
    
  5. Navigate to the newly created cacti-spine-0.8.7g directory.

  6. Prepare the directory for compilation. Please note that this step may not work on other distributions, or additional steps need to be taken to accomplish it:

    ./bootstrap
    
  7. Configure the compiling environment:

    ./configure
    
  8. Compile Spine:

    make
    
  9. Once the make command finishes, install Spine:

    make install
    
  10. You now have Spine installed, but it needs to be configured. Therefore, copy the sample configuration file to a location where Spine will find it:

    cp /usr/local/spine/etc/spine.conf.dist /etc/spine.conf
    
  11. Edit the file in vi:

    vi /etc/spine.conf
    
  12. Change the database configuration to match the settings from earlier.

  13. Create a symbolic link in /sbin to the spine binary:

    ln -s /usr/local/spine/bin/spine /sbin/spine
    

What just happened?

You just set up a basic development environment for compiling Spine, compiled it, and then installed it. You also configured Spine to use the correct database information.

Tip

Compiling Spine on other Linux distributions

When compiling Spine on other Linux distributions such as Ubuntu, you will have to go through some additional steps. Look at the following URL for more information on how to do so:

http://docs.cacti.net/manual:087:1_installation.1_install_unix.6_install_and_configure_spine.

Differences between source and APT/Yum installations

The main difference between installing Cacti from source and using APT/Yum-based installations is the location of configuration files and availability of patches. Cacti, by default, does not follow the Filesystem Hierarchy Standard (FHS) defined for the Linux operating systems. The FHS defines directories where applications should add their configuration or log files. APT/Yum-based installations usually follow this standard. Due to this, add-ons such as the Plugin Architecture may not be available on all platforms using APT/Yum.

The main advantage of using APT/Yum-based installations is the ease of installation but as we've just seen, installing Cacti isn't very difficult.

However, the disadvantage of using APT or Yum is the availability of newer Cacti versions. Source-based Cacti installations can be upgraded to the latest version as soon as it is available on the Cacti website, while APT/Yum-based installations might need to wait until the package maintainers update their repositories.

Have a go hero – remote server for database hosting

Here is a little challenge for you. It's not difficult but it will allow you to alter the installation to suit your needs. What if you want to use a remote database server? Maybe you want to use an existing dedicated MySQL server, instead of hosting the database on the same system as Cacti, or you want to separate the roles to allow more growth. Can you figure out what to change?

Solution: Create the MySQL database on the remote system using the same command as if you were installing it locally, but this time use the -h <hostname> option to specify the remote server. When creating the user and granting it permissions, use the following command, assuming the Cacti server has the IP '192.168.0.10':

GRANT ALL ON cacti.* TO [email protected]'192.168.0.10' IDENTIFIED BY 'MyV3ryStr0ngPassword'; 
flush privileges; 
exit

This will allow the Cacti user access to the database from the Cacti server. Now change $database_hostname in config.php and DB_Host in spine.conf on the Cacti server to point to your remote database server.

 

Installing Cacti on a Windows system


The installation of Cacti on a Windows system is quite different from Linux. Most of the prerequisites that are already available on a Linux platform need to be installed on a Windows system. The MySQL database is an example of such a prerequisite. In the following sections you can find more information about the Windows installation and how you can overcome most of the manual installation procedures by making use of the community-built Windows Installer.

The community-built Windows Installer

Instead of installing every prerequisite individually, the community-built Windows Installer provides a convenient way of installing them together with Cacti.

 

Time for action – starting the Windows setup


  1. Download the Windows Installer to the system on which you want to install Cacti. To retrieve the latest version, go to http://forums.cacti.net/viewtopic.php?t=14946 and click on the download link at the end of the first post. Save the installer to your desktop.

  2. Double-click on the setup file. The installer will check what has already been installed and give you a report. Click Next > after you have read the information.

  3. The next screen shows the GPL license. Accept it and click on Next >.

  4. Next comes the selection of the web server to be used. If you have IIS installed, you can select it here, otherwise Apache will be installed.

  5. In the next step you can choose the components to install. For now, you will only install the Cacti Core Files, so click on Next > without adding any additional components.

  6. Keep the defaults for the installation locations and click on Next >.

  7. The final step provides an overview of the paths to be created. Click on Install to start the installation process.

  8. Please note the default Cacti admin and MySQL root passwords.

  9. Open the Post-Install Instructions and follow the tasks.

What just happened?

You installed Cacti on Windows along with all the prerequisites.

Installing the Spine poller under Windows

Unlike Linux, where compilation from source is the preferred method, Cacti has pre-compiled binaries for Windows. You can download the latest versions from http://www.cacti.net. Click on Download under the Spine (Cactid) section and download the latest Windows binary from there. Extract the archive to the computer running Cacti and edit spine.conf to fit your database settings. In case you want to compile spine yourself, you will have to install a working copy of Cygwin. The following URL will provide you with some information on how to compile Spine using Cygwin:

http://www.cacti.net/spine_install_wincyg.php.

 

Upgrading Cacti


Upgrading Cacti involves several steps, one of which is backing up the database. As you have created a symbolic link to the Cacti directory, you don't need to back up any files, but instead you can copy or move them from the old version over to the new one.

 

Time for action – upgrading Cacti


  1. Create a backup of the database:

    mysqldump –u root -p --lock-tables --add-drop-table cacti > /root/cacti_backup.sql
    
  2. This will back up the Cacti database to a file called cacti_backup.sql. You will be asked for the MySQL root password.

  3. Change to the /var/www/html directory. From http://www.cacti.net download the source of the version to which you want to upgrade.

  4. Extract the file:

    tar –xzvf cacti-0.8.7g.tar.gz
    
  5. You will have a new directory named cacti-0.8.7g.

  6. Change to the newly created directory and edit include/config.php. Change the database entries in there to match your installation.

  7. Before copying the files, you should stop the poller using the web interface. Go to the Configuration | Settings and change to the Poller tab. Disable the poller by unchecking it.

  8. Copy the files from your existing installation to the new one. Execute the following commands, replacing 0.8.x with the new version:

    cp /var/www/html/cacti/rra/* /var/www/html/cacti-0.8.x/rra/
    cp –u /var/www/html/cacti/scripts/* /var/www/html/cacti-0.8.x/scripts/
    cp –u –R /var/www/html/cacti/resource/* /var/www/html/cacti-0.8.x/resource/
    
  9. Set the permissions on the log and rra folders:

    cd /var/www/html/cacti-0.8.7g/
    chown –R cactiuser log/ rra/
    
  10. Change the symbolic link so that it points to the new directory:

    cd /var/www/html/
    ln –fs cacti-0.8.x cacti
    
  11. The final upgrade process is done using the web interface. Point your browser to http://<yourserver>/cacti/install and follow the steps. Make sure you select Upgrade on the second page.

  12. You can now enable the poller again using the Cacti web interface.

  13. Once you have made sure that everything is working fine, you can remove or archive the original Cacti directory.

What just happened?

You upgraded Cacti to a newer version. As a safety net, you created a backup of the database so you can revert back to the old version in case of an error. You copied the RRD files and other resources to the new installation and switched over by changing the symbolic link to point to the new location. You finished the upgrade process by going to the install URL which provided the final web-based upgrade process.

 

Using Cacti for the first time


After the installation of the database and files, there are still several additional configuration tasks left. For these tasks you are going to use the web interface provided with Cacti to guide you through the final part of the setup. The following steps are almost identical for Windows and Linux.

 

Time for action – configuring Cacti


  1. Go to the installation URL http://<yourserver>/cacti/install. Read the license agreement and click on Next >>.

  2. The next page asks if you are installing a new system, or upgrading an existing one. Choose New Install then click on Next >>.

  3. The last page provides an overview of all required binaries and paths. If you have followed the installation steps correctly, all fields should be green:

  4. Click on Finish and you should be redirected to the Cacti login screen.

What just happened?

You finalized your Cacti installation by running the included web-based installer. If you have been following the instructions correctly, you will now have a working Cacti installation.

The installation will leave you with the default cmd.php poller. If you want to use Spine, you will now have to logon to the Cacti web interface and set the Spine Poller File Path in the Paths section of the Settings page. You also have to change the Poller Type to Spine in the Poller section.

 

The Cacti web interface explained


The first time you login, use the username admin and password admin (for Linux) or cactipw (for Windows). You will be forced to change the admin password but, after doing so, you will be presented with the Cacti web interface:

The initial page is called the Console and only administrators and users with special access rights are able to see it. From here you can fully administer Cacti.

The Console tab

The Console tab is where you manage your Cacti installation. From here you can add devices and users or create graphs and assign them to a tree. We're going to explain each of the menu sections next.

Create section

The Create section provides an easy access for new graph creations for specific devices. It's a shortcut to the Create Graphs link within each device.

Management section

The Management section, as its name suggests, allows the management of graphs, devices, data sources, and graph trees. Within this section you can add/edit or delete devices, delete graphs, add devices to trees, and much more.

Collection methods section

The Collection Methods section describes the different ways in which Cacti retrieves data from devices or systems. Here you can manage data queries such as SNMP retrieve methods, or manage the different input methods which are used by external scripts called from the poller.

Templates section

The Templates section provides an easy way of combining data templates into a graph (graph templates), graphs, and data queries for a specific type of host (host templates), or different data source items (data templates). Many graph, data, and host templates are available on the Cacti forums.

Import/export section

The Import/Export section allows the import and export of templates. This is especially useful for providing templates of exotic devices to the Cacti community, or to import them from one of the many provided on the Cacti forum.

Cacti doesn't yet provide a method for importing or exporting other data (for example, device lists) from within the web interface.

Configuration section

Within the Configuration section we can change the settings of Cacti. These settings include:

  • General settings (for example, logging levels)

  • Paths settings (similar to the paths page from the installer)

  • Poller settings (number of threads, or poller type to use)

  • Graph export settings (graphs can be exported to a local path or remote FTP server)

  • Visual settings (size of the graphs, font size to use)

  • Authentication settings (local authentication, LDAP, or HTTP Basic)

Utilities section

The Utilities section provides access to some basic system tools such as log or poller cache management and also hosts the user management interface.

The Graphs tab

The Graphs tab is the main screen for end users. Here they can view the graphs for their devices and systems and also change some personal settings:

The Graphs tab contains a hierarchical tree to the left containing all of the devices which a user is allowed to view. The main part of the page contains the graphs and a filtering system which can be used to customize the timeframe or to search for specific graphs.

 

Before we continue


You now have a rough overview of the Cacti web interface and how it interacts with the database. You're going to dive a bit deeper into the details in the next few chapters so it is not important at this stage to know in detail where everything is or how it works.

Pop quiz – a few questions about Chapter 1

  1. If you are using a remote database server, which configuration files do you need to change?

    a. The config.php file and spine.conf

    b. The global.php file and config.php

    c. The global.php file only

  2. Which section on the Console tab allows you to change the path to the Cacti log file?

    a. The System Utilities section

    b. The Path tab within the Configuration Section

    c. The General tab within the Configuration Section

  3. On a CentOS system, how can you configure the MySQL server to start automatically during system startup?

    a. You can use the enableservice command

    b. The setstartup command allows you to do so

    c. You can use the chkconfig command

 

Summary


You learned a lot in this chapter about installing Cacti.

We covered:

  • Obtaining and installing Cacti—where to download it and how to set up the files

  • MySQL database setup—how to create a database and fill it with the base Cacti data

  • Configuring Cacti—how to tell Cacti where to find its database and how to access it

  • Configuring the system components—how to add a Cacti system user and create the poller's cron entry

  • Spine poller—how to download, compile, and install the spine poller

  • Upgrading Cacti—how to upgrade an existing Cacti installation

  • The Cacti web interface—a brief look at the different sections of the web interface

You're now ready to create your first few devices and graphs. In the next chapter, you're going to create your own graphs using the RRDtool as well as add your first devices to Cacti.

About the Author

  • Thomas Urban

    Thomas Urban is the owner of Urban-Software.de, a software and consulting services company providing add-ons, plugins, and services for the Cacti Performance Monitoring systems. He has been in the consulting business for more than 5 years and has been creating web applications for over 20 years building reporting interfaces, network management software, asset management sites, and much more.

    He is a part of the Cacti community and is known as Phalek in the Cacti forums, where he is among the Top 10 contributors.

    He started writing the first Cacti Beginner’s Guide for Cacti 0.8 back in 2011. The second edition is his second official effort.

    Browse publications by this author

Latest Reviews

(2 reviews total)
Not just a rehash of help postings from other sites! Real detail that worked as advertised.
Examples are incomplete. Don't have sufficient understanding of what's going on to intuit your way through their logic leaps. Numerous noticable typos in examples.
Book Title
Unlock this full book FREE 10 day trial
Start Free Trial