How To Install Cacti (Network Monitoring) in Linux

To Install Cacti (Network Monitoring) on RHEL/CentOS 7.x/6.x/5.x and Fedora 21-12

Cacti is an open-source, web-based network monitoring and graphing tool. It is used to graph time-series data of CPU load and network bandwidth utilization. Installation of Cacti on RHEL/CentOS and Fedora is explained in this article in detail.

Requirements

Apache : A Web server to display network graphs created by PHP and RRDTool.
MySQL : A Database server to store cacti information.
RRDTool : A database tool to manage and retrieve time series data like CPU load, Network Bandwidth etc.
PHP : A script module to create graphs using RRDTool.
PHP-SNMP : A PHP extension for SNMP to access data.
NET-SNMP : A SNMP (Simple Network Management Protocol) is used to manage network.

To Install Cacti Required Packages

For RHEL / CentOS / Fedora

Install the following dependency packages one-by-one using YUM package manager tool.

To Install Apache

[root@linuxhelp1 Desktop]# yum install httpd httpd-devel -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Resolving Dependencies
-->  Running transaction check
--->  Package httpd.x86_64 0:2.4.6-40.el7.centos.1 will be installed
.
.
Complete!

Install MariaDB

RedHat makes a new transaction from MySQL to MariaDB, as MariaDB is the default implementation of MySQL in RHEL/CentOS 7.x and Fedora 19 onwards.

[root@linuxhelp1 Desktop]# yum install mariadb-server -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Resolving Dependencies
-->  Running transaction check
--->  Package mariadb-server.x86_64 1:5.5.47-1.el7_2 will be installed
.
.
.
Installed:
  mariadb-server.x86_64 1:5.5.47-1.el7_2                                                                          

Dependency Installed:
  mariadb.x86_64 1:5.5.47-1.el7_2                         perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7            
  perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7             perl-DBD-MySQL.x86_64 0:4.023-5.el7                     
  perl-DBI.x86_64 0:1.627-4.el7                           perl-IO-Compress.noarch 0:2.061-2.el7                   
  perl-Net-Daemon.noarch 0:0.48-5.el7                     perl-PlRPC.noarch 0:0.2020-14.el7                       

Complete!

To Install PHP

Run the following command, to install PHP and its modules.

[root@linuxhelp1 Desktop]# yum install php-mysql php-pear php-common php-gd php-devel php php-mbstring php-cli -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Resolving Dependencies
-->  Running transaction check
--->  Package php.x86_64 0:5.4.16-36.1.el7_2.1 will be installed
--->  Package php-cli.x86_64 0:5.4.16-36.1.el7_2.1 will be installed
.
.
.
Installed:
  php.x86_64 0:5.4.16-36.1.el7_2.1                       php-cli.x86_64 0:5.4.16-36.1.el7_2.1                    
  php-common.x86_64 0:5.4.16-36.1.el7_2.1                php-devel.x86_64 0:5.4.16-36.1.el7_2.1                  
  php-gd.x86_64 0:5.4.16-36.1.el7_2.1                    php-mbstring.x86_64 0:5.4.16-36.1.el7_2.1               
  php-mysql.x86_64 0:5.4.16-36.1.el7_2.1                 php-pear.noarch 1:1.9.4-21.el7                          

Dependency Installed:
  libzip.x86_64 0:0.10.1-8.el7                          pcre-devel.x86_64 0:8.32-15.el7_2.1                      
  php-pdo.x86_64 0:5.4.16-36.1.el7_2.1                  php-process.x86_64 0:5.4.16-36.1.el7_2.1                 
  php-xml.x86_64 0:5.4.16-36.1.el7_2.1                  t1lib.x86_64 0:5.1.2-14.el7                              

Complete!

To Install PHP-SNMP

Execute the following command to install PHP-snmp

[root@linuxhelp1 Desktop]# yum install php-snmp -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Resolving Dependencies
-->  Running transaction check
--->  Package php-snmp.x86_64 0:5.4.16-36.1.el7_2.1 will be installed
.
.
.                                               
Dependency Installed:
  net-snmp.x86_64 1:5.7.2-24.el7_2.1                 net-snmp-agent-libs.x86_64 1:5.7.2-24.el7_2.1                

