How to install cacti network monitoring tool on CentOS 7 Linux

In this tutorial we are going to show how to install cacti network monitoring tool on CentOS 7 Linux.
as you may know, Cacti network monitoring tool is one of the monitoring tools that can be implemented on Linux servers. Cacti has a web-based management environment and templates for different operating systems and devices.
It has made the monitoring process easy and powerful. In Cacti it is possible to access graphs provided specificly for different individuals and companies with their own username.

Here is our environment:

OS: CentOS 7 linux on VMWare
IP address: 192.168.26.129
Firewall: CSF
Selinux: Permissive

1- Install prerequisits

To launch the Cacti service, you first need to have the software package installed . It is as follows and is done with the following command.
first install mariadb. to know about installing, refer to Database replication with mariadb on CentOS 7 linux

# yum install httpd httpd-devel php-mysql php-pear phpcommon php-gd php-devel php php-mbstring php-cli php-snmp net-snmp-utils net-snmp-libs rrdtool

After all the said software packages have been installed, we will enable Mariadb, SNMP and Apache services with the following commands:

# systemctl enable mariadb
# systemctl enable httpd
# systemctl enable snmpd
# systemctl start mariadb
# systemctl start httpd
# systemctl start snmpd

2- Install cacti

After installing prerequisits, install Epel repository with the command below and install Cacti:

# yum install epel-release
# yum install cacti

3- Configuring database

now it is time to apply the settings to Mariadb as follows. but first wee need to set root password for mysql:

# mysql_secure_installation

then after login to mariadb and create required database:

# mysql -u root -p
# create database cacti;
# ALTER DATABASE cacti CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
# GRANT ALL ON *.* TO cacti@localhost IDENTIFIED BY 'your password';
# FLUSH privileges;
# quit;

Then, the Cacti tables in Mysql should be created which can be executed using the following command. First we need to find the database file path:

# rpm -ql cacti | grep cacti.sql
# mysql -u root -p cacti < /usr/share/doc/cacti-1.2.6/cacti.sql
# mysql -u root -p mysql < /usr/share/mysql/mysql_test_data_timezone.sql

And then we have to apply these settings on Mysql as follows:

# vim /etc/cacti/db.php

And apply the following changes to it:

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

then put the following line in /etc/my.cnf.d/server.cnf below [mysqld] directive:

# vim /etc/my.cnf.d/server.cnf
collation-server = utf8mb4_unicode_ci
init-connect='SET NAMES utf8mb4'
character-set-server = utf8mb4
max-heap-table-size = 29m
tmp-table-size = 29m
join-buffer-size = 58m
innodb-buffer-pool-size = 1g
innodb-flush-log-at-timeout = 3
innodb-read-io-threads = 32
innodb-write-io-threads = 16
innodb-buffer-pool-instances = 11
innodb-io-capacity = 5000
innodb-io-capacity-max = 10000

then restart mariadb:

# systemctl restart mariadb

4- Configuring firewall

Here we use csf as firewall and since cacti is a Web-based service, then port 80 must be open on the firewall. to know how to install and configure csf please refer to How to install CSF on CentOS 7 Linux

5- Configuring apache and php

Then it’s time to make adjustments to the Apache web server so that we can access from our local network

# vim /etc/httpd/conf.d/cacti.conf
Alias /cacti /usr/share/cacti
<Directory /usr/share/cacti/>
Order Deny,Allow
Allow from all
</Directory>

open /etc/php.ini and set the following parameters as specified:

# vim /etc/php.ini
memory_limit = 800M
max_execution_time = 60
date.timezone = Europe/Zagreb (set timezone to your own zone)

set owner of cacti files to apache:

# chown apache:apache /usr/share/cacti/*

Finally we restart the Apache service:

# systemctl restart httpd

6- Configuring cron

open the Cacti Cron file located in the path /etc/cron.d/cacti to apply the scheduling settings and activate the following line to script related to Poller.php script run every five minutes and collect the data:

# vim /etc/cron.d/cacti
*/5 * * * * cacti /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1

7- Configuring cacti

Startup settings are over here, it’s time to connect to the cacti web interface and continue the settings from the panel:

http://192.168.26.129/cacti/

install-cacti-1

 

username & password: admin

login and set new password for admin account. then check the box “Accept GPL License Agreement”.
then click begin. in next page, make sure all pre-installation checks are green:

install-cacti-2

then click next and select “new primary server”, then click next. make sure Directory Permission Checks are green then click next.
also make sure “Critical Binary Locations and Versions” checks are green, then click next.
set “Network Range” to what you want and click next. again click next and then next.
finally check “Confirm Installation” box and then click install button.
after completing installation, you will see cacti console as below:

cacti main console