How to Install Cacti on CentOS 7 / RHEL 7 & Fedora 27 / Fedora 26 – A Network Monitoring Tool

2
Install Cacti on CentOS 7
Install Cacti on CentOS 7

Cacti is an open source web-based network monitoring tool designed as the front end application for the RRDtool (Round-Robin database tool), it allows a user to poll the services at an interval of time and resulting in the graph format.

Cacti is used to get a graph data for the CPU and network bandwidth utilization, it monitors the network traffic by polling a router or switch via SNMP.

Here is the small tutorial about installing Cacti on CentOS 7 / RHEL 7 and Fedora 27 / 26.

Prerequisites

Setup EPEL repository only on CentOS 7 / RHEL 7.

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Install SNMP and RRDTool.

yum -y install net-snmp net-snmp-utils net-snmp-libs rrdtool

Install the required PHP extensions.

### CentOS 7 / RHEL 7 ###

yum -y install mariadb-server php php-xml php-session php-sockets php-ldap php-gd

### Fedora 27 / Fedora 26 ### 

dnf -y install mariadb-server php php-xml php-session php-sockets php-ldap php-gd php-gmp

Start the following services.

systemctl start httpd
systemctl start snmpd
systemctl start mariadb

Create Cacti Database

Create a database for Cacti. If you are configuring the MySQL for the first time; take a look at how to secure the MySQL.

# mysql -u root -p

Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 5.5.37-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>

Create Cacti database.

create database cacti;

Grant permission to the newly created database.

GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactipassword';
flush privileges;
exit

The newly created database user (cactiuser) should have access to the mysql.time_zone_name Table. To do that, import the mysql_test_data_timezone.sql to mysql database first.

### CentOS 7 / RHEL 7 ###

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

### Fedora 27 / Fedora 26 ###

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

Then, log in to MySQL.

mysql -u root -p

Grant the permission to cactiuser.

GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost;
flush privileges;
exit

Database Tuning

Cacti recommend changing MySQL variables settings for better performances.  Edit configuration file depends on the operating system.

### CentOS 7 / RHEL 7 ###

vi /etc/my.cnf.d/server.cnf

### Fedora 27 / Fedora 26 ###

vi /etc/my.cnf

Add variables in [mysqld] section.

CentOS 7 / RHEL 7:

collation-server = utf8_general_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
max_heap_table_size = 128M
max_allowed_packet = 16777216
tmp_table_size = 64M
join_buffer_size = 64M
innodb_file_per_table = on
innodb_buffer_pool_size = 512M
innodb_doublewrite = off
innodb_additional_mem_pool_size = 80M
innodb_lock_wait_timeout = 50
innodb_flush_log_at_trx_commit = 2

Fedora 27 / Fedora 26:

collation-server = utf8mb4_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8mb4
max_heap_table_size = 128M
max_allowed_packet = 16777216
tmp_table_size = 64M
join_buffer_size = 64M
innodb_file_per_table = on
innodb_buffer_pool_size = 512M
innodb_doublewrite = off
innodb_flush_log_at_timeout = 3
innodb_read_io_threads = 32
innodb_write_io_threads = 16
innodb_lock_wait_timeout = 50
innodb_flush_log_at_trx_commit = 2

Install & Configure Cacti

Use YUM command on CentOS / RHEL and DNF command on Fedora to install Cacti package.

### CentOS 7 / RHEL 7 ###

yum -y install cacti

### Fedora 27 / Fedora 26 ###

dnf -y install cacti

Import the default database to the cacti database.

### CentOS 7 / RHEL 7 ###

mysql cacti < /usr/share/doc/cacti-*/cacti.sql -u root -p

### Fedora 27 / Fedora 26 ### 

mysql -u root -p cacti < /usr/share/doc/cacti/cacti.sql

Edit the config file to specify the database type, name, hostname, user, and password information.

vi /usr/share/cacti/include/config.php

Make the changes accordingly.

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

Add the following entry in the crontab to poll every five min.

*/5 * * * * cacti php /usr/share/cacti/poller.php > /dev/null 2>&1

Edit apache configuration file to perform the remote installation.

vi /etc/httpd/conf.d/cacti.conf

