17.9 C
Texas

How To Install and Configure Cacti on Ubuntu 20.04

Today we are going to learn that how to install Cacti on Ubuntu 20.04. Cacti is a totally open-source network monitoring and graphing tool designed as a front-end software for the industry-trendy information logging tool RRDtool. Cacti harness the Power of RRDtool’s data storage and graphing functionality.

Some suitable features of Cacti consist of:

  • Rapid polling of metrics
  • Assist for multiple information acquisition strategies
  • Support for advanced graph template
  • Consumer control functionality with ACL

Cacti offer an intuitive and smooth to use internet interface which may be used for small LAN installations up to complicated networks with lots of servers and networking devices. So, now we are going to start the installation of Cacti on Ubuntu 20.04.

Step 1: Update & Upgrade Your System

sudo apt -y update && sudo apt -y upgrade

Step 2: Install PHP & PHP Extensions

- Advertisement -

Run the below command to install the required PHP extensions.

sudo apt install -y php-mysql libapache2-mod-php php-xml php-ldap php-mbstring php-gd php-gmp

Verify the PHP version by typing.

php -v

Output:

sabir@Ubuntu20:~$ php -v
PHP 7.4.3 (cli) (built: May 26 2020 12:24:22) ( 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

Then set your timezone, memory limit and max_execution time by editing /etc/php/7.4/apache2/php.ini

sudo nano /etc/php/7.4/apache2/php.ini
date.timezone = Asia/Karachi
memory_limit = 512M
max_execution_time = 60

Do the same changes for /etc/php/7.4/cli/php.ini file.

Step 3:Install Apache Server

Apache is one of the best web server that suits with the Cacti. So, install it by running.

sudo apt-get install -y apache2

As the installation of Apache done, apply a security configuration to the Apache by permitting Prod ServerTokens only. Open the security.conf file with your favorite editor.

sudo nano /etc/apache2/conf-enabled/security.conf

Then change the following line.

ServerTokens Prod

Finally allow firewall access to http, https.

sudo ufw allow http
sudo ufw allow https

And restart the Apache server.

sudo systemctl restart apache2

Step 4:Install MariaDB Database

Make sure that you’ve already installed MariaDB on your Ubuntu system. If you don’t know how to install it, then follow the below link to go to the MariaDB installation page first & then continue from here to Install Cacti on Ubunut 20.04.

How To Install MariaDB on Ubuntu 20.04

You can also install it from Ubuntu repository by hitting.

sudo apt install -y mariadb-server mariadb-client

Once the installation finished, run the below command to secure the installation.

sudo mysql_secure_installation

Then change the MariaDB settings to work properly with the Cacti. Edit the config file by hitting below command.

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

And make the below changes under [mysqld] section.

collation-server = utf8mb4_unicode_ci
max_heap_table_size = 128M
tmp_table_size = 64M
join_buffer_size = 64M
innodb_file_format = Barracuda
innodb_large_prefix = 1
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

Then restart the MariaDB services to take effects of the configuration changes.

sudo systemctl restart mariadb

As the services restarted , create a new Database for Cacti:

sudo mysql -u root -p
create database cacti;
grant all privileges on cacti.* to osradar@localhost identified by 'yourpassword';
flush privileges;
quit;

Now, run the below command to give permissions to new user for accessing the mysql.time_zone_name table.

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

Now, login to MySQL and give permissions to “osradar” user.

sudo mysql -u root -p
GRANT SELECT ON mysql.time_zone_name TO osradar@localhost;
flush privileges;
exit

Step 5: Install SNMP & rrdtool on Ubuntu 20.04

Now, run the below command to get install the SNMP and rrdtool for the monitoring of devices.

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

Step 6: Downloading & Configuring Cacti

Fetch the latest version of Cacti by running the below command or you can visit the official page to download the latest version of cacti.

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

After the download finished extract the downloaded package.

tar -zxvf cacti-latest.tar.gz

Then move the resultant to the /opt directory.

sudo mv cacti-1* /opt/cacti

Now, hit the given command to import the default DB data to new cacti DB.

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

And then specify the DB type, DB name, host name, user & passwd info by editing the below file.

sudo nano /opt/cacti/include/config.php

Update to the similar changes.

/* make sure these values reflect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "osradar";
$database_password = "'yourpassword'";
$database_port = "3306";
$database_ssl = false;

Now, create a crontab file to schedule the polling job.

sudo nano /etc/cron.d/cacti

Then add the below line.

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

After it create a new site for the Cacti.

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

And make the following changes

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 .
     </IfVersion>
DirectoryIndex index.php
</Directory>

Then fire the below command to enable the created site.

sudo a2ensite cacti

Finally restart the apache server to take effects.

sudo systemctl restart apache2

Now, create a log file and also permit the Apache user (www-data) to write info on to cacti directory. You can do so by hitting the below command.

sudo touch /opt/cacti/log/cacti.log
sudo chown -R www-data:www-data /opt/cacti/

Step 7 Finalizing Cacti Installation

As we’ve done all the necessary steps to Install & Configure Cacti on our Ubuntu system. So, now we are going to test our Installation. Go to your browser and type locahost/cacti or 127.0.0.1/cacti to finalize our Installation.

Provide the below details to set up Cacti installation.

Username = admin
Password = admin
How To Install and Configure Cacti on Ubuntu 20.04

For security reasons, change the password and provide new strong password.

How To Install and Configure Cacti on Ubuntu 20.04

Accept the License Agreement and hit Begin button.

How To Install and Configure Cacti on Ubuntu 20.04

Make sure that all requirements are okay.

And then hit “Next“.

How To Install and Configure Cacti on Ubuntu 20.04

Select the type of Server, as we are going to Install our first Server so I’m selecting the Primary Server.

How To Install and Configure Cacti on Ubuntu 20.04

Then press “Next” button.

And check the Directory Permissions.

How To Install and Configure Cacti on Ubuntu 20.04

After it press “Next“. And make sure all the options are okay(green tick).

How To Install and Configure Cacti on Ubuntu 20.04

Now, agree to the statement after reading it carefully. And then press “Next

How To Install and Configure Cacti on Ubuntu 20.04

On the next page you can see the default profile page as we’ve already setup the cron job for every 5 minutes. Then click “Next”.

How To Install and Configure Cacti on Ubuntu 20.04

Then select the profile template and press “Next”.

How To Install and Configure Cacti on Ubuntu 20.04

Hit “Next” button to move on to the next step.

Finally finish the installation by checking the “Confirm Installation” box and click on “Install” button.

Then click on “Get Started” button when installation finished.

Now, you will be directed to the dashboard where you can perform different tasks. Navigate to the graphics section to see the graphic details of local or remote machines.

How To Install and Configure Cacti on Ubuntu 20.04

Now, you can see the graphs, resources and values and other network resources via cacti on your system. So, this is how you can install and configure Cacti on Ubuntu 20.04.If you’ve any question regarding this tutorial, feel free to ask in comments.

So, share this post and join our Telegram Channel.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article