Linux MintUbuntu Based

How To Install Cacti on Linux Mint 22

Install Cacti on Linux Mint 22

Cacti stands as one of the most powerful open-source network monitoring and graphing tools available for Linux systems today. Built upon the reliable RRDtool (Round Robin Database), Cacti transforms complex network data into visually appealing graphs that help system administrators track performance metrics in real-time. With robust SNMP (Simple Network Management Protocol) support, you can monitor virtually any network-connected device—from routers and switches to servers and workstations.

For Linux Mint 22 users seeking comprehensive network monitoring, Cacti offers an excellent solution with its flexible templating system and extensive customization options. Whether managing a small home network or enterprise infrastructure, Cacti provides the visibility needed to identify bottlenecks, plan capacity, and troubleshoot issues before they impact users.

This guide walks you through the complete process of installing Cacti on Linux Mint 22, from preparing your system to creating your first monitoring graphs.

Understanding Cacti and Its Components

Cacti functions as a complete frontend to RRDtool, handling the complex tasks of data collection, storage, and presentation through an intuitive web interface. At its core, Cacti operates on a polling mechanism that regularly collects data points from monitored devices, stores this information in round-robin databases, and generates graphical representations of the collected metrics.

The architecture of Cacti consists of several key components working together:

  • The Poller executes at regular intervals (typically every 5 minutes) to gather data from monitored devices using protocols like SNMP
  • Templates provide reusable configurations for graphs, data sources, and devices to streamline monitoring setup
  • Data Sources define what information is collected and how it’s processed
  • Graphs visualize the collected data with customizable parameters like timeframes and thresholds

What sets Cacti apart from other monitoring solutions is its balance of power and accessibility. While tools like Nagios offer more comprehensive alerting, and Zabbix provides broader monitoring capabilities, Cacti excels in creating detailed, historical graphs that make trend analysis intuitive. Its templating system allows you to quickly deploy standardized monitoring across numerous devices, making it particularly well-suited for Linux Mint environments where consistency is valued.

Prerequisites and System Requirements

Before beginning your Cacti installation on Linux Mint 22, ensure your system meets the following requirements for optimal performance:

Hardware Recommendations:

  • CPU: Dual-core processor (quad-core recommended for monitoring 100+ devices)
  • RAM: Minimum 2GB (4GB+ recommended for production environments)
  • Storage: At least 20GB available disk space (SSD recommended for better performance)
  • Network: Stable network connection with access to monitored devices

Software Requirements:

  • Linux Mint 22 with up-to-date packages
  • LAMP stack components:
    • Apache 2.4 or newer
    • MySQL 5.7/MariaDB 10.3 or newer
    • PHP 7.4 or newer (PHP 8.x supported and recommended)
  • Additional dependencies:
    • SNMP and SNMP development libraries
    • RRDtool (version 1.5 or later)
    • PHP extensions (mysql, snmp, xml, ldap, gd)

User Permissions:

You’ll need sudo or root access to install packages and modify system configurations. For production environments, consider creating a dedicated user for running Cacti processes with restricted permissions.

Meeting these prerequisites ensures a smooth installation process and helps prevent common performance issues that might arise when running Cacti with insufficient resources.

Preparing Your Linux Mint 22 System

Begin by updating your Linux Mint 22 system to ensure all packages are current:

sudo apt update
sudo apt upgrade -y

Setting the correct timezone is crucial for accurate time-based graphs and scheduling:

timedatectl status
sudo timedatectl set-timezone Region/City

Replace “Region/City” with your actual timezone (e.g., “Asia/Jakarta” or “Europe/London”).

Next, perform a quick system resource check:

# Check available disk space
df -h

# Verify RAM
free -m

# View CPU information
lscpu

Configure the UFW firewall to allow necessary traffic:

sudo apt install ufw
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https
sudo ufw enable

Create a system backup before proceeding with major changes:

sudo mkdir -p /backup/configs
sudo cp -r /etc /backup/configs/
sudo cp -r /var/www /backup/configs/

This baseline preparation ensures your Linux Mint 22 system is ready for the Cacti installation process, minimizing potential issues related to outdated packages or incorrect configurations.

Installing the LAMP Stack

Cacti relies on the LAMP (Linux, Apache, MySQL, PHP) stack to function. Let’s install and configure each component:

Installing Apache Web Server

