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 php php-{mysql,curl,net-socket,gd,intl,pear,imap,memcache,pspell,tidy,xmlrpc,snmp,mbstring,gmp,json,xml,common}
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: Oct  6 2020 15:47:56) ( 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

Ensure you set correct timezone:

$ sudo vim /etc/php/*/apache2/php.ini 
; http://php.net/date.timezone
date.timezone = "Africa/Nairobi"

$ sudo vim /etc/php/*/cli/php.ini
date.timezone = "Africa/Nairobi"

Update memory limit:

memory_limit = 518M

Also adjust Maximum execution time of each script:

max_execution_time = 300

Step 3: Install Apache Web server

The default recommended web server for Cacti is Apache, install it using the commands:

sudo apt -y 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 [email protected]

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
[mysqld]
innodb_file_format=Barracuda
innodb_large_prefix=1
collation-server=utf8mb4_unicode_ci
character-set-server=utf8mb4
innodb_doublewrite=ON
max_heap_table_size=128M
tmp_table_size=128M
join_buffer_size=64M
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

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.

MariaDB [(none)]> select @@tmp_table_size;
+------------------+
| @@tmp_table_size |
+------------------+
| 134217728 |
+------------------+
1 row in set (0.00 sec)

Or

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

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

$ mysql -u root -p
create database cacti;
alter database cacti character set utf8mb4 collate utf8mb4_unicode_ci;
grant all privileges on cacti.* to [email protected]'localhost' identified by 'strongpassword';
flush privileges; 
exit

Test database connection:

$ mysql -u cacti_user -p
Enter password: 

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

MariaDB [(none)]> \q

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 cacti cacti-spine

When asked to select the web server, choose Apache.

 +-------------------------+ Configuring cacti +--------------------------+
   | Please select the web server for which Cacti should be automatically   |
   | configured.                                                            |
   |                                                                        |
   | Select "None" if you would like to configure the web server manually.  |
   |                                                                        |
   | Web server:                                                            |
   |                                                                        |
   |                                apache2                                 |
   |                                lighttpd                                |
   |                                None                                    |
   |                                                                        |
   |                                                                        |
   |                                 <Ok>                                   |
   |                                                                        |
   +------------------------------------------------------------------------+

For Database configuration, select no for manual configuration since we have created a database for cacti on

 +---------------------------+ Configuring cacti +---------------------------+
 |                                                                           |
 | The cacti package must have a database installed and configured before    |
 | it can be used.  This can be optionally handled with dbconfig-common.     |
 |                                                                           |
 | If you are an advanced database administrator and know that you want to   |
 | perform this configuration manually, or if your database has already      |
 | been installed and configured, you should refuse this option.  Details    |
 | on what needs to be done should most likely be provided in                |
 | /usr/share/doc/cacti.                                                     |
 |                                                                           |
 | Otherwise, you should probably choose this option.                        |
 |                                                                           |
 | Configure database for cacti with dbconfig-common?                        |
 |                                                                           |
 |                    <Yes>                       <No>                       |
 |                                                                           |
 +---------------------------------------------------------------------------+

Wait for the installation to finish then proceed to configure SNMP.

Step 6: Configure SNMP

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

Change

mibs :

to

# mibs :

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

# This 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

To

# 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 <[email protected]>
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.3 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance
SNMPv2-MIB::sysORID.4 = OID: SNMPv2-MIB::snmpMIB
SNMPv2-MIB::sysORID.5 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup
SNMPv2-MIB::sysORID.6 = OID: TCP-MIB::tcpMIB
SNMPv2-MIB::sysORID.7 = OID: IP-MIB::ip
SNMPv2-MIB::sysORID.8 = OID: UDP-MIB::udpMIB
SNMPv2-MIB::sysORID.9 = OID: SNMP-NOTIFICATION-MIB::snmpNotifyFullCompliance
SNMPv2-MIB::sysORID.10 = OID: NOTIFICATION-LOG-MIB::notificationLogMIB
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

From here, we have to configure database settings for Cacti and initiate setup on the web interface. Change db settings on the file /usr/share/cacti/site/include/config.php.

$ sudo vim /usr/share/cacti/site/include/config.php
# Around line 45 - Change cacti database connection info
$database_type = "mysqli";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti_user";
$database_password = "strongpassword";
$database_port = "3306";
$database_ssl = false;

Replace cacti_user with database user you created on Step 4 and strongpassword with cacti database user password.

Import cacti Mysql database schema:

$ sudo mysql -u cacti_user -p cacti < /usr/share/doc/cacti/cacti.sql 
Enter password:

Replace cacti_user with database user and cacti with the database name.

Setup mysql timezone for cacti database user

$ sudo 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.

Grant cacti MySQL database user access to TimeZone database:

$ sudo mysql -u root -p

GRANT SELECT ON mysql.time_zone_name TO [email protected];
FLUSH PRIVILEGES;
\q

Configure Cacti apache site Access control (Optional) :

If you would like to restrict access to Cacti Web interface, edit the file /etc/apache2/conf-available/cacti.conf and comment out the line:

Require all granted

Then configure as below:

# Change line 7
#Require all granted
Require host localhost
Require ip 192.168.1.0/24

Replace 192.168.1.0/24 with your trusted subnet. You can also add a single IP like below:

Require ip 192.168.1.20
Require ip 172.16.20.30

You need to restart apache service after making above modifications,

sudo systemctl restart apache2

Set directory permissions

sudo chown -R www-data:www-data  /usr/share/cacti/

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

install cacti server ubuntu 01

Reset admin password

install cacti server ubuntu 02

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

install cacti server ubuntu 03

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

install cacti ubuntu 18.04 02
install cacti ubuntu 18.04 03

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

install cacti ubuntu 18.04 04

Confirm that all binaries all located and click Next.

install cacti ubuntu 18.04 05

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

Finish all other steps including template setup:

install cacti server ubuntu 04

Then confirm installation:

install cacti server ubuntu 05

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

install cacti ubuntu 18.04 07 login

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:

install cacti ubuntu 18.04 09 ui

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.

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!


As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here