8 min read

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:

    Cacti 0.8 Beginner’s Guide

  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:

    Cacti 0.8 Beginner’s Guide

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.

  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 root@localhost = 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:

    Cacti 0.8 Beginner’s Guide

  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 cactiuser@localhost 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

    Cacti 0.8 Beginner’s Guide

  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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here