First, install the Apache web server:

sudo apt install apache2

After installation, enable Apache to start at boot and verify it’s running:

sudo systemctl enable apache2
sudo systemctl start apache2
sudo systemctl status apache2

For basic security, disable directory listing and server signatures by editing the Apache configuration:

sudo nano /etc/apache2/conf-enabled/security.conf

Find and modify these lines:

ServerTokens Prod
ServerSignature Off
Options -Indexes

Save and close the file, then restart Apache:

sudo systemctl restart apache2

Installing PHP and Required Extensions

Cacti requires PHP with specific extensions:

sudo apt install php php-mysql php-snmp php-xml php-ldap php-gd php-curl php-json php-mbstring php-gmp php-zip libapache2-mod-php

Create a test PHP file to verify the installation:

echo "" | sudo tee /var/www/html/phpinfo.php

Visit http://localhost/phpinfo.php in your browser to confirm PHP is working correctly. Remove this file after testing:

sudo rm /var/www/html/phpinfo.php

Installing MariaDB Database Server

Install MariaDB server:

sudo apt install mariadb-server mariadb-client

Secure the MariaDB installation:

sudo mysql_secure_installation

Follow the prompts to:

  • Set a root password (if not already set)
  • Remove anonymous users
  • Disallow root login remotely
  • Remove test database
  • Reload privilege tables

Verify MariaDB is running and enable it to start at boot:

sudo systemctl status mariadb
sudo systemctl enable mariadb

Your LAMP stack is now ready to support Cacti installation on your Linux Mint 22 system.

Configuring PHP for Cacti

Cacti requires specific PHP settings for optimal performance. You’ll need to modify both the Apache PHP configuration and the CLI PHP configuration:

First, locate the PHP configuration files:

php -i | grep php.ini

You’ll typically need to edit two files:

  • /etc/php/8.2/apache2/php.ini (for web interface)
  • /etc/php/8.2/cli/php.ini (for poller script)

Note: The PHP version number may differ based on your installation.

Edit the Apache PHP configuration:

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

Find and modify the following parameters:

memory_limit = 512M
max_execution_time = 300
date.timezone = Region/City
display_errors = Off
max_input_vars = 1000
post_max_size = 64M
upload_max_filesize = 16M

Replace “Region/City” with your actual timezone.

Now edit the CLI PHP configuration with the same changes:

sudo nano /etc/php/8.2/cli/php.ini

After making these changes, restart Apache:

sudo systemctl restart apache2

Proper PHP configuration is essential for Cacti’s performance, especially when dealing with a large number of devices or graphs.

Setting Up the Database for Cacti

Cacti requires a dedicated database to store its configuration and temporary data:

First, log in to the MariaDB command-line client:

sudo mysql -u root -p

Create a database for Cacti:

CREATE DATABASE cacti CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Create a dedicated user with a strong password:

CREATE USER 'cactiuser'@'localhost' IDENTIFIED BY 'StrongPassword';

Replace ‘StrongPassword’ with a secure password of your choice.

Grant the appropriate privileges to the new user:

GRANT ALL PRIVILEGES ON cacti.* TO 'cactiuser'@'localhost';

Cacti requires MySQL timezone information for time-based graphing:

SET GLOBAL time_zone = 'UTC';
USE mysql;
GRANT SELECT ON time_zone_name TO 'cactiuser'@'localhost';

For optimal performance with Cacti, adjust some MariaDB settings:

SET GLOBAL innodb_buffer_pool_size = 256M;
SET GLOBAL innodb_flush_log_at_timeout = 3;
SET GLOBAL innodb_read_io_threads = 32;
SET GLOBAL innodb_write_io_threads = 16;

For these settings to persist after a restart, add them to your MariaDB configuration:

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Add these lines in the [mysqld] section:

innodb_buffer_pool_size = 256M
innodb_flush_log_at_timeout = 3
innodb_read_io_threads = 32
innodb_write_io_threads = 16

Now flush privileges and exit the MariaDB prompt:

FLUSH PRIVILEGES;
EXIT;

Restart MariaDB to apply all changes:

sudo systemctl restart mariadb

Installing SNMP and RRDtool

SNMP and RRDtool are essential components for Cacti’s monitoring capabilities:

Installing SNMP

Install the SNMP packages:

sudo apt install snmp snmpd libsnmp-dev

