How To Install Cacti on Ubuntu 20.04

THIS DOCUMENT IS ALSO AVAILABLE FOR

Cacti is a free and open-source network monitoring and graphic tool written in PHP. It is designed as the front-end application for the Round-Robin database tool (RRDtool). It is used to get CPU load and network bandwidth utilization in a graph format.

In general, Cacti is used to get network bandwidth utilization and monitor the network traffic of a router or switch by polling over the SNMP protocol.

Here, we will see how to install Cacti on Ubuntu 20.04.

Install Cacti On Ubuntu 20.04

Cacti run on top of Apache, MySQL/MariaDB, and PHP. So, we will install them one by one.

Prerequisites

Update the repository index using the apt command.

sudo apt update

Install Apache & PHP

First, install the Apache webserver.

sudo apt install -y apache2 php-mysql libapache2-mod-php

Install PHP Extensions

Additionally, install a few PHP modules for the proper functioning of Cacti.

sudo apt install -y sphp-xml php-ldap php-mbstring php-gd php-gmp

Install MariaDB

Install the MariaDB (v10.3) from the Ubuntu repository.

READ: How To Install MariaDB v10.04 On Ubuntu 20.04

You can also [install MySQL 8.0 on Ubuntu 20.04](https://www.itzgeek.com/post/how-to-install-mysql-8-0-on-ubuntu-20-04/) and use it as a database server for the Cacti installation.
sudo apt install -y mariadb-server mariadb-client

After the MariaDB installation, run the mysql_secure_installation command to secure the MariaDB instance.

Install SNMP

Also, install the SNMP and RRDtool to monitor the devices.

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

Database Tuning

Cacti recommend changing the MariaDB server settings for better performance. So, edit the configuration file.

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

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

collation-server = utf8mb4_unicode_ci
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 = 512M
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

Restart the MariaDB service post the configuration change.

sudo systemctl restart mariadb

PHP Configuration

We need to set the timezone, memory limit, and execution time in the PHP configuration file for the Cacti installation. So, edit the php.ini file depending on your PHP version.

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

AND

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

Update your timezone, as shown below.

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

Create Database

Log in to the database server.

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

sudo mysql -u root -p

Now, create a database for the Cacti installation.

create database cacti;

Create a database user and grant permission to the newly created database.

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

flush privileges;

exit

The newly created user (cactiuser) should have access to the mysql.time_zone_name table. So, we will import the mysql_test_data_timezone.sql to mysql database first.

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

Then, log in to MySQL.

sudo mysql -u root -p

Grant the permission to cactiuser.

GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost;

flush privileges;

exit

Download & Configure Cacti

Download the latest version of the Cacti using the 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 newly created cacti database.

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

Edit the Cacti configuration file to specify the database type, database name, 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;

Create a crontab file to schedule the polling job.

sudo nano /etc/cron.d/cacti

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

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

Create a new site for the Cacti tool.

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 site.

sudo a2ensite cacti

Restart Apache services.

sudo systemctl restart apache2

Create a log file for Cacti 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 below URL to begin the installation of Cacti.

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

Login to Cacti installation wizard to set up Cacti installation.

Username: admin

Password: admin

Login To Setup Cacti
Login To Setup Cacti

You must change the password of the Cacti admin user before you begin to set up Cacti.

Change Cacti Admin Password
Change Cacti Admin Password

Read and Accept the Cacti license agreement and click on Begin to continue.

Cacti License Agreement
Cacti License Agreement

Cacti perform pre-installation checks and report issues on this page. You need to fix the problems before you go to the next step. Sometimes, you can ignore warnings.

Cacti License Agreement
Cacti License Agreement

Select New Primary Server as an installation type for our installation and validate the database connection information and then click Next.

Cacti Installation Type
Cacti Installation Type

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

Directory Permission Checks
Directory Permission Checks

This page will show you the Cacti binary locations and their versions detail.

Cacti Binary Locations
Cacti Binary Locations

Take the time to read this statement and visit this link for more information and then click the Next.

Input Validation Whitelist Protection
Input Validation Whitelist Protection

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

Cacti Default Profile
Cacti Default Profile

Select the device templates you wish to use and then click Finish to complete the installation of Cacti.

Cacti Template Setup
Cacti Template Setup

Click Next.

Installation Test Page
Installation Test Page

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

Confirm Cacti Installation
Confirm Cacti Installation

Wait for the Cacti installation to complete.

Cacti Installation In Progress
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.

Access Cacti Dashboard

Visit the following URL to begin using the Cacti tool.

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

Enter User Name and Password to login to Cacti.

Username: admin

Password: <YOUR_PASSWORD>

Login To Cacti
Login To Cacti

Cacti Dashboard:

Cacti Dashboard
Cacti Dashboard

By default, the local machine (your Cacti server) will be added for monitoring in Cacti. You can Go to Graphs » Default Tree » Local Linux Machine to see the usage graph of the Cacti server.

Local Machine Usage Graph
Local Machine Usage Graph

Monitor Remote Linux Machines

READ: How to monitor remote Linux machines with Cacti monitoring tool

Conclusion

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

Prev Post
Next Post
comments powered by Disqus