Other

How to Install Cacti with Cacti-Spine Ubuntu

· >

In this tutorial we’ll learn how to install and configure Cacti network monitoring tool in the latest version of Ubuntu 20.04 LTS. Cacti will be build and installed from source files during this guide.

Cacti is an open source monitoring tool created for monitoring networks, especially network devices, such as switches, routers, servers via SNMP protocol. Cacti interacts with end-users and can be administered via a web tool interface.

Pre-Requisites

  • LAMP Stack Installed on Ubuntu already installed on your box

Step 1: Install and Configure Prerequisites for Cacti

  1. First of all, make sure to update the system by issuing the below command.
#apt update && apt upgrade
  • In your LAMP stack make sure the following PHP extensions are present in the system.
apt install php7.0-snmp php7.0-xml php7.0-mbstring php7.0-json php7.0-gd php7.0-gmp php7.0-zip php7.0-ldap php7.0-mcrypt
  • Next, edit PHP configuration file and change the time zone setting to match your server’s physical location, by issuing the below command.
# echo “date.timezone = Asia/Karachi” >> /etc/php/7.4/apache2/php.ini
  • Next, log in to MariaDB or MySQL database from your LAMP stack installation and create a database for installing Cacti by issuing the following commands. Replace cacti database name, user and password to match your own configurations and choose a strong password for cacti database.
# mysql -u root -p mysql> create database cacti; mysql> grant all on cacti.* to ‘cactiuser’@’localhost’ identified by ‘p@$$w0rd’; mysql> flush privileges; mysql> exit
  • Also, issue the below commands to allow cacti user select permissions to MySQL data.timezone setting by issuing the below commands.
# mysql -u root -p mysql < /usr/share/mysql/mysql_test_data_timezone.sql # mysql -u root -p -e ‘grant select on mysql.time_zone_name to cactiuser@localhost’
  • Next, open MySQL server configuration file and add the following lines at the end of the file.
# vi /etc/mysql/mariadb.conf.d/50-server.cnf [For MariaDB] # vi nano /etc/mysql/mysql.conf.d/mysqld.cnf      [For MySQL]

Add the following lines to the end of the 50-server.cnf or mysqld.cnf file.

max_heap_table_size                    = 98M tmp_table_size                                = 64M join_buffer_size                               = 64M innodb_buffer_pool_size             = 485M innodb_doublewrite                      = off innodb_flush_log_at_timeout    = 3 innodb_read_io_threads              = 32 innodb_write_io_threads            = 16
  •  Finally, restart MySQL and Apache services to apply all settings and verify both services status by issuing the following commands.
# systemctl restart mysql apache2 # systemctl status mysql apache2

RELATED ARTICLES

Step 2: Download and Prepare Cacti Installation

  1. Start install Cacti from sources by downloading and extracting the latest version of Cacti archive and copy all the extract files to Apache web document root, by issuing the following commands.
# wget https://www.cacti.net/downloads/cacti-latest.tar.gz # tar xfz cacti-latest.tar.gz # cp -rf cacti-1.1.27/* /var/www/html/
  • Remove index.html file from /var/www/html directory, create the Cacti log file and grant Apache with write permissions to web root path.
# rm /var/www/html/index.html # touch /var/www/html/log/cacti.log # chown -R www-data:www-data /var/www/html/
  • Next, edit cacti configuration file and modify the following lines as shown in the below example.
# nano /var/www/html/include/config.php

Cacti config.php file sample. Replace cacti database name, user and password accordingly.

$database_type     = ‘mysql’; $database_default  = ‘cacti’; $database_hostname = ‘localhost’; $database_username = ‘cactiuser’; $database_password = ‘password1; $database_port     = ‘3306’; $database_ssl      = false; $url_path = ‘/’;
  • Next, populate cacti database with the cacti.sql script from /var/www/html/ directory by issuing the below command.
# mysql -u cactiuser cacti -p < /var/www/html/cacti.sql
  • Now install some additional resources, as Cacti engine collects devices data via the SNMP protocol and displays graphics by using RRDtool. Install all of them by issuing following command.
