We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – Install and Configure Cacti on Ubuntu 20.04|18.04

Learn how to – Install and Configure Cacti on Ubuntu 20.04|18.04.

Here at Computingforgeeks, we like exploring various network and system monitoring tools. So far we have covered the basic setup and usage of Zabbixtelegraf/InfluxDBGrafana, and Prometheus. Zabbix functionality is similar to Cacti, though Cacti is more fit for network graphing. In this guide, we’ll look at how to install and configure Cacti on Ubuntu 20.04|18.04 Linux server.

What is Cacti?

Cacti is a completely open-source network monitoring and graphing tool that was designed as a front-end application for the industry-standard data logging tool RRDtool. Cacti harness the power of RRDTool’s data storage and graphing functionality. Some good features of Cacti include:

  • Fast polling of metrics
  • Support for multiple data acquisition methods
  • Support for advanced graph templating
  • User management functionality with ACL

Cacti provide an intuitive and easy to use web interface which can be used for small LAN installations up to complex networks with thousands of servers and networking devices.

Install Cacti Server on Ubuntu 20.04/18.04

Cacti has a number of dependencies that need to be installed and configured before you can deploy Cacti server itself. This guide will cover the installation of these dependencies one by one:

Step 1: Update system and upgrade all packages

We always start with server packages upgrade to avoid any dependency issues:

sudo apt update
sudo apt upgrade -y

You can reboot the server after upgrade:

sudo reboot

Step 2: Install php and required modules

We now need to install php and some php modules required by cacti. Run the following commands to get everything and installed.

sudo apt -y install apache2 php php-{mysql,curl,net-socket,gd,intl,pear,imap,memcache,pspell,tidy,xmlrpc,snmp,mbstring,gmp,json,xml,common,ldap}

sudo apt install libapache2-mod-php

The most important module is php-snmp and php-mysql. Make sure they are installed. You can check your php version using the command:

$ php -v
PHP 7.4.3 (cli) (built: Nov 25 2021 23:16:22) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

Update PHP parameters:

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

Set correct timezone:

date.timezone = "Africa/Nairobi"

Update memory limit:

memory_limit = 512M

Also adjust Maximum execution time of each script:

max_execution_time = 300

Restart Apache Web server

Step 3: Configure Apache Web server

Ensure Apache web server is installed:

sudo apt install apache2

After installing Apache, configure basic security by allowing Prod ServerTokens only.

sudo vim /etc/apache2/conf-enabled/security.conf

Change line 25

ServerTokens Prod

This directive configures what you return as the Server HTTP response. Valid options are Full | OS | Minimal | Minor | Major | Prod.

Set ServerName:
$ sudo vim /etc/apache2/apache2.conf
ServerName cacti.example.com

Set Server Admin to receive an email in case of issues.

$ sudo vim /etc/apache2/apache2.conf
ServerAdmin adminuser@example.com

If you have ufw enabled, open http and https ports on the firewall.

