Share on Social Media

Learn how to install Cacti Server on CentOS 8 with this comprehensive guide. Follow step-by-step instructions to set up and configure Cacti for efficient network monitoring and performance tracking. #centlinux #linux #cacti

What is Cacti Server?

Cacti is an open-source network monitoring and graphing tool designed to provide a robust solution for monitoring and visualizing the performance of network devices and servers. It is particularly useful for tracking metrics over time and identifying trends or issues in network performance. Here are some key features and aspects of Cacti:

Key Features of Cacti

  • Data Collection:
  • Cacti can collect data from a variety of sources using SNMP (Simple Network Management Protocol), scripts, and other methods.
  • It supports both built-in and custom data collection scripts, allowing for flexibility in monitoring different types of devices and metrics.
  • Graphing:
  • Cacti excels in creating detailed and customizable graphs to visualize collected data.
  • Users can create graphs with multiple data sources and customize the appearance and format to meet specific needs.
  • Templates:
  • Cacti includes templates for graphs, data sources, and devices, simplifying the setup and configuration process.
  • These templates can be customized and extended, making it easy to apply consistent settings across multiple devices.
  • User Interface:
  • Cacti provides a web-based interface for managing and viewing network performance data.
  • The interface is designed to be user-friendly, with options for creating and editing graphs, managing data sources, and configuring devices.
  • Scalability:
  • Cacti is designed to handle large-scale environments, capable of monitoring hundreds or thousands of devices.
  • It can be extended and customized to meet the needs of large enterprises as well as smaller networks.
  • Alerts and Notifications:
  • Cacti can be configured to send alerts and notifications based on predefined thresholds and conditions.
  • This helps administrators respond promptly to network issues and performance problems.
  • Plugins:
  • The functionality of Cacti can be extended through a variety of plugins, which add additional features and capabilities.
  • Plugins are available for enhanced graphing, additional data collection methods, user authentication, and more.

Use Cases for Cacti

  • Network Performance Monitoring: Track bandwidth usage, latency, and other performance metrics for routers, switches, and other network devices.
  • Server Monitoring: Monitor the performance and resource utilization of servers, including CPU usage, memory usage, disk activity, and more.
  • Capacity Planning: Analyze historical data to predict future resource needs and plan for network and infrastructure upgrades.
  • Troubleshooting: Identify and diagnose network and server performance issues by visualizing trends and anomalies in collected data.
  • Reporting: Generate reports and dashboards to provide insights into network performance for management and stakeholders.

Conclusion

Cacti is a powerful and flexible tool for network monitoring and graphing, suitable for a wide range of environments from small networks to large enterprises. Its ability to collect and visualize data, combined with its scalability and extensibility, makes it a valuable asset for IT professionals and network administrators.

Read Also: Install Cacti on Rocky Linux 9

Linux Server Specification

We are using a minimal CentOS 8 KVM machine with following specification.

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 2 GB
  • Storage – 20 GB
  • Operating System – CentOS 8.2
  • Hostname – cacti-01.centlinux.com
  • IP Address – 192.168.116.206 /24

Recommended Online Training: Learn Bash Shell in Linux for Beginners

745772 0021

Upgrade Linux Software Packages

Connect with cacti-01.centlinux.com as root user by using a ssh tool.

First of all, we are upgrading the existing software packages of our CentOS 8 server.

# dnf update -y

Our CentOS 8.1 machine has been upgraded to CentOS 8.2. We can confirm it by using following commands.

# uname -a
Linux cacti-01.centlinux.com 4.18.0-193.6.3.el8_2.x86_64 #1 SMP Wed Jun 10 11:09:32 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

# cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)

You can follow our previous post to upgrade CentOS 7 to 8 Server.

Installing Apache Web Server

Cacti network monitoring server is a PHP based web application, therefore, we need a PHP supported web browser to run it.

We are using the popular Apache HTTP Server for this purpose.

# dnf install -y httpd httpd-devel

Enable and start Apache service.

# systemctl enable --now httpd.service
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service â /usr/lib/systemd/system/httpd.service.

Allow the Apache Service in Linux firewall, to make it accessible from the network computers.

# firewall-cmd --permanent --add-service=http
success
# firewall-cmd --reload
success

Installing MariaDB Database Server

Cacti requires a MySQL database for its metadata repository. Therefore, we are installing MariaDB server. Please follow our previous article, if you want to install latest version of MariaDB on CentOS 8.

# dnf install -y mariadb-server

Enable and start MariaDB database service.

# systemctl enable --now mariadb.service
Created symlink /etc/systemd/system/mysql.service â /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service â /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service â /usr/lib/systemd/system/mariadb.service.

Configure MariaDB Server and set the password of root user.

# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Install PHP on CentOS 8

Cacti is developed in PHP programming language, thus it requires a PHP supported web server to run. We have already installed Apache HTTP Server and now we are installing PHP on CentOS 8.

# dnf install -y php-fpm php-common php-mysqlnd php-xml php-ldap php-json php-cli php-gd php-gmp php-mbstring php-process

Enable and start PHP-FPM Service.

# systemctl enable --now php-fpm.service
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service â /usr/lib/systemd/system/php-fpm.service.

Install SNMP on CentOS 8

SNMP (Simple Network Management Protocol) is an Internet standard protocol for collecting and organizing information about managed devices on IP networks.

Install net-snmp and net-snmp-utils packages to install SNMP and php-snmp to enable PHP support for SNMP.

# dnf install -y net-snmp php-snmp net-snmp-utils

Install RRDTool on CentOS 8

Cacti requires RRDTool (RRD stands for Round Robin Database) for maintaining system metrics data. Therefore, we are installing rrdtool package using dnf command.

# dnf install -y rrdtool

Configure PHP Settings for Cacti Server

To use Cacti network monitoring server, we need to customize PHP settings accordingly.

Edit /etc/php.ini configuration file and configure it for using Cacti.

# vi /etc/php.ini

Locate and set following parameters therein.

safe_mode = Off                 ; Disable safe mode
date.timezone = "Asia/Karachi"  ; Define timezone to avoid warnings on time/date functions
file_uploads = On               ; Allow import of templates
memory_limit = 400M             ; maximum amount of memory a PHP script can consume
max_execution_time = 60         ; maximum execution time (in seconds) of a PHP script

Install Cacti Server on CentOS 8

We are downloading latest stable version of Cacti from their official website.

# cd /tmp
# wget https://www.cacti.net/downloads/cacti-1.2.12.tar.gz
--2020-06-19 09:50:55--  https://www.cacti.net/downloads/cacti-1.2.12.tar.gz
Resolving www.cacti.net (www.cacti.net)... 104.28.9.127, 172.67.196.107, 104.28.8.127, ...
Connecting to www.cacti.net (www.cacti.net)|104.28.9.127|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25126474 (24M) [application/octet-stream]
Saving to: âcacti-1.2.12.tar.gzâ

cacti-1.2.12.tar.gz 100%[===================>]  23.96M  2.34MB/s    in 11s

2020-06-19 09:51:08 (2.12 MB/s) - âcacti-1.2.12.tar.gzâ saved [25126474/25126474]

Extract downloaded tarball into default DOCUMENT_ROOT.

# tar -C /var/www/html -xzf cacti-1.2.12.tar.gz
# cd

Rename the Cacti directory to a simple name for easy accessibility.

# mv /var/www/html/cacti-1.2.12 /var/www/html/cacti

Create a MariaDB Database for Cacti Server

Connect with MariaDB server as root user.

# mysql -u root -p123
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 8
Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]>

Create a database for Cacti network monitoring server.

MariaDB [(none)]> create database cacti CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Query OK, 1 row affected (0.112 sec)

Create a user for Cacti software and grant complete rights on cacti database.

MariaDB [(none)]> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'Str0ngPa55word';
Query OK, 0 rows affected (0.254 sec)

Grant Time Zone selection privilege to cacti user.

MariaDB [(none)]> GRANT SELECT ON mysql.time_zone_name TO cacti@localhost;
Query OK, 0 rows affected (0.042 sec)

Reload privileges tables.

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.083 sec)

Exit from MySQL shell.

MariaDB [(none)]> QUIT
Bye

Cacti tarball also contains a SQL script for creating the necessary database objects. We can use this script to create tables and other objects in the cacti database.

# mysql -D cacti -u cacti -pStr0ngPa55word < /var/www/html/cacti/cacti.sql

Before moving forward, we need to load the MariaDB timezone tables. Otherwise, the Cacti web installer will give you warning on timezones.

Use following command to load timezone tables with available timezones from CentOS 8 operating system.

# mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p123 mysql
Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.

Timezones has been successfully loaded into MariaDB tables. Don’t worry about the warnings, it is because these files do not contain a valid timezone.

Edit MariaDB configuration file.

# vi /etc/my.cnf.d/mariadb-server.cnf

Set following global variables under [mysqld] section, as required by Cacti network monitoring software.

join_buffer_size=30M
innodb_file_format=Barracuda
innodb_buffer_pool_size=256M
innodb_buffer_pool_instances=1
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
innodb_large_prefix=1
character_set_client=utf8mb4
character_set_server=utf8mb4
collation_server=utf8mb4_unicode_ci

Configure Cacti Server on CentOS 8

Edit config.php file and update parameters according to your environment.

# vi /var/www/html/cacti/include/config.php

