;

How to Install Cacti on CentOS 7

Try it in our public cloud & Get $5 Credit
CLAIM NOW

How to Install Cacti on CentOS 7

Cacti is a configurable, scalable network and resource monitoring system based on the RRDTool suite. It works on systems ranging from simple LAN installations, to multi data center LANs. Cacti provides user management, as well as acquisition of data from multiple sources in an easy-to-use interface. This guide sets up a Cacti installation on a CentOS 7 server.

Getting Started

To complete this guide, you will need the following:
• 1 Node (Cloud Server or Dedicated Server) running CentOS 7.

While good for learning how to set up Cacti on CentOS, it is better to install Cacti on a running server once you are familiar with the process, as monitoring is crucial for production-facing assets.

Tutorial

Let’s update all installed packages. Not only does this apply any known security fixes, but it also resolves issues in the base CentOS system.

yum update -y

Cacti depends on Apache, PHP, the MariaDB MySQL fork, and the associated modules needed to make PHP and Apache work together. We’ll install those next.

yum install nano httpd httpd-devel mariadb-server php-mysql php-pear php-common php-gd php-devel php php-mbstring php-cli -y

SNMP is also crucial to the Cacti stack. We’ll install net-snmp, the php-snmp module so PHP can retrieve SNMP data, and finally rrdtool.

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

Let’s start bringing up the various components Cacti needs. We’ll begin by launching Apache, MariaDB and SNMP.

systemctl start httpd.service
systemctl start snmpd.service
systemctl start mariadb.service

All of these should be configured to start at boot. Here we configure these components to launch when the server starts.

systemctl enable httpd.service
systemctl enable snmpd.service
systemctl enable mariadb.service

We must now secure access to Cacti. Leaving monitoring solutions open to public viewing is a security risk. This next step adds password authentication for Cacti.

mysql_secure_installation

Cacti needs a database, which will now be created. We’ll also create a cacti user and grant it all database privileges.

mysql -u root -p
MariaDB> CREATE DATABASE cactidb;
MariaDB> CREATE USER 'cactiuser'@'localhost' IDENTIFIED BY 'cactipassword';
MariaDB> GRANT ALL PRIVILEGES ON cactidb.* TO 'cactiuser'@'localhost';
MariaDB> FLUSH PRIVILEGES;
MariaDB> exit

It is finally time to install Cacti itself.

yum install epel-release -y
yum install cacti -y

Cacti ships with a cacti.sql database dump that should be imported into MySQL. We need to find where it was stored in order to perform the import.

rpm -ql cacti|grep cacti.sql
/usr/share/doc/cacti-0.8.8h/cacti.sql

Now we’ll actually import the schema we’ve just found. This command loads the cacti.sql dump into the database we created previously.

mysql -u cactiuser -p cactidb < /usr/share/doc/cacti-0.8.8h/cacti.sql

Cacti needs to know how to connect to the database. We must add the database name and credentials to its database configuration file.

nano /etc/cacti/db.php
[...]
database_default = "cactidb";
database_hostname = "localhost";
database_username = "cactiuser";
database_password = "cactipassword";
[...]

Apache must be accessible from the network so we can view Cacti’s statistics. Edit /etc/httpd/conf.d/cacti.conf.

nano /etc/httpd/conf.d/cacti.conf

Change these two lines:

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

to:

<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 all
</IfModule>
</Directory>

Restart Apache so it picks up the configuration changes we’ve just made.

systemctl restart httpd.service

There is a crontab entry for Cacti that must be activated in order for it to create its graphs. Uncomment the line in /etc/cron.d/cacti.

nano /etc/cron.d/cacti

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

to:

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

In order for Cacti to log its results, we’ll need to create an empty cacti.log.

mkdir /var/log/cacti
touch /var/log/cacti/cacti.log

The remaining installation steps are done via the web interface. Visit http://your_ip/cacti to finish the process.

When prompted for a username and password, enter “admin” for both. These should be changed as soon as possible.

Conclusion

This CentOS 7 server is now being monitored by Cacti. While the results of monitoring an empty server are not terribly interesting, the true utility of monitoring becomes quickly apparent when it is used on a production server managing actual workloads. If this guide was helpful to you, kindly share it with others who may also be interested.