Cacti is an open-source, web-based network monitoring and graphing tool designed as a front-end application for the open-source, industry-standard data logging tool RRDtool. Cacti allow a user to poll services at predetermined intervals and graph the resulting data. It is generally used to graph time-series metrics data such as CPU load and network bandwidth utilization. Typical usage monitors network traffic by polling a network switch or router interface via Simple Network Management Protocol (SNMP).
#1: Install Apache Web Server
We install a web server on which Cacti will run, as it is a web-based tool. So, run the following command to install an Apache webserver:
sudo dnf install httpd -y
Now, use the following commands to start and enable the webserver :
sudo systemctl start httpd
sudo systemctl enable --now httpd
#2: Install MariaDB Database Server
Like all applications, Cacti also require a database to collect and store the data. Here, I am using Mariadb as our database server.
To install the database, use the following:
sudo dnf install -y mariadb-server mariadb
Next, start and allow mariadb to start on boot as shown:
sudo systemctl start mariadb
sudo systemctl enable mariadb
#3: Install PHP and PHP Extensions
Now we need to install PHP, and the required PHP dependencies as Cacti is written in PHP. So, add the Remi repository:
sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpmmi
Next, allow the DNF module for PHP installation.
sudo dnf module reset php
sudo dnf module enable php:remi-7.4
Later, install PHP and required extensions with the commands below:
sudo dnf install @php
sudo dnf install -y php php-{mysqlnd,curl,gd,intl,pear,recode,ldap,xmlrpc,snmp,mbstring,gettext,gmp,json,xml,common}
Enable the php-fpm service by executing the command:
sudo systemctl enable --now php-fpm
#4: Install SNMP and RRD Tool
Next, we need to install SNMP and RRDtool, which demand gathering and analyzing system metrics.
sudo dnf install -y net-snmp net-snmp-utils net-snmp-libs rrdtool
Start and enable snmpd with the commands:
sudo systemctl start snmpd
sudo systemctl enable snmpd
#5: Create a Cacti Database
Now create a cacti database and user and then grant all the required privileges to the cacti user.
mysql -u root -p
MariaDB [(none)]> CREATE DATABASE cactidb;
MariaDB [(none)]> GRANT ALL ON cactidb.* TO cacti_user@localhost IDENTIFIED BY 'passwd123';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;
Once completed, now import the mysql test data timezone.sql file into the mysql database.
mysql -u root -p mysql < /usr/share/mariadb/mysql_test_data_timezone.sql
Next, connect to the mysql database and give the cacti user access to the mysql.time zone name table.
MariaDB [(none)]> GRANT SELECT ON mysql.time_zone_name TO cacti_user@localhost; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> EXIT;
It is recommended to add the following configuration in the mariadb-server.cnf file under the [ mysqld ] section as shown for optimal performance.
sudo vi /etc/my.cnf.d/mariadb-server.cnf
Copy and paste the following configuration.
collation-server=utf8mb4_unicode_ci
character-set-server=utf8mb4
max_heap_table_size=32M
tmp_table_size=32M
join_buffer_size=64M
# 25% Of Total System Memory
innodb_buffer_pool_size=1GB
# pool_size/128 for less than 1GB of memory
innodb_buffer_pool_instances=10
innodb_flush_log_at_timeout=3
innodb_read_io_threads=32
innodb_write_io_threads=16
innodb_io_capacity=5000
innodb_file_format=Barracuda
innodb_large_prefix=1
innodb_io_capacity_max=10000
Last, save the made changes and exit.
#6: Installing and Configuring the Cacti Monitoring Tool
The Cacti package is available in the EPEL (Extra Packages for Enterprise Linux) repository.
sudo dnf install epel-release -y
Next, we need to install the Cacti monitoring tool as shown:
sudo dnf install cacti -y
Later, check the installation of cacti as shown:
rpm -qi cacti
Then, import the default cacti database tables into the mariadb cacti database(previously created). For the same, run the following command to get the default cacti database path:
rpm -ql cacti | grep cacti.sql
To import the default database tables, use the following command:
mysql -u root -p cactidb < /usr/share/doc/cacti/cacti.sql
Next, alter the cacti configuration file to add the following database details:
sudo vim /usr/share/cacti/include/config.php
Modify the database name, username, and password to reflect the one you created earlier.
Next, set the timezone in the php.ini file. Additionally, modify the below parameters to reflect as shown:
date.timezone = Africa/Nairobi
memory_limit = 512M
max_execution_style = 60
Next, set up cron for Cacti by editing the /etc/cron.d/cacti file as shown:
sudo vim /etc/cron.d/cacti
Uncomment the following line to have a Cacti poll for data every 5 minutes.
*/5 * * * * apache /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1
Save and exit the configuration file.
Then alter Apache’s configuration file to enable remote access to Cacti.
sudo vim /etc/httpd/conf.d/cacti.conf
Change the following lines in the file:
- Modify Require host localhost to Require all granted.
- Change Allow from localhost to Allow from [network subnet].
- Specify your network subnet. For our case, the subnet is 192.168.122.1/24.
Now, restart apache and php-fpm services for the changes to take effect.
$ sudo systemctl restart httpd
$ sudo systemctl restart php-fpm
Before ultimately setting up Cacti, enable HTTP service on your firewall as shown:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
#7: Running Cacti Installer via the Browser
To finish the set up of Cacti, visit your server’s IP as shown:
http://server-IP/cacti
The login page shown below will appear. Log in with the default credentials offered:
Username: admin
Password: admin
Now set a new password for the default cacti admin login and click save to proceed.
Once you have logged in, accept the GPL license agreement and click on ‘Begin‘.
Cacti will run pre-installation tests to guarantee that the required PHP modules are installed and set up the appropriate database settings. If everything is configured perfectly, you can continue with the installation. Click Next to proceed.
Next, select the ‘New Primary Server‘ as the type of installation and confirm that the database connection parameters are correct.
The subsequent step examines directory issues and affirms that the proper permissions are in place. If everything is in order, click ‘Next‘; otherwise, click ‘Previous‘ and correct any problems.
The installer next checks to see if all of the binary paths for the needed packages are installed.
Next, we validate data input methods. This provides you with a few actions to take after installing Cacti to whitelist data input methods. Check the ‘I have read this statement‘ box after reading the instructions.
After that, select the cron interval and input your network subnet as shown. Then click Next.
Cacti come with templates that let you monitor and graph a variety of network devices, including Linux and Windows computers. All options have been checked to ensure that you get all of the templates you need. If you’re satisfied, click Next.
Following that, the installer will verify to see if the database/server collation is UTF8 compliant. Click the Next button.
To start the installation process, press the Confirm Installation checkbox and click on the Install button.
Once the required packages have been installed, click the Get Started button.
Now the Cacti dashboard will be displayed as shown:
By default, cacti create resource utilization graphs for your local machine on which Cacti is installed. Navigate through – Graph –> Default Tree –> Local –> Choose Your Device to view the graphs.
That’s it! This is how you can install Cacti on Rocky Linux and AlmaLinux.