Install Cacti on CentOS 7– The Definitive Guide in 2017

 

Cacti is one of the most robust  monitoring tool available in the market. It has a lot of features and options that able to give you a complete visibility for your infrastructure. In this guide I will walk through installing Cacti on CentOS 7, Configuring the MariaDB (The new Database for the CentOS 7 ), Adding few devices and finally plotting the result. Also  I will cover some troubleshooting points during the configuration. So Let’s start

  clip_image024

Installation Steps

Step 1: Modify the date to be UTC instead of EET or any other format (cacti may print an error you don’t do that)

#rm -f /etc/localtime
#ln -s /usr/share/zoneinfo/UTC /etc/localtime
[root@nom-cs2 ~]# date
Tue Feb 28 13:37:53 UTC 2017 

Step 2:  Install Supplementary packages (Apache, DB,..etc)

# yum install httpd httpd-devel mariadb-server \

php-mysql php-pear php-common php-gd php-devel \

php php-mbstring php-cli epel-release -y

 

Step 3:  Now install the rrdtool (which is graphing backend for cacti)

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

 

Step 4:  Start the Services and Enable them at boot time

systemctl start httpd.service

systemctl start mariadb.service

systemctl start snmpd.service

systemctl enable httpd.service

systemctl enable mariadb.service

systemctl enable snmpd.service

 

Step 5:  Setup MariaDB password for the root username

mysqladmin -u root password access123

Step 6:  Create Cacti DB and create a cacti username

mysql -u root -p

Password: <access123>

MariaDB [(none)]> create database cacti;

MariaDB [(none)]> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'access123';

MariaDB [(none)]> FLUSH privileges;

MariaDB [(none)]> quit;

Step 7:  Install Cacti from Epel Release

 

yum install cacti –y

Step 8:  Import the tables into the Cacti DB

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

Step 9: Edit the Cacti DB Configuration

 

vim /etc/cacti/db.php

$database_type = "mysql";

$database_default = "cacti";

$database_hostname = "localhost";

$database_username = "cacti";

$database_password = "access123";

$database_port = "3306";

$database_ssl = false;

Step 10: Configure HTTP Access

vim /etc/httpd/conf.d/cacti.conf

 

<Directory /usr/share/cacti/>

<IfModule mod_authz_core.c>

# httpd 2.4

#Require host localhost

Require all granted

#Require host 192.168.1.0/24

</IfModule>

<IfModule !mod_authz_core.c>

# httpd 2.2

Order deny,allow

Deny from all

Allow from all

#Allow from 192.168.1.0/24

</IfModule>

</Directory>

Step 11:  Restart HTTPD process for the change to take effect

systemctl restart httpd.service

Step 12:  Create the log file where the cacti will store and write it’s file

mkdir -p /var/log/cacti

Step 13:  Create the Log File inside the above directory

cd /var/log/cacti/

touch cacti.log

Step 14:  Uncomment the Cron Job for the poller in the following file

vim /etc/cron.d/cacti

Step 15:  Go to http://YOUR-IP-ADDRESS/cacti/ and just follow the Installer instruction, Just simple steps and series of Next

clip_image001

clip_image002

clip_image003

Default Login is admin/admin

clip_image004

Step 16:  Change the Permission on installation to 777 for all files to avoid any errors (I know may be not the smart thing in production environment)

 

cd /usr/share/cacti/

chmod 777 -R *

Step 17: Test the CMD and Poller scripts

php /usr/share/cacti/cmd.php

php /usr/share/cacti/poller.php

Step 18:  Add New Device

clip_image005

clip_image006

clip_image007

Now that the device has been added, we specify the graph templates that we want to create. This section can be found in the bottom section of the page and this a suggestion from Cacti to the added host.

clip_image008

clip_image009

Select all available Templates and click on Create

clip_image010

Then choose the legend for each created graph and then click on create

clip_image011

clip_image012

Also you can Create a new Graph from available ones

clip_image013

Cisco Router

clip_image014

clip_image015

clip_image016 

Note: It takes around 15 minutes for Cacti to populate new graphs. There are not alternatives to being patient.

You can create a graph Tree

clip_image018

clip_image019

clip_image020

clip_image021

Add Graphs to created Header

clip_image022

Final View

clip_image023

