How To Install Cacti on Ubuntu 20.04

Step by Step to install cacti on ubuntu 20.04 LTS. | Cacti® — The Complete RRDTool-based Graphing Solution. | You can do it.

Chaovalit Somboonpattanakit
Make it easy

--

How to install cacti on ubuntu 20.04

What is Cacti?

Cacti is a complete frontend to RRDTool, it stores all of the necessary information to create graphs and populate them with data in a MySQL database. The frontend is completely PHP driven. Along with being able to maintain Graphs, Data Sources, and Round Robin Archives in a database, cacti handles the data gathering. There is also SNMP support for those used to creating traffic graphs with MRTG. [1]

Features

  • An unlimited number of graph items can be defined for each graph optionally utilizing CDEFs or data sources from within cacti.
  • Automatic grouping of GPRINT graph items to AREA, STACK, and LINE[1–3] to allow for quick re-sequencing of graph items.
  • Data sources can be created that utilize RRDTool’s “create” and “update” functions. Each data source can be used to gather local or remote data and placed on a graph.
  • It contains a “data input” mechanism that allows users to define custom scripts that can be used to gather data. Each script can contain arguments that must be entered for each data source created using the script (such as an IP address).
  • Built-in SNMP support that can use php-snmp, ucd-snmp, or net-snmp.
  • A PHP-based poller is provided to execute scripts, retrieve SNMP data, and update your RRD files.
  • User-based management allows administrators to create users and assign different levels of permissions to the cacti interface.
  • Permissions can be specified per-graph for each user, making cacti suitable for co-location situations.
  • Each user can keep their graph settings for varying viewing preferences. [2]

How To Install Cacti on Ubuntu 20.04

This guide is show step by step to install cacti latest version (1.2.12) on ubuntu 20.04 LTS.

Cacti requires that the following software is installed on your system.

  • RRDTool 1.0.49 or greater, 1.4+ recommended
  • MySQL 5.x or greater
  • PHP 5.1 or greater
  • Web Server that supports PHP e.g. Apache or IIS

Step 1: Update all system packages

Update all dependency before installing anything.

$ sudo apt update && sudo apt upgrade

Step 2: Install Apache Webserver

Install Apache2 as a web server for the cacti

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

Step 3: Install PHP and Required Extensions

Install a PHP and Extension for the cacti faultless work.

$ sudo apt install -y php php-mysql php-snmp php-curl php-xml php-gd php-ldap php-mbstring php-gmp php-json php-common

Step 4: Install MariaDB (Database Server)

Install a MariaDB as a database server. MariaDB is a community-developed, commercially supported fork of the MySQL relational database management system (RDBMS), intended to remain free and open-source software under the GNU General Public License.[3]

$ sudo apt install -y mariadb-server mariadb-client

Step 5: Install SNMP and rrdtool

Install an SNMP and rrdtool. Cacti use the SNMP protocol to collect data from the device or remote server. And rrdtool to generate a graph.

$ sudo apt install -y snmp snmpd snmp-mibs-downloader rrdtool librrds-perl

Step 6: Configure the System timezone

Changing the Timezone Using the timedatectl Command. (Default is UTC)

$ sudo timedatectl list-timezones
$ sudo timedatectl set-timezone Asia/Bangkok

Step 7: Configure a PHP

Change a memory_limit, max_execution_time, and timezone in two PHP configuration file (php.ini) and save it.

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

You can view the list of timezone here.

date.timezone = "Asia/Bangkok"
memory_limit = 512M
max_execution_time = 60

Save all files and then restart the apache2 service.

sudo systemctl restart apache2

Step 8: Configure a MariaDB (Database Server)

Change the database configuration. The value of each parameter from the cacti suggestion. It depends on the cacti version.

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

Insert or update the below settings in the [mysqld] section.

collation-server = utf8mb4_unicode_ci
max_heap_table_size = 128M
tmp_table_size = 128M
join_buffer_size = 256M
innodb_file_format = Barracuda
innodb_large_prefix = 1
innodb_buffer_pool_size = 2048M
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_buffer_pool_instances = 21

And then restart the MariaDB.

$ sudo systemctl restart mysql

Step 9: Create Cacti’s database

Enter to the MariaDB Server with this command without using MySQL password. When the prompt “Enter password” appeared press “enter” to login.

sudo mysql -u root -p
MariaDB Console

