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
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
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;
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:
- Select "New Install"
- Verify all pre-installation checks pass
- Click "Next" through the license agreement
- Select "Linux" as the OS and "Local" as the database
- Verify the paths and click "Finish"
- Username:
admin
- Password:
admin
10 Basic Cacti Configuration
After logging in, configure the basic settings:
- Go to "Configuration" -> "Settings"
- Configure general settings (paths, polling interval, etc.)
- Set up email alerts under the "Mail/Reporting/DNS" tab
- Configure the "Poller" tab to use Spine if installed
Add your first device to monitor:
- Go to "Management" -> "Devices"
- Click "Add"
- Fill in the device details (description, hostname, etc.)
- Select the appropriate template (e.g., "Generic SNMP-enabled Host")
- Click "Create"
11 Create Graphs and Data Sources
For each device, create graphs to visualize performance data:
- Go to "Management" -> "Devices" and select your device
- Click "Create Graphs for this Host"
- Select the graph templates you want to use
- Click "Create"
Create a tree structure to organize your devices:
- Go to "Management" -> "Graph Trees"
- Click "Add" to create a new tree or edit the default tree
- 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:
- Go to "Configuration" -> "Plugin Management"
- Install the plugins by clicking the "Install" button
- 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