How To Install Cacti on Debian 10 / Debian 9 – A Monitoring Tool

0

ADVERTISEMENT

Install Cacti on Debian 10
Install Cacti on Debian 10

Cacti is an open-source network monitoring tool designed as the front end application for the RRDtool. It allows users to poll services at an interval of time and resulting in a graph format.

With Cacti, you can get a graph for CPU and network bandwidth utilization. Also, it monitors the network traffic by polling a router or switch via SNMP.

Here, we will see how to install Cacti on Debian 10 / Debian 9.

THIS DOCUMENT IS ALSO AVAILABLE FOR

Prerequisites

Update the repository index.

sudo apt update

Install MariaDB

sudo apt install -y mariadb-server mariadb-client
Debian 9 comes with MariaDB v10.1 which is a bit older than the package available in MariaDB’s official site. So, I recommend you to install MariaDB 10.4 / 10.3 on Debian 9.

Database Tuning

Cacti recommend changing MySQL a few settings for better performances. So, edit the configuration file.

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

Add/Update the below settings in [mysqld] section.

collation-server = utf8mb4_unicode_ci
character-set-server  = utf8mb4
max_heap_table_size = 128M
tmp_table_size = 64M
join_buffer_size = 64M
innodb_file_format = Barracuda
innodb_large_prefix = 1
innodb_buffer_pool_size = 1GB
innodb_buffer_pool_instances = 10
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

Install Apache & PHP Extensions

sudo apt install -y apache2 libapache2-mod-php php-xml php-ldap php-mbstring php-gd php-gmp php-mysql
Debian 9 comes with PHP v7.0 which is already the end of life. So, I recommend you to install the PHP 7.3 on Debian 9.

Set Timezone

As a mandatory requirement, we need to set the timezone in the PHP configuration file. So, edit the php.ini file depending on your PHP version.

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

AND

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

Update your timezone, as shown below.

date.timezone = US/Central
memory_limit = 512M
max_execution_time = 60

Install SNMP

sudo apt install -y snmp php-snmp rrdtool librrds-perl

Restart MariaDB service.

sudo systemctl restart mariadb

sudo systemctl restart apache2

Create Database

Create a database for Cacti installation.

You can log in to the MariaDB server without the MySQL root password by running sudo mysql -u root -p or mysql -u root -p command as root in Ubuntu 18.04.
sudo mysql -u root -p

Now, create a database for the Cacti installation.

create database cacti;

Grant permission to the newly created database.

GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactipassword';
flush privileges;
exit

The newly created database user (cactiuser) should have access to the mysql.time_zone_name Table. To do that, import the mysql_test_data_timezone.sql to mysql database.

sudo mysql -u root -p mysql < /usr/share/mysql/mysql_test_data_timezone.sql

Then, log in to MySQL.

ADVERTISEMENT

sudo mysql -u root -p

Grant the permission to cactiuser.

GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost;
flush privileges;
exit

Install Cacti

Download the latest version of the Cacti package using wget command.

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

Extract the Cacti archive using the tar command and move the extracted files to /opt directory.

tar -zxvf cacti-latest.tar.gz

sudo mv cacti-1* /opt/cacti

Import the default Cacti database data to the Cacti database.

sudo mysql -u root -p cacti < /opt/cacti/cacti.sql

Edit the Cacti config file to specify the database type, database name, MySQL hostname, user, and password information.

sudo nano /opt/cacti/include/config.php

Make the changes accordingly.

/* make sure these values reflect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "cactipassword";
$database_port = "3306";
$database_ssl = false;

Edit the crontab file.

sudo nano /etc/cron.d/cacti

Add the following entry in the crontab so that Cacti can poll every five min.

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

Edit the Apache configuration file to perform the remote installation.

sudo nano /etc/apache2/sites-available/cacti.conf

Use the following configuration.

Alias /cacti /opt/cacti

  <Directory /opt/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 created virtual host.

sudo a2ensite cacti

Restart Apache services.

sudo systemctl restart apache2

Create a log file and allow the Apache user (www-data) to write a data on to Cacti directory.

sudo touch /opt/cacti/log/cacti.log

sudo chown -R www-data:www-data /opt/cacti/

Setup Cacti

Visit the following URL to begin the installation of Cacti.

http://your.ip.add.ress/cacti

Login to Cacti to set up Cacti installation.

ADVERTISEMENT

Username: admin
Password: admin

Login To Setup Cacti
Login To Setup Cacti

You must change the password of the Cacti admin user before you setup Cacti.

Change Cacti Admin Password
Change Cacti Admin Password

Accept the Cacti license agreement and click on Next to continue.

Accept Cacti License Agreement
Accept Cacti License Agreement

Cacti perform pre-installation checks and reports any issues on this page. You need to fix the problems if the installation wizard reports.

Cacti Preinstallation Checks
Cacti Preinstallation Checks

Select New Primary Server as an installation type for the new installation and then click Next.

Cacti Installation Type
Cacti Installation Type

Now, Cacti installation wizard checks and reports for permission problems you may have in the Cacti installation directories.

Directory Permission Checks
Directory Permission Checks

It will show you here if there is any package is missing, which is mandatory for the Cacti.

Cacti Binary Locations
Cacti Binary Locations

Click Next on the default profile page as we already configured cron to poll every five minutes.

Cacti Default Profile
Cacti Default Profile

Select all templates or the one you want and then click Finish to complete the installation of Cacti.

Cacti Template Setup
Cacti Template Setup

Click Next on the final test summary page.

Installation Test Page
Installation Test Page

Select Confirm Installation and press Install to begin the Cacti installation.

Confirm Cacti Installation
Confirm Cacti Installation

Wait for the installation to complete.

Cacti Installation In Porgress
Cacti Installation In Progress

In a minute or two, the Cacti installation will complete.

Cacti Installation Complete
Cacti Installation Complete

Clicking on the Get Started on the above page will take you directly to the Cacti dashboard. Otherwise, you can log in to Cacti with the user name and the password you set during the Cacti installation.

Access Cacti

Open up a browser and visit the below URL.

ADVERTISEMENT

http://your.ip.add.ress/cacti

Login to Cacti using the admin with the password you entered during the Cacti setup.

Login To Cacti
Login To Cacti

The Cacti Dashboard will look like below after your successful login.

Cacti Dashboard
Cacti Dashboard

You can go to Graphs >>Default Tree>>Local Linux Machine to see the usage graph of the Cacti server.

Device Usage Graph
Device Usage Graph

Conclusion

That’s All. I hope you have learned how to install Cacti on Debian 10 / Debian 9.. Now, you can check out how to monitor remote Linux machines with Cacti monitoring tool. Please share your feedback in the comments section.

You might also like