(Last Updated On: September 29, 2018)

Here at computingforgeeks, we like exploring various network and system monitoring tools. So far we have covered the basic setup and usage of Zabbix, telegraf/Influxdb, Grafana, 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 cacti server on Ubuntu 18.04.

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.

How to Install Cacti Server on Ubuntu 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-get update
sudo apt-get upgrade

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-get -y install php php-mysql php-curl php-net-socket \
php-gd php-intl php-pear php-imap php-memcache libapache2-mod-php \
php-pspell php-recode php-tidy php-xmlrpc php-snmp \
php-mbstring php-gettext php-gmp php-json php-xml php-common

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.2.5-0ubuntu0.18.04.1 (cli) (built: May 9 2018 17:21:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.5-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

Ensure you set correct timezone:

# grep date.timezone /etc/php/7.2/apache2/php.ini 
; http://php.net/date.timezone
date.timezone = "Africa/Nairobi"

Step 3: Install Apache Web server

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

sudo apt-get -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:
# grep ServerName /etc/apache2/apache2.conf
ServerName cacti.computingforgeeks.com

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

# grep ServerAdmin /etc/apache2/apache2.conf
ServerAdmin [email protected]

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

# ufw allow http
Rule added
Rule added (v6

# ufw allow https
Rule added
Rule added (v6)

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

$ sudo systemctl restart apache2

Step 3: Install MariaDB server

For the installation of MariaDB on Ubuntu, use my previous guide:

How to Install MariaDB on Ubuntu 18.04 and CentOS 7

Tune MariaDB database for Cacti

Add the following settings under [mysqld] on the file /e/etc/mysql/mariadb.cnf

max_heap_table_size=128M
tmp_table_size=128M
join_buffer_size=64M
innodb_buffer_pool_size=512M
innodb_doublewrite=OFF
innodb_flush_log_at_timeout=3
innodb_read_io_threads=32
innodb_write_io_threads=16

Restart mariadb service

$ sudo systemctl restart mysql

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
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 56
Server version: 10.3.7-MariaDB-1:10.3.7+maria~bionic-log mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database cacti;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> grant all privileges on cacti.* to [email protected]'localhost' identified by 'strongpassword';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> flush privileges; 
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> exit 
Bye

Test database connection:

$ mysql -u cacti_user -p
Enter password: 
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 178
Server version: 10.1.29-MariaDB-6 Ubuntu 18.04

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

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

MariaDB [(none)]>

Step 4: Install SNMP and Cacti

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-get 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 5: 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

# On line 49 -  Uncomment and change to the name of community string to any name you like.
# This enable full access from localhost

rocommunity Computingforgeeks localhost

Diable 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 Computingforgeeks localhost system
SNMPv2-MIB::sysDescr.0 = STRING: Linux cacti 4.15.0-22-generic #24-Ubuntu SMP Wed May 16 12:15:17 UTC 2018 x86_64
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (11034) 0:01:50.34
SNMPv2-MIB::sysContact.0 = STRING: Me <[email protected]>
SNMPv2-MIB::sysName.0 = STRING: cacti
SNMPv2-MIB::sysLocation.0 = STRING: Sitting on the Dock of the Bay
SNMPv2-MIB::sysServices.0 = INTEGER: 72
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (1) 0:00:00.01
SNMPv2-MIB::sysORID.1 = OID: SNMP-MPD-MIB::snmpMPDCompliance
SNMPv2-MIB::sysORID.2 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance
SNMPv2-MIB::sysORID.3 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance
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 MIB for Message Processing and Dispatching.
SNMPv2-MIB::sysORDescr.2 = STRING: The management information definitions for the SNMP User-based Security Model.
SNMPv2-MIB::sysORDescr.3 = STRING: The SNMP Management Architecture MIB.
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: (1) 0:00:00.01
SNMPv2-MIB::sysORUpTime.2 = Timeticks: (1) 0:00:00.01
SNMPv2-MIB::sysORUpTime.3 = Timeticks: (1) 0:00:00.01
SNMPv2-MIB::sysORUpTime.4 = Timeticks: (1) 0:00:00.01
SNMPv2-MIB::sysORUpTime.5 = Timeticks: (1) 0:00:00.01
SNMPv2-MIB::sysORUpTime.6 = Timeticks: (1) 0:00:00.01
SNMPv2-MIB::sysORUpTime.7 = Timeticks: (1) 0:00:00.01
SNMPv2-MIB::sysORUpTime.8 = Timeticks: (1) 0:00:00.01
SNMPv2-MIB::sysORUpTime.9 = Timeticks: (1) 0:00:00.01
SNMPv2-MIB::sysORUpTime.10 = Timeticks: (1) 0:00:00.01

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

Step 6: Configure Cacti Server

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.

# On line 49 - 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 3 and strongpassword with cacti database user password.

Import cacti Mysql database schema:

$ 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

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

# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 202
Server version: 10.1.29-MariaDB-6 Ubuntu 18.04

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 
MariaDB [(none)]> GRANT SELECT ON mysql.time_zone_name TO [email protected];
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye

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  /opt/cacti/

Step 7: Start Initial Cacti Setup

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.

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.

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: admin

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 8: 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.