Cacti is a powerful open-source network monitoring tool that allows you to monitor the performance and availability of your network devices. With its web-based interface and extensive graphing capabilities, Cacti is a popular choice among system administrators and network engineers. In this article, we will guide you through the process of installing and configuring Cacti on Debian 11, providing you with a step-by-step tutorial.
Prerequisites
Before we dive into the installation process, make sure you have the following prerequisites in place:
- A server running Debian 11.
- A root password configured on the server.
Getting Started
To begin, it’s always a good practice to update your system to the latest version. Open your terminal and run the following commands:
sudo apt update sudo apt upgrade
Once the update process is complete, you can proceed with the installation.
Install Dependencies
Cacti relies on SNMP (Simple Network Management Protocol), so we need to install the necessary dependencies. Run the following command to install them:
sudo apt install snmp snmpd php-snmp rrdtool librrds-perl unzip curl git gnupg2
These dependencies will ensure that Cacti can collect the necessary data from your network devices.
Install LAMP Server
To run Cacti, we need to set up a LAMP (Linux, Apache, MySQL, PHP) server. Let’s start by installing Apache, the web server:
sudo apt install apache2 -y
Once the installation is complete, start the Apache service and enable it to start at boot time:
sudo systemctl start apache2 sudo systemctl enable apache2
Next, we need to install PHP and its required extensions. Run the following command:
sudo apt install php php-mysql libapache2-mod-php php-xml php-ldap php-mbstring php-gd php-gmp -y
After the installation, we need to make some modifications to the PHP configuration files. Open the php.ini file for Apache:
sudo vim /etc/php/*/apache2/php.ini
In this file, locate the following lines and make the necessary changes:
memory_limit = 512M max_execution_time = 60 date.timezone = Asia/Kolkata
Save and close the file. Now, open the php.ini file for the command-line interface:
sudo vim /etc/php/*/cli/php.ini
Make the same changes as before:
memory_limit = 512M max_execution_time = 60 date.timezone = Asia/Kolkata
Save and close the file. Finally, restart the Apache service to apply the changes:
sudo systemctl restart apache2
Install and Configure Database Server for Cacti
Cacti requires a database to store its data. We will use MariaDB as the backend for Cacti. Install MariaDB by running the following command:
sudo apt install mariadb-server
Once the installation is complete, start the MariaDB service, enable it at system startup, and check its status:
sudo systemctl start mariadb sudo systemctl enable mariadb sudo systemctl status mariadb
Log in to the MariaDB shell:
mysql
Inside the shell, create a database and a user for Cacti:
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;
Flush the privileges to apply the changes and exit the MariaDB shell:
flush privileges; exit;
Next, import the timezone data to the MariaDB database:
mysql mysql < /usr/share/mysql/mysql_test_data_timezone.sql
Grant the required privileges on the MySQL timezone:
mysql GRANT SELECT ON mysql.time_zone_name TO cacti_user@localhost; flush privileges; exit;
Now, let’s edit the MariaDB configuration file:
sudo vim /etc/mysql/mariadb.conf.d/50-server.cnf
Comment out the following two lines by adding the ‘#’ symbol at the beginning:
#collation-server = utf8mb4_general_ci #character-set-server = utf8mb4
Below the [mariadb]
section, add or modify the following lines:
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
Save and close the file. Finally, restart the MariaDB service:
sudo systemctl restart mariadb
Install and Configure Cacti
Now, let’s download the latest version of Cacti from the official website:
wget https://www.cacti.net/downloads/cacti-latest.tar.gz
Extract the downloaded file:
tar -zxvf cacti-latest.tar.gz
Move the extracted directory to the Apache root path:
mv cacti -1* /var/www/html/cacti
Next, import the database to the Cacti’s database:
mysql cactidb < /var/www/html/cacti/cacti.sql
Edit the config.php file and enter your Cacti’s database details:
cd /var/www/html/cacti/include vim config.php
Make the necessary changes in the following lines:
$database_type = 'mysql'; $database_default = 'cactidb'; $database_hostname = 'localhost'; $database_username = 'cacti_user'; $database_password = 'password'; $database_port = '3306';
Save and close the file. Set the necessary permissions to the Cacti directory:
chown -R www-data:www-data /var/www/html/cacti chmod -R 775 /var/www/html/cacti
To automate data collection, set up a cronjob for Cacti:
sudo vim /etc/cron.d/cacti
Add the following line to the file:
*/5 * * * * www-data php /var/www/html/cacti/poller.php > /dev/null 2>&1
Save and close the file.
Configure Apache Virtual Host for Cacti
To access Cacti from a web browser, we need to configure an Apache virtual host. Create a new configuration file:
sudo vim /etc/apache2/sites-available/cacti.conf
Add the following lines to the file:
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>
Enable the virtual host:
sudo a2ensite cacti
Verify the virtual host file:
ls -l /etc/apache2/sites-enabled/cacti.conf
Restart the Apache service to apply the changes:
sudo systemctl restart apache2
Accessing Cacti Web Interface
Now, open your web browser and enter the following URL with your server’s IP address:
http://your-server-ip/cacti
You should see the Cacti login page. Use the default username and password (admin) to log in. You will be prompted to change the password. After changing the password, click on the Save button. Accept the GPL Licence Agreement and click on the Begin button.
The installation process will guide you through various steps such as pre-installation checks, installation type selection, directory permission checks, and template setup. Follow the prompts and make the necessary selections.
Once the installation is complete, you will see the Cacti dashboard. From here, you can start adding network devices, monitor network bandwidth, and generate various network monitoring graphs.
Conclusion
Congratulations! You have successfully installed and configured Cacti, the powerful network monitoring tool, on Debian 11. With Cacti, you can effectively monitor the performance and availability of your network devices, ensuring smooth operation and proactive troubleshooting.
Shape.host provides reliable and efficient cloud hosting solutions, including Linux SSD VPS services. If you have any questions or need assistance with your hosting needs, feel free to reach out to our team at Shape.host. We are here to help you optimize your network monitoring and ensure a seamless IT infrastructure.