Cacti is a powerful, open-source network monitoring and graphing tool that uses SNMP (Simple Network Management Protocol) to collect data from devices (routers, switches, servers, etc.) and RRDtool to generate visual graphs. It’s ideal for tracking metrics like bandwidth usage, CPU load, memory utilization, and more.
Rocky Linux and AlmaLinux—both RHEL (Red Hat Enterprise Linux) derivatives—are stable, secure, and enterprise-grade operating systems, making them perfect for hosting Cacti. This guide will walk you through installing Cacti on Rocky Linux 8/9 or AlmaLinux 8/9 with a detailed, step-by-step approach.
Table of Contents#
- Introduction
- Prerequisites
- Install LAMP Stack
- Configure MariaDB for Cacti
- Install Cacti Dependencies
- Download and Install Cacti
- Configure Apache for Cacti
- Complete Cacti Web Installation
- Set Up Cacti Poller Cron Job
- Configure SNMP for Monitoring
- Troubleshooting Common Issues
- Conclusion
- References
2. Prerequisites#
Before starting, ensure your system meets these requirements:
2.1 System Requirements#
- OS: Rocky Linux 8/9 or AlmaLinux 8/9 (64-bit)
- RAM: 2 GB minimum (4 GB recommended for large deployments)
- CPU: 2 cores minimum
- Storage: 10 GB minimum (more for historical data)
- Network: Static IP address (for consistent access)
2.2 Update Operating System#
Always start with an updated system to avoid compatibility issues:
sudo dnf update -y && sudo dnf upgrade -y2.3 Root or Sudo Access#
You’ll need sudo privileges to install packages and modify system settings.
3. Install LAMP Stack#
Cacti requires a LAMP stack (Linux, Apache, MariaDB, PHP) to run. Let’s install each component:
3.1 Install Apache Web Server#
Apache is the most popular web server for hosting Cacti:
sudo dnf install httpd -yStart and enable Apache to run on boot:
sudo systemctl start httpd
sudo systemctl enable httpdAllow Apache through the firewall (for web access):
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reloadVerify Apache is running:
sudo systemctl status httpdYou should see active (running) in the output.
3.2 Install MariaDB Database Server#
MariaDB (a fork of MySQL) stores Cacti’s configuration and historical data:
sudo dnf install mariadb-server -yStart and enable MariaDB:
sudo systemctl start mariadb
sudo systemctl enable mariadbVerify MariaDB is running:
sudo systemctl status mariadb3.3 Install PHP and Required Extensions#
Cacti requires PHP 7.4+ (for Rocky/Alma 8) or 8.0+ (for Rocky/Alma 9).
For Rocky Linux 8 / AlmaLinux 8#
The default PHP version (7.2) is too old—use the Remi repository to install PHP 7.4:
# Install Remi repository
sudo dnf install dnf-utils -y
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
# Enable PHP 7.4
sudo dnf module reset php -y
sudo dnf module enable php:7.4 -y
# Install PHP and extensions
sudo dnf install php php-gd php-xml php-mbstring php-json php-snmp php-mysqlnd php-cli php-process php-zip -yFor Rocky Linux 9 / AlmaLinux 9#
The default PHP version (8.0+) is compatible—install directly:
sudo dnf install php php-gd php-xml php-mbstring php-json php-snmp php-mysqlnd php-cli php-process php-zip -yRestart Apache to load PHP:
sudo systemctl restart httpdVerify PHP is installed:
php -vYou should see a version ≥7.4.
4. Configure MariaDB for Cacti#
Now we’ll set up a database and user for Cacti, and import critical time zone data.
4.1 Secure MariaDB Installation#
Run the mysql_secure_installation script to harden MariaDB:
sudo mysql_secure_installationFollow the prompts:
- Set root password: Enter a strong password (e.g.,
MySecurePass123!). - Remove anonymous users: Type
Y. - Disallow remote root login: Type
Y. - Remove test database: Type
Y. - Reload privilege tables: Type
Y.
4.2 Create Cacti Database and User#
Log into MariaDB as root:
mysql -u root -pEnter your MariaDB root password when prompted.
Create a database for Cacti:
CREATE DATABASE cacti DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;Create a user with full access to the Cacti database:
CREATE USER 'cactiuser'@'localhost' IDENTIFIED BY 'StrongPassword123!';Grant privileges to the user:
GRANT ALL PRIVILEGES ON cacti.* TO 'cactiuser'@'localhost';Flush privileges to apply changes:
FLUSH PRIVILEGES;4.3 Import Time Zone Tables (Critical!)#
Cacti requires MariaDB’s time zone tables to handle graphing correctly. Import them using:
sudo mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysqlEnter your MariaDB root password when prompted.
Next, grant the Cacti user access to the time zone tables:
mysql -u root -pRun these SQL commands:
GRANT SELECT ON mysql.time_zone_name TO 'cactiuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;4.4 Import Cacti Database Schema#
We’ll import Cacti’s default database schema later—first, we need to download Cacti (Step 6).
5. Install Cacti Dependencies#
Cacti relies on SNMP (for data collection) and RRDtool (for graphing). Install them:
sudo dnf install net-snmp net-snmp-utils rrdtool -y6. Download and Install Cacti#
Download the latest stable version of Cacti from the official website:
wget https://www.cacti.net/downloads/cacti-latest.tar.gzExtract the tarball:
tar xzf cacti-latest.tar.gzMove the Cacti directory to Apache’s web root (/var/www/html):
sudo mv cacti-*/ /var/www/html/cactiVerify the files are in place:
ls /var/www/html/cacti7. Configure Apache for Cacti#
7.1 Set File Permissions#
Apache needs write access to Cacti’s files. Set the owner to the apache user:
sudo chown -R apache:apache /var/www/html/cacti7.2 Adjust SELinux Policies#
SELinux (Security-Enhanced Linux) is enabled by default on Rocky/Alma. It restricts Apache’s access to files—fix this with:
-
Set SELinux context for Cacti’s files:
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti(/.*)?" sudo restorecon -Rv /var/www/html/cacti -
Allow Apache to connect to MariaDB:
sudo setsebool -P httpd_can_network_connect_db 1
7.3 Configure PHP Settings#
Cacti requires specific PHP settings (memory limit, execution time, time zone). Edit the php.ini file:
For Rocky/Alma 8 (PHP 7.4)#
sudo nano /etc/php/7.4/apache2/php.iniFor Rocky/Alma 9 (PHP 8.0+)#
sudo nano /etc/php/8.0/apache2/php.iniModify these values (replace America/New_York with your time zone):
memory_limit = 512M
max_execution_time = 300
date.timezone = America/New_YorkSave and exit (Ctrl+O, Ctrl+X).
Restart Apache to apply changes:
sudo systemctl restart httpd8. Complete Cacti Web Installation#
Now access the Cacti web installer to finalize setup.
-
Open a browser and navigate to:
http://your-server-ip/cactiReplace
your-server-ipwith your server’s static IP (e.g.,192.168.1.100). -
Welcome Screen: Click Next.
-
License Agreement: Accept the GPL license and click Next.
-
Prerequisites Check: Verify all requirements are met (green checkmarks). Click Next.
-
Database Settings:
- Database Type:
MySQL - Database Name:
cacti - Database Username:
cactiuser - Database Password: The password you set for
cactiuser(e.g.,StrongPassword123!)
Click Next.
- Database Type:
-
Template Setup: Select Default Templates (for most users) and click Next.
-
Install Preview: Review the settings and click Install.
-
Post-Install:
- The installer will create tables and configure Cacti.
- When done, click Get Started.
-
Login: Use the default credentials:
- Username:
admin - Password:
admin
IMPORTANT: Change the admin password immediately after logging in!
- Username:
9. Set Up Cacti Poller Cron Job#
Cacti uses a poller to collect data every 5 minutes. Set up a cron job for the apache user:
Open the cron editor:
sudo crontab -u apache -eAdd this line (runs the poller every 5 minutes):
*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1Save and exit (Ctrl+O, Ctrl+X).
Verify the cron job is set:
sudo crontab -u apache -l10. Configure SNMP for Monitoring#
To monitor devices, you need to enable SNMP on them. Let’s start with your Cacti server (to monitor itself):
10.1 Enable SNMP on the Cacti Server#
Edit the SNMP configuration file:
sudo nano /etc/snmp/snmpd.confFind the line starting with com2sec and change the community string (e.g., from public to MySNMPCommunity):
com2sec notConfigUser default MySNMPCommunitySave and exit.
Restart SNMP and enable it on boot:
sudo systemctl restart snmpd
sudo systemctl enable snmpdAllow SNMP through the firewall (UDP port 161):
sudo firewall-cmd --permanent --add-port=161/udp
sudo firewall-cmd --reload10.2 Add a Device to Cacti#
Now add your server to Cacti for monitoring:
- Log into Cacti.
- Go to Console > Devices > Add.
- Device Settings:
- Device Name: Your server’s name (e.g.,
Cacti-Server) - IP Address:
127.0.0.1(localhost) - SNMP Version:
SNMPv2 - SNMP Community: The string you set (e.g.,
MySNMPCommunity)
- Device Name: Your server’s name (e.g.,
- Click Create.
Cacti will automatically discover metrics (CPU, memory, disk) and generate graphs. Wait 5–10 minutes for the first graphs to appear.
11. Troubleshooting Common Issues#
11.1 Database Connection Error#
- Cause: Incorrect credentials in
config.php. - Fix: Edit
/var/www/html/cacti/include/config.phpand verify:$database_username = 'cactiuser'; $database_password = 'StrongPassword123!'; $database_name = 'cacti';
11.2 No Graphs Appearing#
- Cause: Cron job not running, or RRDtool path incorrect.
- Fix:
- Verify the cron job:
sudo crontab -u apache -l. - Check RRDtool path in Cacti: Console > Settings > Paths (should be
/usr/bin/rrdtool).
- Verify the cron job:
11.3 SNMP Timeout#
- Cause: Firewall blocking UDP port 161, or incorrect community string.
- Fix:
- Test SNMP from the Cacti server:
snmpwalk -v2c -c MySNMPCommunity localhost system. - Ensure the remote device’s firewall allows UDP 161.
- Test SNMP from the Cacti server:
11.4 SELinux Permission Denied#
- Cause: Incorrect SELinux context on Cacti files.
- Fix: Reapply SELinux policies:
sudo restorecon -Rv /var/www/html/cacti
12. Conclusion#
You’ve successfully installed Cacti on Rocky Linux or AlmaLinux! Now you can:
- Add remote devices (routers, switches, servers) for monitoring.
- Customize graphs and templates.
- Set up alerts (using plugins like Thold).
Cacti is a robust tool—take time to explore its features and tailor it to your needs.
13. References#
- Cacti Official Documentation
- Rocky Linux Documentation
- AlmaLinux Documentation
- Remi Repository
- Net-SNMP Documentation
- RRDtool Documentation
Let me know if you have any questions—happy monitoring! 📊