How to Install Cacti on Ubuntu 16.04 / Ubuntu 14.04 & LinuxMint 18

16

Cacti is an open source web-based network monitoring tool designed as the front end application for the RRDtool (Round-Robin database tool), it allows a user to poll the services at an interval of time and resulting in the graph format.

Cacti is generally used to get a graph data for the CPU and network bandwidth utilization and monitors the network traffic by polling a router or switch via SNMP protocol.

Here is the small tutorial on how to install Cacti on Ubuntu 16.04 / Ubuntu 14.04 & Linux Mint 18.

Prerequisites

Log in as the root user or switch to the root user.

sudo su -

OR

su -

Update the repository index using the apt command.

apt-get update

Cacti run on top of AMP server. So, install Apache, MySQL and PHP packages on your machine.

### Ubuntu 16.04 / LinuxMint ###

apt install -y apache2 mariadb-server mariadb-client php-mysql libapache2-mod-php

### Ubuntu 14.04 ### Below command will install MariaDB 5.5. Consider installing MariaDB 10

apt install -y apache2 mariadb-server mariadb-client php5-mysql libapache2-mod-php5

Note: While installing MariaDB on Ubuntu 14.04, the installer will prompt you to set the MySQL root password. Whereas, in Ubuntu 16.04 or LinuxMint, there will be no prompt.

There are few PHP extensions you would need to install for the proper functioning of Cacti monitoring tool.

### Ubuntu 16.04 / LinuxMint ###

apt-get -y install php-xml php-ldap php-mbstring php-gd php-gmp

### Ubuntu 14.04 ###

apt-get -y install php5-ldap php5-gd php5-gmp

Also, install the SNMP and RRDtool.

### Ubuntu 16.04 / LinuxMint ###

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

### Ubuntu 14.04 ###

apt-get -y install snmp php5-snmp rrdtool librrds-perl

Create Database

Create a database for Cacti. You can login to MariaDB without the password using the sudo mysql -u root -pcommand in Ubuntu 16.04 and Linuxmint.

# mysql -u root -p

Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 5.5.37-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>

Now, create a database for Cacti installation.

create database cacti;

Grant permission to the newly created database.

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

The newly created database user (cactiuser) should have access to the mysql.time_zone_name Table. To do that, import the mysql_test_data_timezone.sql to mysql database first.

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

Then, log in to MySQL.

mysql -u root -p

Grant the permission to cactiuser.

GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost;
flush privileges;
exit

Database Tuning

Cacti recommend changing MySQL variables settings for better performances. So, edit the configuration file.

### Ubuntu 16.04 / LinuxMint ###

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

### Ubuntu 14.04 ###

nano /etc/mysql/my.cnf

Add variables in [mysqld] section.

In Ubuntu 16.04 / LinuxMint 18:

collation-server = utf8mb4_unicode_ci
max_heap_table_size = 128M
tmp_table_size = 64M
join_buffer_size = 64M
innodb_buffer_pool_size = 512M
innodb_doublewrite = off
innodb_additional_mem_pool_size=96M
innodb_flush_log_at_timeout = 3
innodb_read_io_threads = 32
innodb_write_io_threads = 16

In Ubuntu 14.04:

max_heap_table_size = 181M
tmp_table_size = 64M
join_buffer_size = 64M
innodb_buffer_pool_size = 904M
innodb_doublewrite = off
innodb_file_per_table = on
innodb_additional_mem_pool_size=96M
innodb_flush_log_at_trx_commit = 2

Set Timezone

As a mandatory requirement, we need to set the timezone in the php configuration file. Edit the php.ini file.

### Ubuntu 16.04 / LinuxMint ###

nano /etc/php/7.0/apache2/php.ini

### Ubuntu 14.04 ###

nano /etc/php5/apache2/php.ini

Update your timezone, shown like below.

date.timezone = EST

Install Cacti

The Cacti package available on OS repository is too old, and for this setup, we are going to use the latest version of Cacti from cacti.net. Use the wget command to download the latest Cacti package from the official website on a terminal.

wget https://www.cacti.net/downloads/cacti-latest.tar.gz

