In this article, we will have explained the necessary steps to install and configure Cacti on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo
privileges. All the commands in this tutorial should be run as a non-root user.
Cacti is an open-source platform for data monitoring that is completely PHP driven. It is designed as the front-end application for the Round-Robin database tool (RRDtool). It enables users to view CPU load graphs, RAM usage, and other information collected from different hosts. Like Nagios, Cacti supports SNMP that makes it possible to monitor: Linux’s, BSD’s, and Windows hosts.
Install Cacti on CentOS 8
Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.
sudo dnf install epel-release sudo dnf update sudo dnf install policycoreutils-python-utils-2.9-9.el8.noarch
Step 2. Install LAMP Stack on CentOS 8 system.
Cacti is built with PHP. You can host it like you would any other web app is written in PHP. So, you’re going to need to set CentOS up as either a LAMP server. If you haven’t done so already, use our traditional LAMP guide to set up CentOS to serve PHP before you continue.
Step 3. Install SNMP and RRD tool.
We are going to install SNMP and RRDtool using the command below:
sudo dnf install net-snmp net-snmp-utils net-snmp-libs rrdtool
Step 4. Download and Install Cacti on CentOS system.
We are downloading the latest stable version of Cacti from their official website:
wget https://www.cacti.net/downloads/cacti-1.2.15.tar.gz tar -C /var/www/html -xzf cacti-1.2.15.tar.gz cd
Next, rename the Cacti directory to a simple name for easy accessibility:
mv /var/www/html/cacti-1.2.15 /var/www/html/cacti
Step 5. Creating a MySQL database for Cacti.
Cacti uses the MySQL database to store all its data like posts, pages, users, plugins, and themes settings. Log in to your MySQL server with the following command and enter your MySQL root password:
mysql -u root -p
Once you’re in the MySQL console, create a new database:
MariaDB [(none)]> create database cacti CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> GRANT ALL ON cacti.* TO [email protected] IDENTIFIED BY 'Y0ur-PassWd'; Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> GRANT SELECT ON mysql.time_zone_name TO [email protected]; Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> QUIT Bye
Now, hit the given command to import the default DB data to the new cacti DB:
mysql -D cacti -u cacti -pY0ur-PassWd < /var/www/html/cacti/cacti.sql
Next, load timezone tables with available timezones from CentOS 8 operating system:
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
Once done, now edit MariaDB configuration file:
nano /etc/my.cnf.d/mariadb-server.cnf
Set the following global variables under [mysqld] section, as required by Cacti network monitoring:
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
Step 6. Configure Cacti on CentOS 8.
First, edit config.php
file and update parameters according to your environment:
nano /var/www/html/cacti/include/config.php
Update the following parameters:
$database_username = 'cacti'; $database_password = 'Y0ur-PassWd';
Next, Make apache user the owner of the Cacti software directory:
chown -R apache:apache /var/www/html/cacti/ systemctl restart httpd.service
Step 7. Configure SELinux for Cacti.
Now configure SELinux to allow read/write on the following directories:
[[email protected] ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/log(/.*)?" [[email protected] ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/resource/snmp_queries(/.*)?" [[email protected] ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/resource/script_server(/.*)?" [[email protected] ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/resource/script_queries(/.*)?" [[email protected] ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/scripts(/.*)?" [[email protected] ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/boost(/.*)?" [[email protected] ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/mibcache(/.*)?" [[email protected] ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/realtime(/.*)?" [[email protected] ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/spikekill(/.*)?" [[email protected] ~]# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/rra(/.*)?"
After that, Re-apply the filecontexts
on the cacti directory:
restorecon -R /var/www/html/cacti/
Next, configure a cron job to run poller.php
the script every 5 minutes. This script will collect and update the system metrics in/rra
the directory:
echo "*/5 * * * * apache /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1" >> /etc/crontab
Step 8. Completing the Cacti Installation.
Open your favorite web browser and go to http://your-domain-name/cacti.
Login to the Cacti installation wizard to set up the Cacti installation:
Username: admin
Password: admin
That’s all you need to do to install Cacti on CentOS 8. I hope you find this quick tip helpful. For further reading on Cacti monitoring, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.