Locate and update following parameters.

$database_username = 'cacti';
$database_password = 'Str0ngPa55word';

Make apache user as owner of the Cacti software directory.

# chown -R apache:apache /var/www/html/cacti/

Restart Apache and PHP services to apply changes.

# systemctl restart httpd.service php-fpm.service

Configure SELinux for Cacti Server

Install required SELinux commands i.e. semanage by using dnf command..

# dnf install -y policycoreutils-python-utils-2.9-9.el8.noarch

Configure SELinux to allow read/write on the following directories.

# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/log(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/resource/snmp_queries(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/resource/script_server(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/resource/script_queries(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/scripts(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/boost(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/mibcache(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/realtime(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/spikekill(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/rra(/.*)?"

Reapply the filecontexts on the cacti directory.

# restorecon -R /var/www/html/cacti/

Configure a cron job to run poller.php script in every 5 minutes. This script will collect and update the system metrics in /rra directory.

# echo  "*/5 * * * *    apache   /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1" >> /etc/crontab

Open URL http://cacti-01.centlinux.com/cacti in a client’s browser such as Google Chrome.

Cacti Server Login
Cacti Server Login

Login by using default username/password i.e. admin/admin

Cacti Server - Change Password
Cacti Server – Change Password

Since, we are login to Cacti web interface for the first time, therefore, we are required to change the default password of admin user.

Cacti Server License Agreement
Cacti Server License Agreement

Read and accept the License Agreement of Cacti network monitoring software.

Cacti Preinstallation Checks
Cacti Preinstallation Checks

If you have followed the installation steps in this article correctly, then you won’t found any warning on this page.

We are skipping a warning about innodb_buffer_pool_instances, a MariaDB global variable, because we are installing MariaDB on a machine with limited memory. If you install MariaDB on a machine with more than 1 GB RAM available for InnoDB buffer, you won’t see this warning.

Cacti Installation Type
Cacti Installation Type

Choose your preferred installation type. Since, this is our first Cacti server therefore, we have selected “New Primary Server”.

Cacti Directory Permission Checks
Cacti Directory Permission Checks

If you have configured the SELinux correctly, then there won’t be any warnings.

Cacti - Critical Binary Location and Versions
Cacti – Critical Binary Location and Versions

Setup is checking for required binaries, their locations and required versions.

Cacti Security Concerns
Cacti Security Concerns

Setup will inform you about a security concern and how to handle it. Accept it and continue.

Cacti Server - Default Profile
Cacti Server – Default Profile

Adjust your default profile and continue.

Cacti Server - Template Setup
Cacti Server – Template Setup

Select the required device templates and continue.

Cacti Server Collation
Cacti Server Collation

Setup is checking the MariaDB server and database collation.

Cacti - Confirm Installation
Cacti – Confirm Installation

If your configurations are fine, then Cacti setup will display this page and it will ask you to start installation.

Installing Cacti Server
Installing Cacti Server
Cacti Installation Process Log
Cacti Installation Process Log

We have successfully install Cacti on CentOS 8.

Cacti Dashboard 1
Cacti Dashboard 1

After successful installation, you will reached at the Cacti Dashboard.

Cacti Dashboard - Graphs
Cacti Dashboard – Graphs

You can see some graphs by clicking on the Graphs tab.

Before you begin using the Cacti network monitoring server, we recommend that you should read Cacti Beginner’s Guide – Second Edition (PAID LINK) by Packt Publishing. It will be really helpful to understand the Cacti web interface and it’s usage.

Final Thoughts

Cacti is an invaluable tool for network and server performance monitoring, providing detailed insights and visualizations to help manage and optimize your infrastructure. Installing and configuring Cacti on CentOS 8 can significantly enhance your ability to track and analyze network metrics, ensuring your systems run smoothly and efficiently.

If you need expert guidance on setting up Cacti Server on Linux Server, I offer a comprehensive service to help you through the process. From installation to configuration and optimization, I’ll ensure your Cacti setup is tailored to your specific needs and runs seamlessly.

For professional assistance, visit my Fiverr gig here. Let’s get your Cacti Server up and running on CentOS 8!

7 thoughts on “How to install Cacti Server on CentOS 8”
  1. Indeed, i followed so many articles, but this one went through without any issues. Seamless and clear instructions with snapshots. Many thanks for the publisher.

  2. I changed the data directory location in database, how to change socket location in php?
    PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/app/cactiserver/cactidb/mysql/mysql.socket' (2)' in Command line code:1
    Stack trace:
    #0 Command line code(1): PDO->__construct('mysql:host=loca…', 'cactiuser', 'Cacti*102030')
    #1 {main}
    thrown in Command line code on line 1

Leave a Reply