Create the cacti’s database with this command.

MariaDB [(none)]> create database cacti;

Grant the permission to the cactiuser. Replace the ‘password’ with your password. Then Flush Privilege and exit from MariaDB console.

MariaDB [(none)]> GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'password';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit

And Then, Import the mysql_test_data_timezone.sql to the MariaDB database.

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

Grant the permission to the cactiuser to access the time_zone table.

MariaDB [(none)]> GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost;
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit

Step 10: Download and Prepare a cacti setup

Download the cacti installation file from the Cacti’s website. On the day I wrote the cacti version is 1.2.12.

Cacti’s Website

Download the cacti with this command.

$ cd /var/www/html
$ sudo rm index.html
$ sudo wget https://www.cacti.net/downloads/cacti-latest.tar.gz

Extract the cacti-latest.tar.gz file and move to directory /var/www/html.

$ sudo tar zxvf cacti-latest.tar.gz
$ cd cacti-1.2.12/
$ sudo mv * /var/www/html/

Import the Cacti’s database with this command.

$ sudo mysql -u root -p cacti < /var/www/html/cacti.sql

Edit the MySQL in the Cacti config file.

$ sudo nano /var/www/html/include/config.php
Change the password to your password in step 9

Change the Cacti Directory owner to the www-data and store the log file.

$ sudo touch /var/www/html/log/cacti.log
$ sudo chown -R www-data:www-data /var/www/html/*

Step 11: Add alias path to apache2

In this step, I want to access my cacti via the URL https://mycacti.mydomain.com without the “/cacti” at the end of the path.

So, I add the alias to the apache2 by create a new config file with the name cacti.conf in the “/etc/apache2/sites-enabled”.

$ sudo nano /etc/apache2/sites-enabled/cacti.conf

And Insert this,

Alias /cacti /var/www/html<Directory /var/www/html>Options +FollowSymLinksAllowOverride None<IfVersion >= 2.3>Require all granted</IfVersion><IfVersion < 2.3>Order Allow,DenyAllow from all</IfVersion>AddType application/x-httpd-php .php<IfModule mod_php.c>php_flag magic_quotes_gpc Offphp_flag short_open_tag Onphp_flag register_globals Offphp_flag register_argc_argv Onphp_flag track_vars On# this setting is necessary for some localesphp_value mbstring.func_overload 0php_value include_path .</IfModule>DirectoryIndex index.php</Directory>

And Restart the apache2 again.

$ sudo systemctl restart apache2

Step 12: Install cacti

Open the cacti installation by entering your URL “https://mycacti.mydomain.com” on your web browser.

The Cacti first installation page

Login with username: admin and password: admin and cacti force you to change the default password.

Change to your password

Accept and “Begin”

1. Read an Agreement and Begin

Checking the pre-installation check. You should get the result like this.

Good! Ready to install

Warning!!! If you get the result like this. You should to re-check your configuration in previous step

Not Good! Try to check your configuration

Select a New Primary Server and Next.

New Primary Server and Next

Directory Permission Check and Next.

Directory permission check

Required Binary Check and Next

All Require Software Check

Input Validation Whitelist Protection. Checked the “I have read this statement”.

Input Validation Whitelist Protection

Setup the profile. I select a default cacti profile and disable “Scan Mode” to stop the automation. (this option can be enabled after install)

Setup the profile

Select all Template and Next

Template Setup

Database Collation and Next ( In this step should not display a warning message, I forget to capture this step. So, I use an old picture.)

Database Collation

Click confirm and Next

Your cacti server is now installing

Installing cacti server

Complete the install click “Get Started”

Complete

Success!!!! Login to your cacti with the username: admin and your password.

Your cacti is ready

Set up the poller to collect data every 5 minutes. Create file cactipoller in /etc/cron.d/ and add this crontab and save it.

$ sudo nano /etc/cron.d/cactipoller
*/5 * * * * php /var/www/html/poller.php > /dev/null 2>&1
An Example of cacti graph

Notice!!! If you can’t login to your cacti after install or later. You should clear a cookie of your web browser. “The cacti 1.2.12 unable to log in after fresh install

Job done… I hope this story is useful for new cacti user.

--

--

Chaovalit Somboonpattanakit
Make it easy

Sharing my experience. | I am interested in Security, Crypto Currency, Decentralized Finance.