Configure the SNMP daemon for local monitoring:

sudo cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.original
sudo nano /etc/snmp/snmpd.conf

Replace the default configuration with a basic setup:

# Listen for connections on all interfaces
agentAddress udp:161

# Configure default SNMP community string for read-only access
rocommunity public localhost
rocommunity public 127.0.0.1

# System information
sysLocation    Your Location
sysContact     Your Name <your.email@example.com>
sysName        LinuxMint22Cacti

# Run as an AgentX master agent
master agentx

Customize the system information as appropriate for your environment.

Start and enable the SNMP service:

sudo systemctl enable snmpd
sudo systemctl start snmpd

Test SNMP functionality:

snmpwalk -v2c -c public localhost system

Installing RRDtool

RRDtool is required for Cacti’s graphing functionality:

sudo apt install rrdtool librrd-dev

Verify the installation:

rrdtool --version

With SNMP and RRDtool properly installed and configured, your Linux Mint 22 system is now prepared for the core Cacti installation.

Downloading and Installing Cacti

You have two options: using the package manager or manual installation. We’ll cover both, but manual installation is generally preferred for getting the latest version.

Option 1: Package Manager Installation

This is the simplest method but may not provide the latest Cacti version:

sudo apt install cacti

During installation, you’ll be prompted to configure the database automatically. Select “Yes” and follow the on-screen instructions.

Option 2: Manual Installation (Recommended)

Download the latest Cacti release from the official website:

cd /tmp
wget https://www.cacti.net/downloads/cacti-latest.tar.gz

Extract the downloaded archive:

tar -xzvf cacti-latest.tar.gz

This will create a directory like “cacti-1.2.x”. Move this directory to your web server’s document root:

sudo mv cacti-1.2.* /var/www/html/cacti

Set appropriate permissions:

sudo chown -R www-data:www-data /var/www/html/cacti/
sudo find /var/www/html/cacti/ -type d -exec chmod 755 {} \;
sudo find /var/www/html/cacti/ -type f -exec chmod 644 {} \;

Create directories for logs and RRA files:

sudo mkdir -p /var/www/html/cacti/log /var/www/html/cacti/rra
sudo chown -R www-data:www-data /var/www/html/cacti/log/
sudo chown -R www-data:www-data /var/www/html/cacti/rra/

Import the Cacti database schema:

mysql -u cactiuser -p cacti < /var/www/html/cacti/cacti.sql

When prompted, enter the password you created for the cactiuser.

Configuring Cacti Core Files

The main Cacti configuration file needs to be updated with your database settings:

sudo cp /var/www/html/cacti/include/config.php.dist /var/www/html/cacti/include/config.php
sudo nano /var/www/html/cacti/include/config.php

Find the database section and update it with your settings:

/* database connection */
$database_type     = 'mysql';
$database_default  = 'cacti';
$database_hostname = 'localhost';
$database_username = 'cactiuser';
$database_password = 'StrongPassword';
$database_port     = '3306';
$database_ssl      = false;
$database_ssl_key  = '';
$database_ssl_cert = '';
$database_ssl_ca   = '';

Replace ‘StrongPassword’ with the actual password you set for the cactiuser.

Configure the paths and URLs:

/* Default session name - Session name must contain alpha characters */
$cacti_session_name = 'Cacti';

/* path variables */
$url_path = '/cacti/';
$cacti_url = 'http://localhost/cacti/';

Save and close the file, then verify the syntax:

php -f /var/www/html/cacti/include/config.php

If there are no errors, the file is correctly configured.

Setting Up the Cacti Poller

The Cacti poller is responsible for periodically collecting data from monitored devices:

Create a cron job file for Cacti:

sudo nano /etc/cron.d/cacti

Add the following line to run the poller every 5 minutes:

*/5 * * * * www-data php /var/www/html/cacti/poller.php > /dev/null 2>&1

For more advanced deployments, you might prefer setting up a systemd service:

sudo nano /etc/systemd/system/cacti-poller.service

Add the following content:

[Unit]
Description=Cacti Poller
After=network.target mysql.service

[Service]
Type=simple
User=www-data
Group=www-data
ExecStart=/usr/bin/php /var/www/html/cacti/poller.php
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

Enable and start the service:

sudo systemctl daemon-reload
sudo systemctl enable cacti-poller.service
sudo systemctl start cacti-poller.service

