How to install Cacti Network and performance monitoring tool using CentOS 7

Cacti is one of best monitoring tool used to monitor network, CPU load, memory, Disk and other services and the same in the x86 servers running Windows and Linux OS’es. Cacti uses PHP for front end, RRDTool for graphing and mariadb to store the reporting graph for storage. Cacti installation on centos requires LAMP setup and SNMP. Before installing cacti, first we need to setup httpd or apache with php, mariadb and SNMP services. In this article we will use CentOS 7 this is the latest release as of writing this post.

Before we start make sure you disable the SELINUX if your not familiar on this better disable it now then reboot your server after the change is done

[[email protected] home]# vim /etc/selinux/config

Change it from SELINUX=permissive to SELINUX=disabled

Requirements:

The Cacti required following packages to be installed on your Linux operating systems like RHEL / CentOS / Fedora.

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

Step 1: Install the packages needed to run the Cacti such as the mariadb aka mysql, php and the httpd aka apache.

[[email protected]~]# yum install mariadb mariadb-server php php-mysql httpd httpd-devel

cacti_01

and then press “y” in your keyboard then press ENTER after that it will install all the required packages needed

cacti_02

 

Step 2: Configure the mariadb and httpd to auto run their services in system startup this is helpful when the system reboots then no need to manually run the script to run again.

systemctl enable mariadb.service -This is to enable the service mariadb in startup

[[email protected] ~]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[[email protected] ~]#

cacti_03

systemctl enable httpd.service – This is to enable the service httpd in startup

[[email protected] ~]# systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[[email protected] ~]#

cacti_04

Then now start both the services by typing

[[email protected]~]# systemctl start httpd.service
[[email protected]~]# systemctl status httpd.service
[[email protected]~]# systemctl start mariadb.service
[[email protected]~]# systemctl status mariadb.service

cacti_04

Step 3: Configure the root password of the mariadb database

[[email protected]~]# mysqladmin -u root password ‘abcde12345’

and issue the below command to secure the mariadb database

[[email protected]~]# /usr/bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 ... Failed!  Not critical, keep moving...
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[[email protected]~]#

cacti_08

Step 4: Create database that will be use to store all the data of Cacti. In mariadb database we will create a name called ‘cactidb’ but first login in mariadb using the command below

[[email protected] ~]# mysql -u root -p

cacti_09

now create the dabatase called ‘cactidb’ using the commands “create database cactidb” and “grant all on cactidb.* to [email protected] identified by ‘abcde12345’ and then “flush priviledge” this command is to apply all the command changes for this creation.

MariaDB [(none)]> create database cactidb;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]>
MariaDB [(none)]> grant all on cactidb.* to [email protected] identified by 'abcde12345';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]>

cacti_10
cacti_11

 

Step 5: Install the SNMP RPM package using the command below. The SNMP is use to capture all the necesarry information in the server or network devices such as  cpu, memory, hardisk, port usage and etc. The SNMP agent receives requests on UDP port 161. The manager may send requests from any available source port to port 161 in the agent. The agent response will be sent back to the source port on the manager. The manager receives notifications (Traps and InformRequests) on port 162.

[[email protected]~]# yum install net-snmp-utils php-snmp net-snmp-libs

cacti_12a

After installation is competed we can configure the “/etc/snmp/snmpd.conf” file

[[email protected] ~]# cd /etc/snmp/
[[email protected] snmp]# ls
snmpd.conf  snmptrapd.conf
[[email protected] snmp]# mv snmpd.conf snmpd.conf.org
[[email protected] snmp]# cp -rp snmptrapd.conf snmptrapd.conf.org

After now create a file called snmpd.conf by doing below command and then vim to edit the file

[[email protected] snmp]#  touch snmpd.conf
[[email protected] snmp]#  vim snmpd.conf

and this is what will be inside

com2sec local  localhost       public

####
# Second, map the security name into a group name:

#       groupName      securityModel securityName
#group   notConfigGroup v1           notConfigUser
#group   notConfigGroup v2c           notConfigUser
group   MyReadWriteGP v1        local
group   MyReadWriteGP v2c       local


####
# Third, create a view for us to let the group have rights to:

# Make at least  snmpwalk -v 1 localhost -c public system fast again.
#       name           incl/excl     subtree         mask(optional)
#view    systemview    included   .1.3.6.1.2.1.1
#view    systemview    included   .1.3.6.1.2.1.25.1.1
view    all     included  .1

####
# Finally, grant the group read-only access to the systemview view.

#       group          context sec.model sec.level prefix read   write  notif
#access  notConfigGroup ""      any       noauth    exact  systemview none none
access  MyReadWriteGP ""      any       noauth    exact all     all      none

syslocation Unknown (edit /etc/snmp/snmpd.conf)
#syscontact Root <[email protected]> (configure /etc/snmp/snmp.local.conf)
syscontact francis <[email protected]> (configure /etc/snmp/snmp.local.conf)

 

Step 6: Enable the snmpd service to auto start on startup and start the service now by doing the command below

[[email protected] snmp]# systemctl enable snmpd.service
[[email protected] snmp]# systemctl start snmpd.service

[[email protected] snmp]# systemctl enable snmpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/snmpd.service to /usr/lib/systemd/system/snmpd.service.
[[email protected] snmp]#
[[email protected] snmp]# systemctl start snmpd.service
[[email protected] snmp]# systemctl satus snmpd.service

cacti_14

Step 7: Run the command below to test if the snmpwalk can run successfully without any issue and you should see the assigned IP address of your server

[[email protected]~]# snmpwalk -v 1 -c public 127.0.0.1  IP-MIB::ipAdEntIfIndex

[[email protected]~]# snmpwalk -v 1 -c public 127.0.0.1  IP-MIB::ipAdEntIfIndex
IP-MIB::ipAdEntIfIndex.10.4.97.11 = INTEGER: 2
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
[[email protected] ~]#

cacti_15

 

INSTALLATION OF CACTI PACKAGE

Step 8: This is the Cacti application installation part in here, you need to install and enable EPEL Repository for Cacti. Once you’ve enabled repository. First, you need to download the file using wget and then install it using RPM on your system to enable the EPEL repository. Use below links based on your Linux OS versions. (Make sure you must be root user).

## RHEL/CentOS 7 64-Bit ##

[[email protected]~]# wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
[[email protected]~]# rpm -ivh epel-release-7-5.noarch.rpm

## RHEL/CentOS 6 32-Bit ##

[[email protected]~]# wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
[[email protected]~]# rpm -ivh epel-release-6-8.noarch.rpm

## RHEL/CentOS 6 64-Bit ##

[[email protected]~]# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[[email protected]~]# rpm -ivh epel-release-6-8.noarch.rpm

cacti_16

Now we are ready to install the Cacti application using yum

[[email protected]~]# yum install cacti

cacti_17

then it will confirm if you want to proceed installing the package using the repository that we just use

cacti_18

That’s it its done. In the next post we will continue to configure the Cacti Now click this link to go to next phase

 

1 Trackbacks & Pingbacks

  1. MyTechRepublic | mytechrepublic.com

Leave a comment

Your email address will not be published.