Modify first directory stanza, from “Require host localhost

<Directory /usr/share/cacti/>
<IfModule mod_authz_core.c>
# httpd 2.4
Require host localhost
</IfModule>
<IfModule !mod_authz_core.c>
# httpd 2.2
Order deny,allow
Deny from all
Allow from localhost
</IfModule>
</Directory>

To “Require all granted

<Directory /usr/share/cacti/>
<IfModule mod_authz_core.c>
# httpd 2.4
Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
# httpd 2.2
Order deny,allow
Deny from all
Allow from localhost
</IfModule>
</Directory>

Set the timezone by editing /etc/php.ini file.

vi /etc/php.ini

Update the timezone.

date.timezone = US/Central

Restart the services.

systemctl restart httpd
systemctl restart snmpd
systemctl restart mariadb

Enable services to start at system start-up.

systemctl enable httpd
systemctl enable snmpd
systemctl enable mariadb

Firewall

Configure the firewall to allow HTTP service.

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

SELinux

It is recommended to permanently disable SELinux for Cacti to work correctly. To temporarily disable the SELinux, run the following command in the terminal.

setenforce 0

Setup Cacti Web Interface

Visit the following URL to start the installation of cacti.

http://your-ip-address/cacti

Accept the License Agreement on this page and then click on Next to continue.

Install Cacti on CentOS 7 - Cacti License Agreement
Install Cacti on CentOS 7 – Cacti License Agreement

Move to next step by clicking Next button located at the right bottom of the page.

Install Cacti on CentOS 7 - Cacti Pre-Installation Checks
Install Cacti on CentOS 7 – Cacti Pre-Installation Checks
Install Cacti on CentOS 7 - Successful Cacti Pre-Installation Checks
Install Cacti on CentOS 7 – Successful Cacti Pre-Installation Checks

You can safely ignore the warning for updating MySQL 5.5 to 5.6+.

If you probably want to install MySQL 5.7 and MariaDB 10 then follow below links.

READ: Install MySQL 5.7 on CentOS 7/6, RHEL 7/6, and Fedora 27/26/25

Select New Primary Server or the new installation and then click Next.

Install Cacti on CentOS 7 - Cacti Installation Type
Install Cacti on CentOS 7 – Cacti Installation Type

It will show you if there is any package is missing which is mandatory for the cacti.

Install Cacti on CentOS 7 - Cacti Binaries
Install Cacti on CentOS 7 – Cacti Binaries

You can safely ignore the error for Spine as we are using the buit-in poller for remote polling.

READ: How to Install and Use Spine Poller with Cacti

This step checks and reports for permission problems you may have in the Cacti installation directory.

Install Cacti on CentOS 7 - Cacti Directory Permission Checks
Install Cacti on CentOS 7 – Cacti Directory Permission Checks

Select all templates and click Finish to complete the Cacti installation.

Install Cacti on CentOS 7 - Cacti Template Setup
Install Cacti on CentOS 7 – Cacti Template Setup

Access Cacti Dashboard

Enter User Name and Password (Default: admin/admin) to login to Cacti.

Install Cacti on CentOS 7 - Cacti Login Page
Install Cacti on CentOS 7 – Cacti Login Page

You must change the default password.

Install Cacti on CentOS 7 - Cacti Change Password
Install Cacti on CentOS 7 – Cacti Change Password

Cacti Dashboard:

Install Cacti on CentOS 7 - Cacti DashBoard
Install Cacti on CentOS 7 – Cacti Dash Board

How to Add Graphs

Go to Management >> Device >> Select Device >> Select Place on a Tree >> Go.

Install Cacti on CentOS 7 - Add Device to Graphs
Install Cacti on CentOS 7 – Add Device to Graphs

Click continue to finish adding a device to Graph.

To view usage graph. Go to Graph >> Default Tree >> Choose Your Device. Wait at least 15 – 30 minutes to let Cacti populate the usage graph of your device for you.

Install Cacti on CentOS 7 - Resource Usage Graph
Install Cacti on CentOS 7 – Resource Usage Graph

Now you can start configuring the Cacti to monitor your devices. More documentation can be found here. Please post your valuable comments below.

You might also like