Cacti Network Monitoring Setup

Cacti is a complete network graphing solution designed to harness the power of RRDTool's data storage and graphing functionality. It provides a robust and extensible operational monitoring and fault management framework.

Prerequisites

  • Ubuntu Server 20.04 LTS or 22.04 LTS
  • Minimum 2GB RAM (4GB recommended for larger deployments)
  • 20GB+ of disk space
  • Root or sudo privileges
  • LAMP stack (Linux, Apache, MySQL/MariaDB, PHP)
  • Basic knowledge of Linux command line

1 System Update and Preparation

Start by updating your system packages to the latest versions:

sudo apt update && sudo apt upgrade -y
sudo apt install -y software-properties-common

Set the hostname for your monitoring server (optional but recommended):

sudo hostnamectl set-hostname cacti-monitor
exec bash

2 Install LAMP Stack

Install Apache web server, MySQL database, and PHP with required extensions:

sudo apt install -y apache2 mariadb-server mariadb-client \
php php-mysql php-ldap php-snmp php-gd php-xml php-mbstring \
php-json php-curl php-zip php-intl

Verify that Apache is running:

sudo systemctl status apache2

Secure your MySQL installation:

sudo mysql_secure_installation
Note: Follow the prompts to set a root password and secure your database installation.

3 Install Required Dependencies

Install SNMP and other required packages for Cacti:

sudo apt install -y snmp snmpd rrdtool librrds-perl \
help2man libssl-dev libmysqlclient-dev

Verify SNMP is working:

snmpwalk -v 2c -c public localhost .1.3.6.1.2.1.1.1.0

4 Install Cacti

Add the Cacti repository and install the package:

sudo add-apt-repository -y ppa:andreas-boettger/cacti
sudo apt update
sudo apt install -y cacti
Info: During installation, you'll be prompted to configure the database. Select your web server (apache2) and configure the database for Cacti.

If you encounter any issues with the PPA, you can install Cacti directly from the Ubuntu repositories:

sudo apt install -y cacti cacti-spine

5 Database Configuration

Log into MySQL and create a dedicated database for Cacti:

sudo mysql -u root -p

Within the MySQL prompt, execute these commands (replace 'password' with a strong password):

CREATE DATABASE cacti DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
GRANT ALL PRIVILEGES ON cacti.* TO 'cactiuser'@'localhost' IDENTIFIED BY 'your_strong_password';
FLUSH PRIVILEGES;
EXIT;

Import the Cacti database schema:

sudo mysql -u root -p cacti < /usr/share/doc/cacti/cacti.sql

6 Configure Cacti Database Connection

Edit the Cacti configuration file to set up the database connection:

sudo nano /etc/cacti/debian.php

Update the database configuration with your credentials:

$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "your_strong_password";
$database_port = "3306";
$database_ssl = false;
Warning: Make sure to use the actual password you set for the cactiuser database account.

7 Configure Apache for Cacti

Enable the Cacti site in Apache:

sudo a2ensite cacti
sudo systemctl reload apache2

Adjust PHP settings for Cacti:

sudo nano /etc/php/8.1/apache2/php.ini

Make sure these settings are configured (adjust the PHP version in the path as needed):

memory_limit = 512M
max_execution_time = 60
date.timezone = America/New_York  # Set to your timezone

Restart Apache to apply the changes:

sudo systemctl restart apache2

8 Configure Cacti Poller

Set up the Cacti poller cron job:

sudo nano /etc/cron.d/cacti

Ensure the poller is set to run every 5 minutes:

*/5 * * * * www-data php /usr/share/cacti/site/poller.php > /dev/null 2>&1

Install and configure Spine for better performance (optional but recommended):

sudo apt install -y cacti-spine
sudo nano /etc/spine.conf

Update the Spine configuration with your database credentials:

DB_Host localhost
DB_Database cacti
DB_User cactiuser
DB_Pass your_strong_password
DB_Port 3306

9 Complete Web Installation

Open your web browser and navigate to your Cacti installation:

http://your_server_ip/cacti

Follow the web-based installation wizard:

  1. Select "New Install"
  2. Verify all pre-installation checks pass
  3. Click "Next" through the license agreement
  4. Select "Linux" as the OS and "Local" as the database
  5. Verify the paths and click "Finish"
Note: The default login credentials are:
  • Username: admin
  • Password: admin
You will be forced to change the password on first login.

10 Basic Cacti Configuration

After logging in, configure the basic settings:

  1. Go to "Configuration" -> "Settings"
  2. Configure general settings (paths, polling interval, etc.)
  3. Set up email alerts under the "Mail/Reporting/DNS" tab
  4. Configure the "Poller" tab to use Spine if installed

Add your first device to monitor:

  1. Go to "Management" -> "Devices"
  2. Click "Add"
  3. Fill in the device details (description, hostname, etc.)
  4. Select the appropriate template (e.g., "Generic SNMP-enabled Host")
  5. Click "Create"

11 Create Graphs and Data Sources

For each device, create graphs to visualize performance data:

  1. Go to "Management" -> "Devices" and select your device
  2. Click "Create Graphs for this Host"
  3. Select the graph templates you want to use
  4. Click "Create"

Create a tree structure to organize your devices:

  1. Go to "Management" -> "Graph Trees"
  2. Click "Add" to create a new tree or edit the default tree
  3. Add devices to the tree structure

12 Advanced Configuration

Install additional plugins to extend Cacti's functionality:

cd /usr/share/cacti/site/plugins
sudo git clone https://github.com/Cacti/plugin_thold.git thold
sudo git clone https://github.com/Cacti/plugin_monitor.git monitor
sudo chown -R www-data:www-data /usr/share/cacti/site/plugins

Enable the plugins in the Cacti web interface:

  1. Go to "Configuration" -> "Plugin Management"
  2. Install the plugins by clicking the "Install" button
  3. Enable the plugins by toggling the status

Configure thresholds and alerts using the thold plugin.

13 Troubleshooting Common Issues

Check the Cacti log for errors:

tail -f /var/log/cacti/cacti.log

If graphs are not being created, check the poller:

sudo -u www-data php /usr/share/cacti/site/poller.php --force

Common issues and solutions:

Issue Solution
Graphs not displaying Check RRDtool permissions and paths
Poller not running Verify cron job is active and check permissions
SNMP timeouts Check SNMP configuration on target devices
Database connection errors Verify database credentials in config files

14 Maintenance and Updates

Backup your Cacti configuration and data:

# Backup database
mysqldump -u root -p cacti > cacti_backup_$(date +%Y%m%d).sql

# Backup configuration and RRD files
tar -czf cacti_files_backup_$(date +%Y%m%d).tar.gz /etc/cacti/* /var/lib/cacti/rra/*

Update Cacti when new versions are available:

sudo apt update
sudo apt upgrade cacti

Regularly clean up old data:

# Clean up old log files
sudo find /var/log/cacti -name "*.log" -mtime +30 -delete
Command copied to clipboard!