apt install snmp snmpd snmp-mibs-downloader rrdtool
  • Verify if SNMP service is up and running by restarting snmpd daemon by issuing the below command. Also check the snmpd daemon status and its open ports.
# systemctl restart snmpd.service # systemctl status snmpd.service # ss -tulpn| grep snmp

Step 3: Download and Install Cacti-Spine

  1. Cacti-Spine is a C written replacement for the default cmd.php poller. Cacti-Spine provides a faster execution time. To compile Cacti-Spine pooler from sources install the below required dependencies in your system.
# apt install build-essential dos2unix dh-autoreconf help2man libssl-dev libmysql++-dev  librrds-perl libsnmp-dev libmysqlclient-dev libmysqld-dev 
  • After you’ve installed the above dependencies, download the latest version of Cacti-Spine archive, extract the tarball and compile cacti-spine by issuing the following series of commands.
# wget https://www.cacti.net/downloads/spine/cacti-spine-latest.tar.gz # tar xfz cacti-spine-latest.tar.gz # cd cacti-spine-1.1.27/
  • Compile and install Cacti-Spine from sources by issuing the following commands.
# ./bootstrap # ./configure # make # make install
  • Next, make sure spine binary is owned by root account and set the suid bit for the spine utility by running the following commands.
# chown root:root /usr/local/spine/bin/spine # chmod +s /usr/local/spine/bin/spine
  • Now, edit Cacti Spine configuration file and add the cacti database name, user and password to the Spine conf file as illustrated in the below example.
# nano /usr/local/spine/etc/spine.conf

Add following configuration to spine.conf file.

DB_Host localhost DB_Database cacti DB_User cactiuser DB_Pass password1 DB_Port 3306 DB_PreG 0

Step 4: Cacti Installation Setup Wizard

To install Cacti, open a browser and navigate to your system IP address or domain name at the following URL.

First, check Acept License Agreement and hit on the Next button to continue.

Cacti Installation Setup Wizard

Next, check if system requirements and hit Next button to continue.

Cacti Installation Setup Wizard

In the next window, select New Primary Server and hit on Next button to continue.

Cacti Installation Setup Wizard

Next, verify critical binary locations and versions and change Spine binary path to /usr/local/spine/bin/spine. When finished, hit Next button to continue.

Cacti Installation Setup Wizard

Next, check if all web server directory permissions are in place (write permissions are set) and hit on Next button to continue.

Cacti Installation Setup Wizard

On the next step check all the templates and hit on Finish button in order to finish the installation process.

Cacti Installation Setup Wizard
  • Log in to Cacti web interface with the default credentials shown below and change the admin password, as illustrated in the following screenshots.
Cacti Installation Setup Wizard
Cacti Installation Setup Wizard
  • Next, navigate to Console -> Configuration -> Settings -> Poller and change the Poller Type from cmd.php to Spine binary and scroll down to Save button to save the configuration.
Cacti Installation Setup Wizard
  • Then, navigate to Console -> Configuration -> Settings -> Paths and add the following path to Cacti-Spine configuration file:
/usr/local/spine/etc/spine.conf
Cacti Installation Setup Wizard

The final setup which enables Cacti poller to start collecting data from monitored devices is to add a new crontab task in order to query each device via SNMP every 5 minutes.

The crontab job must be owned by www-data account.

# crontab -u www-data -e

Add Cron file entry:

*/5 * * * * /usr/bin/php /var/www/html/poller.php
  1. Wait a few minutes for Cacti to collect data and navigate to the Graphs -> Default Tree and there you will see the graphs collected for your monitored devices.

Congratulations! You have successfully installed and configured Cacti with Cacti-Spine pooler, from sources, in the latest release Ubuntu 20.04 LTS server.

close

Sign up to receive awesome content in your inbox, every month.

We don’t spam! Read our privacy policy for more info.

Leave a Reply

Your email address will not be published. Required fields are marked *