How to Install Cacti Network Monitoring Tool on Debian 11

Cacti is an open-source, web-based network monitoring tool written in PHP. Cacti is the front end of industry-standard RRDtool. Cacti generates CPU load and network bandwidth utilization graphs using SNMP (Simple Network Management Protocol). It is specially designed for monitoring network devices like switches, routers, and servers. Cacti stores all necessary data in the MySQL database to generate various graphs.

This guide will show you, how to install the Cacti monitoring tools on Debian 11.

Prerequisites

  • A server running Debian 11.
  • A root password has been configured on the server.

Getting Started

Before you start, It is always a good idea to update your base system to the latest version. Execute the following command to update all the packages:

sudo apt update
sudo apt upgrade

After the package update, you can proceed to the next installation step.

Install Dependencies

Cacti use SNMP, so you need to install the required dependencies by running the following command:

sudo apt install snmp snmpd php-snmp rrdtool librrds-perl unzip curl git gnupg2

Install LAMP Server

You need to install Apache, PHP, and MySQL/MariaDB on your server.

Install Apache Web Server

You can install the Apache web server by the following command:

sudo apt install apache2 -y

Next, start the Apache service and enable the Apache service to start at boot time by running the following command:

sudo systemctl start apache2
sudo systemctl enable apache2

Install PHP

You need to install PHP and other required PHP extensions:

apt install php php-mysql libapache2-mod-php php-xml php-ldap php-mbstring php-gd php-gmp -y

Next, make some modifications to php.ini file:

vim /etc/php/*/apache2/php.ini

Now, make changes as shown in the below:

memory_limit = 512M
max_execution_time = 60
date.timezone = Asia/Kolkata

Now, save and close the file and next edit php.ini for CLI:

vim /etc/php/*/cli/php.ini

Next, make the following changes:

memory_limit = 512M
max_execution_time = 60
date.timezone = Asia/Kolkata

Save and close the file and restart the Apache service to apply the changes:

systemctl restart apache2

Install and Configure Database server for Cacti

MySQL/MariaDB is the backend for Cacti. You can install MariaDB by running the following command:

sudo apt install mariadb-server

Next, start the MariaDB service, enable the service at system startup and check the MariaDB service status using the following command:

sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo systemctl status mariadb

Next, log in to the MariaDB shell by executing the following command:

mysql

After login, create a database and user for Cacti by running the following command:

CREATE DATABASE cactidb DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
GRANT ALL PRIVILEGES ON cactidb.* TO 'cacti_user'@'localhost' IDENTIFIED BY 'password';
ALTER DATABASE cactidb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Next, flush the privileges to apply changes and exit from the MariaDB shell using the below command:

flush privileges;
exit;

Now, you need to import timezone data to the MariaDB database. Execute the below command to import the timezone:

mysql mysql < /usr/share/mysql/mysql_test_data_timezone.sql


import cacti mysql database

Now, log in to the MariaDB shell and grant the required privileges on the MySQL timezone by running the following command:

mysql
GRANT SELECT ON mysql.time_zone_name TO [email protected];

Next, flush the privileges and exit the MariaDB shell:

flush privileges;
exit;

Grant MySQL user privileges

Next, edit the MariaDB default configuration file:

vim /etc/mysql/mariadb.conf.d/50-server.cnf

First, comment the following two lines by adding #tag

#collation-server      = utf8mb4_general_ci
#character-set-server  = utf8mb4

Next, Add / Modify the following lines below the [mariadb] section:

collation-server = utf8mb4_unicode_ci
character-set-server=utf8mb4
max_heap_table_size = 128M
tmp_table_size = 128M
join_buffer_size = 128M
innodb_file_format = Barracuda
innodb_large_prefix = 1
innodb_buffer_pool_size = 1G
innodb_flush_log_at_timeout = 3
innodb_read_io_threads = 32
innodb_write_io_threads = 16
innodb_io_capacity = 5000
innodb_io_capacity_max = 10000
innodb_doublewrite = 0

Now, save and exit the file and restart the MariaDB service to apply the changes:

systemctl restart mariadb

After restarting the service, you can proceed to the next step.

Install and Configure Cacti

Now, download the latest version of Cacti from Cacti's official website using wget command:

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

Then, extract the tar.gz file by running the following command:

tar -zxvf cacti-latest.tar.gz

Now, move the extracted directory to the Apache root path by executing the following command:

mv cacti-1* /var/www/html/cacti

Next, import the database to the cacti's database 'cactidb' using the below command:

mysql cactidb < /var/www/html/cacti/cacti.sql

Now edit the config.php and enter your Cacti's Database Details.