If using the systemd service method, remove the cron job to avoid duplicate polling:

sudo rm /etc/cron.d/cacti

To verify that the poller is working correctly, check the Cacti log files:

sudo tail -f /var/www/html/cacti/log/cacti.log

Completing the Web-Based Installation

With the backend components in place, complete the Cacti installation through its web interface:

  1. Open your web browser and navigate to: http://your-server-ip/cacti/ Install Cacti on Linux Mint 22
  2. You’ll be greeted with the Cacti installation page. Click “Next” to proceed.
  3. Review the license agreement and click “I Agree” to continue.
  4. The installation will perform pre-installation checks. Ensure all checks pass with a “PASS” status.
  5. Select “New Install” as the installation type and click “Next”.
  6. The installer will verify directory permissions and database connectivity. If all checks pass, click “Next”.
  7. Choose the installation profile based on your environment size.
  8. Review the installation summary and click “Install” to begin the final installation process.
  9. Once installation completes, you’ll be directed to the login page.
  10. Log in with the default credentials:
    • Username: admin
    • Password: admin
  11. You’ll be immediately prompted to change the default password. Create a strong, unique password.

If you encounter any issues during the web installation:

  • Check Apache error logs: sudo tail -f /var/log/apache2/error.log
  • Verify database connectivity: mysql -u cactiuser -p cacti
  • Ensure file permissions are correct

Basic Cacti Configuration and First Device Setup

Now that Cacti is installed, let’s configure your first device for monitoring:

Install Cacti on Linux Mint 22

Adding Your First Device

  1. In the Cacti web interface, navigate to “Console” > “Devices” > “Add”
  2. Enter the following information for your Linux Mint 22 host:
    • Description: Linux Mint 22 Server
    • Hostname: localhost (or 127.0.0.1)
    • Host Template: Linux Host
    • SNMP Community: public
    • SNMP Version: Version 2
    • Downed Device Detection: PING
  3. Click “Create” to add the device
  4. After adding the device, click “Create Graphs for this Host” at the top of the page
  5. Select metrics like CPU Usage, Load Average, Memory Usage, and Network Interface Traffic
  6. Click “Create” to generate the graphs

Creating Your First View

To organize your graphs:

  1. Go to “Console” > “Management” > “Graph Trees” > “Add”
  2. Enter a name like “Linux Mint 22 Monitoring”
  3. Click “Create”
  4. Go to “Tree Items” > “Add”
  5. Select “Host” as the Tree Item Type
  6. Choose your newly added device
  7. Click “Create”

Verifying Data Collection

After setting up graphs, you need to ensure data is being collected properly:

  1. Wait for at least one polling cycle (5 minutes by default)
  2. Go to the “Graphs” tab
  3. Navigate to your graph tree and select it
  4. You should see your device with the graphs you created
  5. Initially, graphs may appear empty or with minimal data points
  6. After an hour or more, patterns will begin to emerge in your graphs

If graphs remain empty after several polling cycles, check:

  • Cacti log files for errors
  • SNMP connectivity: snmpwalk -v2c -c public localhost system
  • Poller status: ps aux | grep poller

Advanced Configuration Options

Once you’ve established basic monitoring, you can enhance your Cacti installation with advanced configurations:

Setting Up User Accounts and Permissions

For environments with multiple administrators:

  1. Navigate to “Console” > “Configuration” > “User Management” > “Users” > “Add”
  2. Create accounts with appropriate permission levels:
    • Viewer: Can only view graphs
    • Normal User: Can view and create personal graphs
    • Administrator: Full control over the system

Implementing HTTPS for Secure Access

Secure your Cacti installation with HTTPS:

sudo a2enmod ssl
sudo a2ensite default-ssl
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt
sudo systemctl restart apache2

Update your Cacti configuration to use HTTPS:

sudo nano /var/www/html/cacti/include/config.php

Change the URL to HTTPS:

$url_path = '/cacti/';
$cacti_url = 'https://your-server-ip/cacti/';

Configuring Email Notifications

Set up email alerting for monitoring thresholds:

  1. Navigate to “Console” > “Configuration” > “Settings” > “Mail/DNS”
  2. Configure your email settings:
    • From Email Address
    • From Name
    • SMTP Server
    • SMTP Port
    • SMTP Username/Password (if required)
  3. Test the email configuration by sending a test email