Extract the downloaded Cacti archive using the tar command and move the extracted files to /opt directory.

tar -zxvf cacti-latest.tar.gz
mv cacti-1* /opt/cacti

Import the default database to the Cacti database.

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

Edit the config file to specify the database type, name, hostname, user, and password information.

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;

Edit the crontab file.

nano /etc/crontab

Add the following entry in the crontab to poll every five min.

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

Edit apache configuration file to perform the remote installation.

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 virtual host.

a2ensite cacti

Restart MariaDB and Apache2 services.

service mysql restart
service apache2 restart

Create a log file and allow Apache user (www-data) to write a data on Cacti directory.

touch /opt/cacti/log/cacti.log
chown -R www-data:www-data /opt/cacti/log/
chown -R www-data:www-data /opt/cacti/resource/
chown -R www-data:www-data /opt/cacti/cache/
chown -R www-data:www-data /opt/cacti/scripts/
chown -R www-data:www-data /opt/cacti/rra

Setup Cacti

Open a web browser and visit the following URL to start the installation of Cacti.

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

Accept the license agreement and click on Next to continue.

Install Cacti on Ubuntu 16.04 - Cacti License Agreement
Install Cacti on Ubuntu 16.04 – Cacti License Agreement

Cacti perform pre-installation checks and reports any issues on this page.

Install Cacti on Ubuntu 16.04 - Cacti Preinstallation Checks - PHP Modules
Install Cacti on Ubuntu 16.04 – Cacti Preinstallation Checks – PHP Modules

You can ignore few red alerts for MariaDB parameters in case you are running an old version of MySQL / MariaDB.

Also, you can safely ignore the warning for updating MySQL 5.5 to 5.6+ or suggesting to use MariaDB 10.

If you want to install MySQL 5.7 and MariaDB 10, then follow below links.

READ: How to install MySQL 5.7 on Ubuntu 14.04 / Linux Mint 17

READ: How to install MariaDB 10 on Ubuntu 14.04 / Linux Mint 17

Select New Primary Server for the new installation and then click Next.

Install Cacti on Ubuntu 16.04 - Installation Type
Install Cacti on Ubuntu 16.04 – Installation Type

It will show you if there is any package is missing which is mandatory for the cacti.

Install Cacti on Ubuntu 16.04 - Cacti Binary Locations
Install Cacti on Ubuntu 16.04 – Cacti Binary Locations

You can safely ignore the error for Spine as we are using the built-in poller for remote polling.

READ: How to Install and Use Spine Poller with Cacti

In this page, Cacti checks and reports for permission problems you may have in the Cacti installation directory.

Install Cacti on Ubuntu 16.04 - Directory Permission Checks
Install Cacti on Ubuntu 16.04 – Directory Permission Checks

Select all templates and click Finish to complete the Cacti installation.

Install Cacti on Ubuntu 16.04 - Cacti Template Setup
Install Cacti on Ubuntu 16.04 – Cacti Template Setup

Access Cacti Dashboard

Enter User Name and Password (Default: admin/admin) to login to Cacti.

Install Cacti on Ubuntu 16.04 - Cacti First Time Login
Install Cacti on Ubuntu 16.04 – Cacti First Time Login

You must change the default password.

Install Cacti on Ubuntu 16.04 - Cacti Password Change
Install Cacti on Ubuntu 16.04 – Cacti Password Change

Cacti Dashboard:

Install Cacti on Ubuntu 16.04 - Cacti Dashboard
Install Cacti on Ubuntu 16.04 – Cacti Dashboard

By default, the Local machine has been added for monitoring in Cacti. You can Go to Graphs >> Default Tree >> Local Linux Machine to see the usage graph of Cacti server.

Install Cacti on Ubuntu 16.04 - Usage Graph of Local Machine
Install Cacti on Ubuntu 16.04 – Usage Graph of Local Machine

In our next article, we will see how to configure cacti to monitor remote Linux machines.

READ: How to monitor remote Linux machines with Cacti

That’s All.

Further Reading

You might also like

How to Install Cacti on Ubuntu 16.04 / Ubuntu 14.04 & LinuxMint 18

16