$ sudo ufw allow http
Rule added
Rule added (v6

$ sudo ufw allow https
Rule added
Rule added (v6)

You need to restart apache web service after making these changes:

sudo systemctl restart apache2

Step 4: Install and Configure MariaDB Database

Run the following commands to install MariaDB server on Ubuntu:s

sudo apt install mariadb-server -y

Tune MariaDB database for Cacti

Add the following settings under [mysqld]:

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

Comment out other settings on local

#around line 116
#character-set-server  = utf8mb4
#collation-server      = utf8mb4_general_ci

Restart mariadb service

sudo systemctl restart mariadb

To check any of these settings, use mysql select statement, e.g.

$ sudo mysql -u root
MariaDB [(none)]> select @@tmp_table_size;
| @@tmp_table_size |
| 134217728 |
1 row in set (0.00 sec)
MariaDB [(none)]> exit


MariaDB [(none)]> show variables like 'join_buffer_size';

Once Database server installation is done, you need to create a database for Cacti:

$ sudo mysql -u root -p
GRANT ALL PRIVILEGES ON cacti.* TO 'cacti_user'@'localhost' IDENTIFIED BY 'strongpassword';
GRANT SELECT ON mysql.time_zone_name TO cacti_user@localhost;
ALTER DATABASE cacti CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Test database connection:

$ mysql -u cacti_user -p
Enter password: strongpassword

MariaDB [(none)]> show databases;
| Database |
| cacti |
| information_schema |
2 rows in set (0.00 sec)

MariaDB [(none)]> q

Setup mysql timezone for cacti database user

$ sudo su -
$ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
Enter password: 
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.

Step 5: Install SNMP and Cacti on Ubuntu 20.04/18.04

The last package installation step is for Cacti and snmp packages. Cacti depend on Snmp and rrdtool tool for its functions. Install these packages using the command:

sudo apt install snmp snmpd snmp-mibs-downloader rrdtool

When asked to select the web server, choose Apache.

Clone Project from github:

$ sudo apt install git
$ git clone -b 1.2.x  https://github.com/Cacti/cacti.git
Cloning into 'cacti'...
remote: Enumerating objects: 75698, done.
remote: Counting objects: 100% (1608/1608), done.
remote: Compressing objects: 100% (496/496), done.
remote: Total 75698 (delta 1155), reused 1536 (delta 1105), pack-reused 74090
Receiving objects: 100% (75698/75698), 127.92 MiB | 7.02 MiB/s, done.
Resolving deltas: 100% (56327/56327), done.
Updating files: 100% (3621/3621), done.

After cloning the Cacti repository, move the files into the /var/www/html directory:

sudo mv cacti /var/www/html

Let’s now pre-populate the database used by cacti:

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

With the database populated we can go ahead and create the config.php file in /var/www/html/cacti/include:

sudo mv /var/www/html/cacti/include/config.php.dist /var/www/html/cacti/include/config.php

Modify Cacti configuration file and make sure to change the database settings as needed:

$ sudo vim /var/www/html/cacti/include/config.php
$database_type     = 'mysql';
$database_default  = 'cacti';
$database_hostname = 'localhost';
$database_username = 'cacti_user';
$database_password = 'strongpassword';

Step 6: Configure SNMP

Start by enabling the loading of MIBs by commenting out the following line on /etc/snmp/snmp.conf

sudo vim /etc/snmp/snmp.conf


mibs :


# mibs :

Configure SNMP community name by editing /etc/snmp/snmpd.conf

sudo vim /etc/snmp/snmpd.conf

Enable full access from localhost:

rocommunity MyCacti localhost

Disable public access by commenting below lines:

rocommunity public default -V systemonly
rocommunity6 public default -V systemonly


# rocommunity public default -V systemonly
# rocommunity6 public default -V systemonly

Restart snmpd service:

sudo systemctl restart snmpd

Validate snmp configurations using snmpwalk command line tool:

$ sudo snmpwalk -v 2c -c MyCacti localhost system
SNMPv2-MIB::sysDescr.0 = STRING: Linux ubuntu 5.4.0-73-generic #82-Ubuntu SMP Wed Apr 14 17:39:42 UTC 2021 x86_64
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (1964) 0:00:19.64
SNMPv2-MIB::sysContact.0 = STRING: Me <me@example.org>
SNMPv2-MIB::sysName.0 = STRING: ubuntu
SNMPv2-MIB::sysLocation.0 = STRING: Sitting on the Dock of the Bay
SNMPv2-MIB::sysServices.0 = INTEGER: 72
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORID.1 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance
SNMPv2-MIB::sysORID.2 = OID: SNMP-MPD-MIB::snmpMPDCompliance
SNMPv2-MIB::sysORID.4 = OID: SNMPv2-MIB::snmpMIB
SNMPv2-MIB::sysORID.7 = OID: IP-MIB::ip
SNMPv2-MIB::sysORID.9 = OID: SNMP-NOTIFICATION-MIB::snmpNotifyFullCompliance
SNMPv2-MIB::sysORDescr.1 = STRING: The SNMP Management Architecture MIB.
SNMPv2-MIB::sysORDescr.2 = STRING: The MIB for Message Processing and Dispatching.
SNMPv2-MIB::sysORDescr.3 = STRING: The management information definitions for the SNMP User-based Security Model.
SNMPv2-MIB::sysORDescr.4 = STRING: The MIB module for SNMPv2 entities
SNMPv2-MIB::sysORDescr.5 = STRING: View-based Access Control Model for SNMP.
SNMPv2-MIB::sysORDescr.6 = STRING: The MIB module for managing TCP implementations
SNMPv2-MIB::sysORDescr.7 = STRING: The MIB module for managing IP and ICMP implementations
SNMPv2-MIB::sysORDescr.8 = STRING: The MIB module for managing UDP implementations
SNMPv2-MIB::sysORDescr.9 = STRING: The MIB modules for managing SNMP Notification, plus filtering.
SNMPv2-MIB::sysORDescr.10 = STRING: The MIB module for logging SNMP Notifications.
SNMPv2-MIB::sysORUpTime.1 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORUpTime.2 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORUpTime.3 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORUpTime.4 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORUpTime.5 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORUpTime.6 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORUpTime.7 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORUpTime.8 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORUpTime.9 = Timeticks: (6) 0:00:00.06
SNMPv2-MIB::sysORUpTime.10 = Timeticks: (6) 0:00:00.06

Remember to replace MyCacti with the name of your community string.

Step 7: Configure Cacti Server on Ubuntu 20.04/18.04

Set Cacti directory permissions:

sudo chown -R www-data:www-data /var/www/html/cacti

Create systemd unit file for Cacti:

sudo tee /etc/systemd/system/cactid.service<<EOF
Description=Cacti Daemon Main Poller Service



Touch environment file:

sudo touch /etc/default/cactid

Now start and enable cacti service:

sudo systemctl daemon-reload
sudo systemctl enable cactid
sudo systemctl restart cactid

Check status of cactid service:

$ systemctl status cactid
 cactid.service - Cacti Daemon Main Poller Service
     Loaded: loaded (/etc/systemd/system/cactid.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-09-01 17:48:43 UTC; 5s ago
    Process: 42072 ExecStart=/var/www/html/cacti/cactid.php (code=exited, status=0/SUCCESS)
   Main PID: 42089 (php)
      Tasks: 1 (limit: 4682)
     Memory: 13.6M
     CGroup: /system.slice/cactid.service
             └─42089 php /var/www/html/cacti/cactid.php

Sep 01 17:48:43 ubuntu systemd[1]: Starting Cacti Daemon Main Poller Service...
Sep 01 17:48:43 ubuntu cactid.php[42072]: Starting Cacti Daemon ... [OK]
Sep 01 17:48:43 ubuntu systemd[1]: Started Cacti Daemon Main Poller Service.

Step 8: Start Initial Cacti Setup on web interface

Open your favorite web browser and navigate to  “http://(Cacti server’s hostname or IP address)/cacti/” from a client system authorized on Cacti server.

Login with username admin and Password admin

Reset admin password

Tick Accept GPL License Agreement then click “Begin” button to proceed.

Cacti will check if all requirements are satisfied. You may need to make some changes depending on warnings level.

Click Next button to go to the next stage.

You will be asked to select server installation type:

  • New Primary Server – Choose this for the Primary site.
  • New Remote Poller – Remote Pollers are used to access networks that are not readily accessible to the Primary site.

Since this is our first server, Choose “New  Primary Server” then click Next

Confirm that all binaries all located and click Next.

Take note of directories that need to have read-only permissions after installation and click Next.

Finish all other steps including template setup:

Then confirm installation:

You are now on the final stage, finish the installation by clicking the Finish button to get the login page.

The default logins are:

username: admin
Password: updated_password

When prompted to change the password for the admin user, provide a new password and confirm.You will then get access to Cacti interface which looks like below:

Step 9: Monitor Local Cacti Server

Add the local Cacti server for monitoring.  Login to Cacti as admin user and go to:

Console > Devices > + (Add device)

Fill server details and scroll down and click “Save” button.

Step 10: Using Cacti Spine Poller

The spine is a multi-thread, high-speed data collection tool that acts as a replacement for cmd.php for Cacti. You can install and use it by following the guide in the link below:


Your Cart is Empty

Back To Shop