Complete!

To Install NET-SNMP

Execute the following command to install NET-snmp

[root@linuxhelp1 Desktop]# yum install net-snmp-utils net-snmp-libs -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Package 1:net-snmp-libs-5.7.2-24.el7_2.1.x86_64 already installed and latest version
Resolving Dependencies
-->  Running transaction check
--->  Package net-snmp-utils.x86_64 1:5.7.2-24.el7_2.1 will be installed
.
.
.
Installed:
  net-snmp-utils.x86_64 1:5.7.2-24.el7_2.1                                                                        

Complete!

To Install RRDTool

Execute the following command to install rrdtool

[root@linuxhelp1 Desktop]# yum install rrdtool -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Resolving Dependencies
-->  Running transaction check
--->  Package rrdtool.x86_64 0:1.4.8-9.el7 will be installed
.
.
.
Installed:
  rrdtool.x86_64 0:1.4.8-9.el7                                                                                    

Complete!

To Start Apache, MySQL and SNMP Services

Start the software one-by-one using following commands.

For RHEL/CentOS 6.x/5.x and Fedora 18-12

[root@linuxhelp ~]# service httpd start
[root@linuxhelp ~]# service mysqld start
[root@linuxhelp ~]# service snmpd start

For RHEL/CentOS 7.x and Fedora 19 Onwards

[root@linuxhelp1 Desktop]# systemctl start httpd.service
[root@linuxhelp1 Desktop]# systemctl start mariadb.service
[root@linuxhelp1 Desktop]# systemctl start snmpd.service

Configure Start-up Links

To Configure Apache, MySQL and SNMP Services to start on boot.

For RHEL/CentOS 6.x/5.x and Fedora 18-12

# /sbin/chkconfig --levels 345 httpd on
# /sbin/chkconfig --levels 345 mysqld on
# /sbin/chkconfig --levels 345 snmpd on

For RHEL/CentOS 7.x and Fedora 19 Onwards

[root@linuxhelp1 Desktop]# systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@linuxhelp1 Desktop]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@linuxhelp1 Desktop]# systemctl enable snmpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/snmpd.service to /usr/lib/systemd/system/snmpd.service.

To Install Cacti on RHEL/CentOS/Fedora

Install and enable EPEL Repository.After enabling repository, type the following command to install Cacti application.

[root@linuxhelp1 Desktop]# yum install epel-release -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Resolving Dependencies
-->  Running transaction check
--->  Package epel-release.noarch 0:7-6 will be installed
.
.
.
Installed:
  epel-release.noarch 0:7-6                                                                                       

Complete!

[root@linuxhelp1 Desktop]# yum install cacti -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * epel: epel.mirror.net.in
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Resolving Dependencies
-->  Running transaction check
--->  Package cacti.noarch 0:0.8.8h-1.el7 will be installed
.
.
.
Installed:
  cacti.noarch 0:0.8.8h-1.el7                                                                                     

Complete!

To Configure MySQL Server for Cacti Installation

To configure MySQL for Cacti, set password for the newly installed MySQL server and then create Cacti database with user Cacti. If MySQL is already password protected, then don’ t assign it again.

To Set MySQL Password

Use the following command, to set new password for MySQL server
This is for new MySQL installation only.

[root@linuxhelp1 Desktop]# mysqladmin -u root password linuxc

To Create MySQL Cacti Database

Now Login into MySQL server with the newly created password and create Cacti database with user Cacti and set the password for it.

For RHEL/CentOS 6.x/5.x and Fedora 18-12

[root@linuxhelp1 Desktop]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with   or g.
Your MariaDB connection id is 3
Server version: 5.5.47-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]>  create database cacti 
Query OK, 1 row affected (0.08 sec)

MariaDB [(none)]>  GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY ' linuxc'  
Query OK, 0 rows affected (0.03 sec)

MariaDB [(none)]>  FLUSH privileges 
Query OK, 0 rows affected (0.03 sec)

MariaDB [(none)]>  q 
Bye

For RHEL/CentOS 7.x and Fedora 19 Onwards

