How to Install Cacti on Ubuntu 18.04 LTS (Bionic Beaver)

0

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

Cacti, in general, it is used to get a graph of CPU and network bandwidth utilization and monitors the network traffic by polling a router or switch over the SNMP protocol.

Here is the post on how to install Cacti on Ubuntu 18.04.

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 update

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

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

Additionally, you would need to install a few PHP extensions for the proper functioning of Cacti.

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

Also, install the SNMP and RRDtool on the server in case you want to monitor the Cacti server as well.

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

Create Database

Create a database for Cacti.

You can log in to MariaDB server without the MySQL root password by running sudo mysql -u root -p or mysql -u root -p command as root in Ubuntu 18.04.
# mysql -u root -p

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.

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 few settings for better performances. So, edit the configuration file.

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

Add the below variables in [mysqld] section.

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

Set Timezone

As a mandatory requirement, we need to set the timezone in the PHP configuration file. So, edit the php.ini file depending on your PHP version.

nano /etc/php/7.2/apache2/php.ini

Update your timezone, shown like below.

date.timezone = EST

Install Cacti

Download the latest version of Cacti package using wget command.

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

Extract the 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 Cacti database data to the Cacti database.

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

Edit the Cacti config file to specify the database type, database name, MySQL 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 so that Cacti can poll every five min.

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

Edit the 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.

systemctl restart mysql
systemctl restart apache2

Create a log file and allow the Apache user (www-data) to write a data on to 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

Visit the following URL to begin the installation of Cacti.

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

Accept the Cacti license agreement and click on Next to continue.

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

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

Install Cacti on Ubuntu 18.04 - Cacti Preinstallation Checks 1
Install Cacti on Ubuntu 18.04 – Cacti Preinstallation Checks 1
Install Cacti on Ubuntu 18.04 - Cacti Preinstallation Checks 2
Install Cacti on Ubuntu 18.04 – Cacti Preinstallation Checks 2

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

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

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

Install Cacti on Ubuntu 18.04 - Cacti Binary Locations
Install Cacti on Ubuntu 18.04 – Cacti Binary Locations
You can ignore the error for Spine binary file location as we are using the built-in poller for remote device polling.

READ: How to Install and Configure Spine Poller with Cacti

Now, Cacti installation wizard checks and reports for permission problems you may have in the Cacti installation directories.

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

Select all templates or the one you want and click Finish to complete the installation of Cacti.

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

Access Cacti Dashboard

Enter User Name and Password to login to Cacti.

Username: admin
Password: admin
Install Cacti on Ubuntu 18.04 - Cacti Login Screen
Install Cacti on Ubuntu 18.04 – Cacti Login Screen

You must change the password of the Cacti admin user on its first login.

Install Cacti on Ubuntu 18.04 - Cacti Change Password First Time
Install Cacti on Ubuntu 18.04 – Cacti Change Password First Time

Cacti Dashboard:

Install Cacti on Ubuntu 18.04 - Cacti Dashboard
Install Cacti on Ubuntu 18.04 – Cacti Dashboard

By default, the Local machine will be 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 18.04 - Cacti GraphAdditionally, read 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 18.04 LTS (Bionic Beaver)

0