cd /var/www/html/cacti/include/
vim config.php

Next, make changes in the following lines:

$database_type     = 'mysql';
$database_default  = 'cactidb';
$database_hostname = 'localhost';
$database_username = 'cacti_user';
$database_password = 'password';
$database_port     = '3306';

Now, set necessary permission to the cacti directory using the below command:

chown -R www-data:www-data /var/www/html/cacti/
chmod -R 775 /var/www/html/cacti/

Now, set the data collection frequency by using the cronjob for Cacti with the following command:

vim /etc/cron.d/cacti

Add the following line to set Cacti Pollor to run poller.php every five minutes.

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

Save and exit the file.

Configure Apache virtual host for Cacti

Next, You need to create a separate Apache virtual host configuration file for Cacti. You can create it using the below command:

vim /etc/apache2/sites-available/cacti.conf

Then, add the following lines:

Alias /cacti /var/www/html/cacti

  <Directory /var/www/html/cacti>
      Options +FollowSymLinks
      AllowOverride None
      <IfVersion >= 2.3>
      Require all granted
      </IfVersion>
      <IfVersion < 2.3>
      Order Allow,Deny
      Allow from all
      </IfVersion>

   AddType application/x-httpd-php .php

<IfModule mod_php.c>
      php_flag magic_quotes_gpc Off
      php_flag short_open_tag On
      php_flag register_globals Off
      php_flag register_argc_argv On
      php_flag track_vars On
      # this setting is necessary for some locales
      php_value mbstring.func_overload 0
      php_value include_path .
 </IfModule>

  DirectoryIndex index.php
</Directory>

Next, you need to enable this virtual host file. Execute the below command to enable it.

a2ensite cacti

Verify the cacti.conf file by running the following command:

ls -l /etc/apache2/sites-enabled/cacti.conf

Next, you have to restart the Apache service to apply changes:

systemctl restart apache2

After restarting the Apache service, execute the below command to check the Apache service status:

systemctl status apache2

Output:

? apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-06-29 07:22:07 UTC; 3s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 63096 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 63100 (apache2)
      Tasks: 6 (limit: 1132)
     Memory: 13.6M
        CPU: 100ms
     CGroup: /system.slice/apache2.service
             ??63100 /usr/sbin/apache2 -k start
             ??63101 /usr/sbin/apache2 -k start
             ??63102 /usr/sbin/apache2 -k start
             ??63103 /usr/sbin/apache2 -k start
             ??63104 /usr/sbin/apache2 -k start
             ??63105 /usr/sbin/apache2 -k start

Jun 29 07:22:07 debian-11 systemd[1]: Starting The Apache HTTP Server...

At this stage, your Cacti is installed and configured, and you can proceed to the next step to access Cacti from a web browser.

Cacti Web Interface

Now, Open your web browser and enter the following URL with your IP address:

http://your-server-ip/cacti

You should see the Cacti login page.

Cacti login

Enter the default username and password as admin and click on the Login button. You will be redirected to password reset screen as shown the below:

Set cacti password

After changing the default password, click on the Save button. You should see Licence Agreement screen:

accept license agreement from cacti

Select Accept GPL Licence Agreement check box and click on the Begin button. You should see the Pre-Installation Check and other warning information on the next screen:

Pre-Installation checks

Click on the Next button. You should see the following Installation Type screen:

Installation type

Here, you can select the type of installation you want, then click on the Next button. Next, you should see Directory Permission check screen:

Directory permission checks

Click on the next button. It will show you Critical Binary Locations and Versions screen as below:

Binary locations and versions

Click on the Next button. You should see Input Validation Whitelist Protection screen:

Input validation

Select the “I have read this statement” checkbox and Click on the Next button. You should be redirected to the Default Profile screen:

network and profile

Enter the information as per your requirement and click on the Next button. Next you should see the Template Setup screen:

Template setup

Click on the Next button, and you should see the UTF-8 related setting on the following screen:

Server Allocation

Click on the Next button. You should see the Confirm Installation screen:

Confirm installation

Select the “Confirm Installation” checkbox and then click the Install button. You should see the installation log on the next screen:

Cacti Installation complete

Once the installation has been completed, click on the Get Started button. You should see the Cacti Dashboard screen:

Cacti dashboard

Conclusion

From this article, you successfully installed and configured the Cacti monitoring tool on Debian 11. Now you can add Network devices, monitor your network bandwidth, generate various network monitoring graphs, and many more. You can easily access Cacti from a web browser. Please have no hesitation to ask me if you have any questions.

Share this page:

Suggested articles

0 Comment(s)

Add comment