clip_image024

CPU Graphing

CPU can exceed the value of 100% if you’ve multiple cores in your servers and hence a value of nan will be shown in your graph

Here’s how to fix it and get it working. First Navigate to the following Path

Console> Data Templates > CPU Templates

clip_image025

Increase this value to cover all of your cores

clip_image026

Also fix the values in your rrd files

cd /usr/share/cacti/rra

rrdtool tune localhost_cpu_nice_12.rrd --maximum cpu_nice:900%

rrdtool tune localhost_cpu_user_14.rrd --maximum cpu_user:900%

rrdtool tune localhost_cpu_system_13.rrd --maximum cpu_system:900%

Repeat for Memory Template

clip_image027

Also it’s worth to go to RR directory inside the cacti and change the permissions  to 777 (Again, Dont do that in production)

[root@nom-cs2 rra]# ls -htlr

total 620K

-rwxrwxrwx. 1 cacti cacti 47K Feb 28 19:00 cactiserver_cpu_user_13.rrd

-rwxrwxrwx. 1 cacti cacti 47K Feb 28 19:00 cactiserver_cpu_system_12.rrd

-rwxrwxrwx. 1 cacti cacti 47K Feb 28 19:00 cactiserver_cpu_user_10.rrd

-rwxrwxrwx. 1 cacti cacti 47K Feb 28 19:00 cactiserver_cpu_system_9.rrd

-rwxrwxrwx. 1 cacti cacti 47K Feb 28 19:00 cactiserver_cpu_nice_8.rrd

-rwxrwxrwx. 1 cacti cacti 47K Feb 28 19:00 cactiserver_cpu_nice_11.rrd

-rwxrwxrwx. 1 cacti cacti 47K Feb 28 19:00 cactiserver_mem_buffers_14.rrd

-rwxrwxrwx. 1 cacti cacti 47K Feb 28 19:00 cactiserver_mem_swap_15.rrd

-rwxrwxrwx. 1 cacti cacti 139K Feb 28 19:00 cactiserver_load_1min_16.rrd

-rwxrwxrwx. 1 cacti cacti 47K Feb 28 19:00 cactiserver_users_17.rrd

-rwxrwxrwx. 1 cacti cacti 47K Feb 28 19:00 cactiserver_proc_18.rrd

Finally You can Find Database size that consumed by the cacti till now

mysql -u cacti -p

Enter password:<access123>

SELECT table_schema "cacti",

Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB"

FROM information_schema.tables

GROUP BY table_schema;

+--------------------+---------------+

| cacti | DB Size in MB |

+--------------------+---------------+

| cacti | 0.6 |

| information_schema | 0.1 |

+--------------------+---------------+

Client Host Configuration

In this section, I will guide you through configuring the  clients with SNMP configuration so they will be ready to be connected with Cacti

Step 1: Install SNMP

yum install net-snmp

Step 2: Enable the SNMP on client host

mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.old

echo "rocommunity public" > /etc/snmp/snmpd.conf

service snmpd restart

chkconfig snmpd on

Step 3: Make sure you can get all SNMP OIDs  by running the below command

snmpwalk -c public 127.0.0.1 -v1

Or use SNMP Version2

snmpwalk -c public 127.0.0.1 -v2c

If you need to add additional security to monitoring by specifying only the cacti host, add the below line

vim /etc/snmp/snmpd.conf

Step 1:  First, map the community name “public” into a “security name”

com2sec local localhost public

com2sec mynetwork 41.234.66.0/25 public

Step 2: map the security name into a group name:

group MyRWGroup v1 local

group MyRWGroup v2c local

group MyROGroup v1 mynetwork

group MyROGroup v2c mynetwork

Step 3: create a view for us to let the group have rights to:

# incl/excl subtree mask

view all included .1 80

Step 4:  Finally, grant the group read-only access to the systemview view.

# group context sec.model sec.level prefix read write notif

access MyROGroup "" any noauth exact all none none

access MyRWGroup "" any noauth exact all all none

syslocation Linux, Home Linux Router.

syscontact BasimAly <basim.alyy@gmail.com>

Step 5: Restart the service

service snmpd restart

 

That’s it. I hope this has been informative for your and I’d like to thank you for reading.

Advertisements

Share you opinion to benefit others :)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s