[root@linuxhelp1 Desktop]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with   or g.
Your MariaDB connection id is 3
Server version: 5.5.47-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]>  create database cacti 
Query OK, 1 row affected (0.08 sec)

MariaDB [(none)]>  GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY ' linuxc'  
Query OK, 0 rows affected (0.03 sec)

MariaDB [(none)]>  FLUSH privileges 
Query OK, 0 rows affected (0.03 sec)

MariaDB [(none)]>  q 
Bye

To Install Cacti Tables in MySQL

Now Find out the database file path by executing RPM commands and to install cacti tables into newly created Cacti database, use the following command.

[root@linuxhelp1 Desktop]# rpm -ql cacti | grep cacti.sql
/usr/share/doc/cacti-0.8.8h/cacti.sql

Type the following command to install tables and type the Cacti user password.

[root@linuxhelp1 Desktop]# mysql -u cacti -p cacti <  /usr/share/doc/cacti-0.8.8h/cacti.sql
Enter password:

To Configure MySQL settings for Cacti

Open the file called /etc/cacti/db.php with any editor.

[root@linuxhelp1 Desktop]# vim /etc/cacti/db.php

Add the following changes and save the file and set password.

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

To Configure Firewall for Cacti

For RHEL/CentOS 6.x/5.x and Fedora 18-12

# iptables -A INPUT -p udp -m state --state NEW --dport 80 -j ACCEPT
# iptables -A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
# service iptables save

For RHEL/CentOS 7.x and Fedora 19 Onwards

[root@linuxhelp1 Desktop]# firewall-cmd --permanent --zone=public --add-service=http
success
[root@linuxhelp1 Desktop]# firewall-cmd --reload
success

To Configure Apache Server for Cacti Installation

Open a file called /etc/httpd/conf.d/cacti.conf with the choice of editor.

[root@linuxhelp1 Desktop]# vim /etc/httpd/conf.d/cacti.conf

Enable access to Cacti application for your local network or per IP level.

Alias /cacti    /usr/share/cacti
< 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 the Apache service.

On RHEL/CentOS 6.x/5.x and Fedora 18-12

# service httpd restart

On RHEL/CentOS 7.x and Fedora 19 onwards

[root@linuxhelp1 Desktop]# systemctl restart httpd.service

To Set Cron for Cacti

Open file /etc/cron.d/cacti.

[root@linuxhelp1 Desktop]# vim /etc/cron.d/cacti
And uncomment the following line. The poller.php script runs every 5mins and collects data of known host which is used by Cacti application to display graphs.

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

To Run Cacti Installer Setup

Navigate to http://YOUR-IP-HERE/cacti/ & follow the installer instruction through the following screens and hit Next button.

Choose installation Type as " New Install" .

Before continuing make sure all the following values are correct and hit Finish button.

In Cacti Login Screen, enter username as admin and password as admin.

Now enter a new password for cacti.

Cacti Console Screen appears.

To Create New Graphs

To generate graphs, Hit on New Graphs &rarr Select Host &rarr Select SNMP - Interface Statistics and Select a graph type In/Out Bits. Hit on Create button.



Tag : Cacti
Comment
namgayongchuk
May 07 2018
FATAL: connection to cacti database failed.Please ensure the database is running and your credentials in config.php are valid.. This error message pops up and i cant connect with cacti..what is the problem
Add a comment
FAQ
Q
what are all the requirements to install cacti in linux?
A
Apache : A Web server to display network graphs created by PHP and RRDTool.
MySQL : A Database server to store cacti information.
RRDTool : A database tool to manage and retrieve time series data like CPU load, Network Bandwidth etc.
PHP : A script module to create graphs using RRDTool.
PHP-SNMP : A PHP extension for SNMP to access data.
NET-SNMP : A SNMP (Simple Network Management Protocol) is used to manage network.
Q
where download the latest version of cacti?
A
use the following link for download the latest version of cacti
https://www.cacti.net/download_cacti.php
Q
what are the other similar package like cacti?
A
You can see the following list

Solarwinds NPM
PRTG
ManageEngine OpManager
Nagios
Q
where to get full documentation for cacti?
A
refer the following link for documentation of cacti,
https://docs.cacti.net/
Q
does cacti is supported for windows?
A
yes, cacti will supported for windows