Ubuntu

How to Install Cacti on Ubuntu

How to Install Cacti on Ubuntu

Cacti is a network graphing solution based on RRDtool’s framework. It collects and stores performance information to create graphs. It mostly uses SNMP for gathering information. In this post, we will be showing you step by step procedure for installing Cacti on Ubuntu OS.

Note: The installation method described here has been tried on Ubuntu 20.04 LTS.

Step 1: Installing Prerequisites

First, we will update the repository index and then install some prerequisite packages.

Execute the command below to update the repository index:

$ sudo apt update -y

Then use this command for installing the prerequisites:

$ sudo apt install unzip rrdtool git snmp php-snmp librrds-perl curl gnupg2 -y

Step 2: Installing LAMP server

Cacti also requires LAMP stack to be installed on your system. Use this command to install it:

$ sudo apt install mariadb-server php php-mysql apache2 libapache2-mod-php php-xml php-mbstring php-gmp php-ldap php-gd -y

Wait for a little until the installation of all the mentioned packages is completed on your system.

Next, you are required to do is to open the php.ini file in a text editor using the command below:

$ sudo nano /etc/php/7.4/apache2/php.ini

Find and change the values of these lines:

memory_limit = 512M

max_execution_time = 60

date.timezone = Asia/Karachi

Now save the file and exit the editor.

Then open another php.ini file:

$ sudo nano /etc/php/7.4/cli/php.ini

Find and change the values of these lines:

memory_limit = 512M

max_execution_time = 60

date.timezone = Asia/Karachi

Now save the file and exit the editor.

As you have done the changes, so now restart the Apache service:

$ sudo systemctl restart apache2

Now the LAMP stack has been installed.

Step 3: Configuring MariaDB Server

The database server used by Cacti is MariaDB. We will need to configure it.

Use the below command to edit the default configuration file of MariaDB server in Nano editor:

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

Add the below lines in this file:

collation-server = utf8mb4_unicode_ci

tmp_table_size = 64M

join_buffer_size = 64M

innodb_file_format = Barracuda

innodb_large_prefix = 1

max_heap_table_size = 128M

innodb_io_capacity = 5000

innodb_io_capacity_max = 10000

innodb_buffer_pool_size = 512M

innodb_flush_log_at_timeout = 3

innodb_read_io_threads = 32

innodb_write_io_threads = 16

Save the file and exit the editor.

Now restart MariaDB using the command below:

$ sudo systemctl restart mariadb

Next, we will create a database and a user for Cacti. Enter into MariaDB server prompt using the command below:

$ sudo mysql

Create database named “cacti_db” using the command below:

$ create database cacti_db;

Then create a user named “cactiuser” with the password “123cacti” for Cacti:

$ GRANT ALL ON cacti_db.* TO [email protected] IDENTIFIED BY '123cacti';

Then use the command below to apply the changes you have made and then exit the MySQL prompt.

$ flush privileges;
$ exit;

Now grant database access to MySQL timezone:

$ sudo mysql mysql < /usr/share/mysql/mysql_test_data_timezone.sql

Now grant permission to the cactiuser to access the MySQL timezone. To do so, first enter into MariaDB server prompt using the command below:

$ sudo mysql

Then grant permission to cactiuser to access MySQL timezone:

$ GRANT SELECT ON mysql.time_zone_name TO [email protected];

Then use the command below to apply the changes you have made and then exit the MySQL prompt.

$ flush privileges;
$ exit;

Step 4: Installing Cacti

Now download Cacti from its official Downloads page. Alternatively, you can use the below command to download the Cacti latest version 1.2.18 (as of August 2021).

$ wget https://files.cacti.net/cacti/linux/cacti-1.2.18.tar.gz

You can find the downloaded tar.gz file in your current Terminal directory.

Then extract the archive using the command below:

$ sudo tar -zxf cacti-1.2.18.tar.gz

The archive file cacti-1.2.18.tar.gz will be extracted to a new folder cacti-1.2.18. Move the contents of the directory to /var/www/html/cacti.

$ sudo mv cacti-1.2.18 /var/www/html/cacti

Now import the cacti database using the command below:

$ sudo mysql cactidb < /var/www/html/cacti/cacti.sql

Edit the config.php file:

$ sudo nano /var/www/html/cacti/include/config.php

Then modify the settings as follows:

$database_type = 'mysql';
$database_default = 'cacti_db';
$database_hostname = 'localhost';
$database_username = 'cactiuser';
$database_password = ‘123cacti’;
$database_port = '3306';

Save the config.php file and close it.

Now change the Cacti directory owner using the command below:

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

Also, change the permissions:

$ sudo chmod -R 775 /var/www/html/cacti/

Step 5: Creating a Cron Job

Now create a cron job file to configure poller to gather information every 5 minutes. Use this command to create a cron job file:

$ sudo nano /etc/cron.d/cacti

Add the below line in the file:

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

Then save the cron file and close it.

Step 6: Configuring Apache

Now configure Apache virtual host file using the command below:

$ sudo nano /etc/apache2/sites-available/cacti.conf

In the file, add below lines:

Alias /cacti /var/www/html/cacti

<Directory /var/www/html/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

php_value mbstring.func_overload 0

php_value include_path .

</IfModule>

DirectoryIndex index.php

</Directory>

Now save the cacti.conf file and exit it.

Then run these commands:

$ sudo a2ensite cacti
$ sudo systemctl restart apache2

Then to verify if the Apache is running without any issues, use the command below:

$ sudo systemctl status apache2

Step 7: Starting the Cacti Initialization Wizard

Now access the following link in your web browser:

http://server_ip/cacti

After accessing the above link, you will see the Cacti login page. To login, use admin as your login credentials.

Then the following page will appear. You can set a new password here.

Then you will be presented with the license terms. Accept the terms and click Begin.

Hit Next.

Select the installation type and hit Next.

Hit Next.

Again, hit Next.

Check the box at the bottom and hit Next.

Chose your preferred options and hit Next.

When the following screen appears, make sure all templates are selected. Then hit Next.

Hit Next.

Check Confirm Installation box and click Install to initiate the installation process.

After the installation is finished, hit Get Started.

After that, the following Cacti Dashboard will appear on your screen.

Now in your Cacti Dashboard, you can create devices and start monitoring them.

In this post, we described step by step procedure for installing the Cacti monitoring tool on Ubuntu 20.04 LTS. For more information about how to add and manage your devices, visit Cacti’s official documentation.

Similar Posts