Site is Under Maintenance
Please come back again in...
00 Days
00 Hours
00 Minutes
00 Seconds

How to Install Cacti on CentOS 6


Cacti is a popular open-source Network Management Software (NMS) that utilizes RRDTool for data storage and graphing capabilities. As a web-based application released under the GNU General Public License, it is completely free to use. Cacti is compatible with various operating systems, including Windows, Linux, and Solaris, but deploying it on Linux provides an effective and cost-free NMS solution. In this tutorial, I will guide you through the installation of Cacti on a CentOS 6 server.

1. Prerequisites

Cacti requires MySQL, PHP, RRDTool, net-snmp, and a web server that supports PHP such as Apache (Linux) or IIS (Windows). 

First, we need to install Apache to serve our HTTP requests, as such:

# yum install httpd httpd-devel

Now, install MySQL for the database:

# yum install mysql mysql-server

And, don't forget to install PHP:

# yum install php-mysql php-pear php-common php-gd php-devel php php-mbstring php-cli php-mysql

And go ahead and install SNMP for support:

# yum install php-snmp
# yum install net-snmp-utils p net-snmp-libs php-pear-Net-SMTP

Now if you like pretty colorful graphs, install RRDTool, as such:

# yum install rrdtool

Once you have installed everything, we can now start up the services:

# service httpd start
# service mysqld start
# service snmpd start

After reboot, you will have to manually start them again, so it's better to change this option to have the services auto-start upon reboot:

# chkconfig httpd on
# chkconfig mysqld on
# chkconfig snmpd on

You can install Cacti from a repository or compile it yourself. To save time, we'll use the EPEL repository:

# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm

Now, we are ready to install Cacti:

# yum install cacti

Apache, MySQL, and SNMP are now running, and Cacti has been installed. The next step will be to configure MySQL to prepare for Cacti.

2. MySQL Configuration

Because we just installed MySQL, we still have to set a password for the MySQL server. We also have to create a new database for Cacti to connect to and create a new user account for that:

# mysqladmin -u root password MYPASSWORD

The MySQL server now has a password. Let's login and create a database and user account.

Note: The default Cacti Web User ID is admin with a password of admin. You will be forced to change it upon initial login to the Cacti web UI.
# mysql -u root -p
Enter password: MYPASSWORD
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.1.69 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> create database cacti;
Query OK, 1 row affected (0.01 sec)

mysql> grant all on cacti.* to cacti@localhost identified by 'MYPASSWORD';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

We have a new database called 'cacti' and a username called 'cacti.' The database is there, but it's empty. We'll import a file from the Cacti installation packet and import it into the database. First, however, we need to find out where it is located:

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

In my case, it's located in the folder above. We'll import this SQL file into the database, as such:

# mysql -u cacti -p cacti < /usr/share/doc/cacti-0.8.8a/cacti.sql 

This will find the database. Now, we need to edit the database configuration file of Cacti so that it uses the correct database name and username:

# vi /etc/cacti/db.php

As you may have noticed, I'm using vi as my text editor. Below, you will find the part that we are looking for:

/* 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 = "cacti";
$database_port = "3306";
$database_ssl = false;

Make sure it reflects your database name and username/password you created. When you are done, save the file and exit your text editor. We still have yet to configure Apache.

3. Apache Configuration

We can change the Apache configuration to choose what IP addresses or subnets that are allowed to connect. We can do this by editing the following file:

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

This is the part we are looking for:

<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>

I will now change the "Allow from localhost" to "Allow from all" so that I can access Cacti from any IP address:

Allow from all

If you are installing Cacti for a production environment, then it's recommended to ensure security by only selecting a specific range of IP addresses vice full zones or ranges, as such:

Allow from 192.168.1.0/24

Once you are done, save your configuration and exit your text editor. Also, don't forget to restart the Apache service:

# service httpd restart

MySQL and Apache are now up and running. The last thing to do is enable a cron job. This will allow Cacti to collect information from network devices.

4. Configuring a Cron Job

By default, Cron will collect data from devices every 5 minutes, but the cron job is disabled by default, so we'll go ahead and enable it:

# vi /etc/cron.d/cacti

You will find the line below:

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

Remove the # so that it looks like this:

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

Save your changes and exit your text editor. We can now access the web installer!

5. Configuring Cacti

You can access the GUI from your web browser using http://YOUR-IP/cacti. It will look similar to this:

Click on Next and choose a new installation:


Cacti will show you an installation guide checklist. At this point, everything should be good to go now.


Just click on Finish, and you will be presented with the login screen:


As stated above, the default username and password are admin/admin. Hit the login button and you will be prompted to change your password:


After changing your password and saving it, you will be rewarded with this main screen:


Cacti is now installed and with some minor tweaks and settings configurations, Cacti is ready to monitor! Add some devices and explore Cacti. I hope this tutorial has been helpful to you in installing Cacti on your CentOS server.

Happy Installing Cacti on your CentOS server!



Rate This Article

Thanks for reading: How to Install Cacti on CentOS 6, Sorry, my English is bad:)

Getting Info...

About the Author

I'm Aevon...Just a gal with an insane passion for all things cybersecurity. 17 years in the industry and still love what I'm doing.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.