Setting Up Graph Templates

Customize graph appearance for better visualization:

  1. Go to “Console” > “Templates” > “Graph Templates”
  2. Select an existing template or create a new one
  3. Adjust parameters like:
    • Graph title format
    • Vertical label
    • Size and scaling
    • Custom colors
    • Time range defaults

Troubleshooting Common Installation Issues

Even with careful installation, you may encounter issues with your Cacti setup:

PHP Configuration Problems

Issue: Cacti shows errors related to PHP settings or extensions.

Solution:

  1. Verify PHP version and extensions:
    php -v
    php -m | grep -E 'mysql|snmp|xml|gd'
  2. Check PHP configuration values:
    php -i | grep -E 'memory_limit|max_execution_time|date.timezone'
  3. If any required extensions are missing:
    sudo apt install php-extension-name
    sudo systemctl restart apache2

Database Connection Issues

Issue: Cacti cannot connect to the database.

Solution:

  1. Verify database credentials in config.php
  2. Test database connectivity:
    mysql -u cactiuser -p -h localhost cacti
  3. Check MariaDB service status:
    sudo systemctl status mariadb

Permission-Related Errors

Issue: Cacti shows errors about writing to files or directories.

Solution:

  1. Reset permissions on Cacti directories:
    sudo chown -R www-data:www-data /var/www/html/cacti/
    sudo find /var/www/html/cacti/ -type d -exec chmod 755 {} \;
    sudo find /var/www/html/cacti/ -type f -exec chmod 644 {} \;
  2. Ensure specific directories are writable:
    sudo chmod -R 775 /var/www/html/cacti/resource/
    sudo chmod -R 775 /var/www/html/cacti/cache/
    sudo chmod -R 775 /var/www/html/cacti/log/
    sudo chmod -R 775 /var/www/html/cacti/rra/

SNMP Connectivity Problems

Issue: Cacti cannot collect data via SNMP.

Solution:

  1. Test SNMP connectivity:
    snmpwalk -v2c -c public localhost system
  2. Check SNMP daemon status and configuration
  3. Restart SNMP after configuration changes:
    sudo systemctl restart snmpd

Performance Tuning and Optimization

As your monitoring environment grows, optimizing Cacti performance becomes essential:

Database Optimization

Improve MariaDB performance with these settings:

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Add or modify these parameters:

innodb_buffer_pool_size = 1G
innodb_flush_log_at_timeout = 3
innodb_file_per_table = ON
innodb_buffer_pool_instances = 4

Optimize the Cacti database regularly:

OPTIMIZE TABLE cacti.poller_item;
OPTIMIZE TABLE cacti.poller_output;
OPTIMIZE TABLE cacti.graph_tree_items;

Poller Optimization

For larger installations, adjust poller settings in Cacti’s web interface:

  1. Navigate to “Console” > “Configuration” > “Settings” > “Poller”
  2. Consider these adjustments:
    • Increase “Maximum Concurrent Poller Processes”
    • Set “Poller Type” to “Spine” for better performance
    • Enable “Process SNMP Get Requests per Host”

If using Spine (a C-based poller):

sudo apt install cacti-spine

Backup Strategy

Implement a regular backup routine for your Cacti installation:

sudo mkdir -p /backup/cacti

Create a backup script:

sudo nano /usr/local/bin/backup-cacti.sh
#!/bin/bash
DATE=$(date +%Y-%m-%d)
BACKUP_DIR="/backup/cacti"

# Backup database
mysqldump -u root -p cacti > $BACKUP_DIR/cacti-db-$DATE.sql

# Backup configuration
tar -czf $BACKUP_DIR/cacti-files-$DATE.tar.gz /var/www/html/cacti/

# Remove backups older than 30 days
find $BACKUP_DIR -name "cacti-*" -type f -mtime +30 -delete

Make the script executable and schedule it:

sudo chmod +x /usr/local/bin/backup-cacti.sh
sudo crontab -e

Add this line to run weekly:

0 2 * * 0 /usr/local/bin/backup-cacti.sh > /dev/null 2>&1

Congratulations! You have successfully installed Cacti. Thanks for using this tutorial to install the latest version of Cacti monitoring on Linux Mint 22 system. For additional help or useful information, we recommend you check the official Cacti website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button