21
How To Install and Configure Cacti on Linux i | Page Contents Overview ....................................................................................................................................................... 1 Applies To...................................................................................................................................................... 1 Slideshare Documentation – Screenshots .................................................................................................... 1 Cacti NNM – Pre-requisites ........................................................................................................................... 1 Query – Packages Installed ........................................................................................................................... 1 Step 1: Install Packages ................................................................................................................................. 2 Install Apache2 .......................................................................................................................................... 2 Install MySQL ............................................................................................................................................ 3 Install Net-SNMP ....................................................................................................................................... 4 Install PHP ................................................................................................................................................. 5 Install PHP SNMP .................................................................................................................................. 6 List PHP – Configuration Files Loaded....................................................................................................... 7 Install RRDTool .......................................................................................................................................... 7 Step 2: Configure Apache Service (HTTPD) ................................................................................................... 7 Apache Service - Status ............................................................................................................................. 7 Apache Service - OS Startup Status........................................................................................................... 8 Apache Service – Modify OS Startup Status ............................................................................................. 8 Starting Apache Webserver ...................................................................................................................... 8 Configure Apache - ServerName............................................................................................................... 8 Step 3: Configure MySQL Service (mysqld) ................................................................................................... 9 MySQL Service - Status ............................................................................................................................. 9 MySQL Service - OS Startup Status ........................................................................................................... 9 MySQL Service – Modify OS Startup Status .............................................................................................. 9 Setup MySQL Database Server ................................................................................................................. 9 Connect MySQL Database ................................................................................................................... 10 Set MySQL root password ................................................................................................................... 10 MySQL Login – Root User.................................................................................................................... 10 Step 4: Configure SNMP Service ................................................................................................................. 11 Default SNMP Configuration ................................................................................................................... 11 Counting SNMP Line – Default Config................................................................................................. 11 Minimal SNMP Configuration ................................................................................................................. 11

How to Install and Configure Cacti on Linux

Embed Size (px)

Citation preview

Page 1: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti on Linux

i | P a g e

Contents

Overview ....................................................................................................................................................... 1

Applies To ...................................................................................................................................................... 1

Slideshare Documentation – Screenshots .................................................................................................... 1

Cacti NNM – Pre-requisites ........................................................................................................................... 1

Query – Packages Installed ........................................................................................................................... 1

Step 1: Install Packages ................................................................................................................................. 2

Install Apache2 .......................................................................................................................................... 2

Install MySQL ............................................................................................................................................ 3

Install Net-SNMP ....................................................................................................................................... 4

Install PHP ................................................................................................................................................. 5

Install PHP SNMP .................................................................................................................................. 6

List PHP – Configuration Files Loaded ....................................................................................................... 7

Install RRDTool .......................................................................................................................................... 7

Step 2: Configure Apache Service (HTTPD) ................................................................................................... 7

Apache Service - Status ............................................................................................................................. 7

Apache Service - OS Startup Status........................................................................................................... 8

Apache Service – Modify OS Startup Status ............................................................................................. 8

Starting Apache Webserver ...................................................................................................................... 8

Configure Apache - ServerName ............................................................................................................... 8

Step 3: Configure MySQL Service (mysqld) ................................................................................................... 9

MySQL Service - Status ............................................................................................................................. 9

MySQL Service - OS Startup Status ........................................................................................................... 9

MySQL Service – Modify OS Startup Status .............................................................................................. 9

Setup MySQL Database Server ................................................................................................................. 9

Connect MySQL Database ................................................................................................................... 10

Set MySQL root password ................................................................................................................... 10

MySQL Login – Root User .................................................................................................................... 10

Step 4: Configure SNMP Service ................................................................................................................. 11

Default SNMP Configuration ................................................................................................................... 11

Counting SNMP Line – Default Config ................................................................................................. 11

Minimal SNMP Configuration ................................................................................................................. 11

Page 2: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti on Linux

ii | P a g e

Create SNMP Configuration File ......................................................................................................... 11

Test SNMP Configuration .................................................................................................................... 11

Counting SNMP Line – Customized Config.......................................................................................... 11

SNMP Service - Status ............................................................................................................................. 12

SNMP Service - OS Startup Status ........................................................................................................... 12

SNMP Service – Modify OS Startup Status.............................................................................................. 12

Starting SNMP service ............................................................................................................................. 12

Step 4: Install RRDTool Package .................................................................................................................. 12

Step 5: Install Cacti Package ........................................................................................................................ 13

Configure MySQL for Cacti ...................................................................................................................... 13

Create and Configure cacti User ......................................................................................................... 13

Test MySQL connection – Cacti User .................................................................................................. 13

Find Cacti SQL Script ........................................................................................................................... 14

Import Cacti Database Table Script ..................................................................................................... 14

Verify Cacti Database Import Status ................................................................................................... 14

Configure cacti DB Connection Parameters ........................................................................................ 14

Edit DB Connection Parameters .......................................................................................................... 14

Configure Apache for Cacti ................................................................................................................. 15

Restart httpd Service .......................................................................................................................... 15

Set Cron job for cacti pooling .............................................................................................................. 16

Step 6: Cacti Monitoring Setup ................................................................................................................... 16

Tool Information ..................................................................................................................................... 16

Identify SNMP & RRDTool Versions .................................................................................................... 17

Launch Cacti Application ......................................................................................................................... 17

App Step 1 – Welcome screen ............................................................................................................ 17

App Step 2 – Installation Type ............................................................................................................ 17

App Step 3 – Executables Path ............................................................................................................ 18

App Step 4 – First Login....................................................................................................................... 19

App Step 5 – Reset Password (admin) ................................................................................................ 19

App Step 6 – Create Graphs ................................................................................................................ 19

Page 3: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti

1 | P a g e

Overview

Cacti tool is an open source web based network monitoring and system monitoring graphing solution for IT business.

Cacti enables a user to poll services status, performance of different devices viz., system, network, processes, etc. At regular intervals to create graphs on resulting data using RRDtool. By default data is pooled every 5 minutes.

Applies To

CentOS 6.x / RHEL 6.x

Slideshare Documentation – Screenshots

This documentation is available with screenshots at http://slideshare.net

Cacti NNM – Pre-requisites

Few of the major pre-requisites are;

Apache A Web server to display network graphs created by PHP and RRDTool.

MySQL A Database server to store cacti information.

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.

RRDTool A database tool to manage and retrieve time series data like CPU load, Network Bandwidth etc.

Query – Packages Installed

rpm -qa | grep ^httpd*

rpm -qa | grep ^mysql*

rpm -qa | grep ^net*

rpm -qa | grep ^php-*

rpm -qa | grep ^rrd*

Page 4: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti

2 | P a g e

Step 1: Install Packages

Apache2 yum install httpd httpd-devel

MySQL yum install mysql mysql-server

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

SNMP yum install net-snmp-utils php-snmp net-snmp-libs php-pear-Net-SMTP

RRD yum install rrdtool

Install Apache2

Install the Apache2 package using yum and dependent packages.

yum install httpd httpd-devel

Page 5: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti

3 | P a g e

Install MySQL

Install the MySQL package using yum and dependent packages.

yum install mysql mysql-server

Page 6: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti

4 | P a g e

Install Net-SNMP

Install the Net-SNMP package using yum and dependent packages.

yum install net-snmp-utils php-snmp net-snmp-libs php-pear-NET-SMTP

Page 7: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti

5 | P a g e

Install PHP

Install the PHP package using yum and dependent packages.

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

Page 8: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti

6 | P a g e

Install PHP SNMP

To install php snmp packages using yum and dependent packages.

yum install net-snmp-utils php-snmp net-snmp-libs php-pear-NET-SMTP

Page 9: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti

7 | P a g e

List PHP – Configuration Files Loaded

After installation, you can list the php configurations loaded, execute the command “php --ini”"

Output:

Install RRDTool

Install the RRDTool package using yum and dependent packages.

yum install rrdtool

Step 2: Configure Apache Service (HTTPD)

Apache Service - Status

Check the status of httpd, execute the command

service httpd status

Output:

httpdd service status:

httpd is stopped

Page 10: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti

8 | P a g e

Apache Service - OS Startup Status

Check the OS startup status of apache web server service, execute the command

chkconfig httpd --list

Output:

httpd service start-up setting:

httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off

Apache Service – Modify OS Startup Status

Modify OS startup status of apache web server; service to auto-start at levels (3, 4, 5) execute the command

chkconfig httpd on

Output:

httpd service start-up setting:

httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

Starting Apache Webserver

service httpd start

Output:

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.2.92 for ServerName

[ OK ]

Configure Apache - ServerName

vi /etc/httpd/conf/httpd.conf

Find and replace attribute value of “ServerName” to respective hostname or FQDN of the host and restart httpd service.

Example:

ServerName etpl01nm01pr.ftech.com

service httpd restart

Output:

Stopping httpd: [ OK ] Starting httpd: [ OK ]

After restarting httpd service, access in browser access the URL http://vcp01tst02pr.ftech.com/ or http://<IP Address> default apache page should be displayed.

Page 11: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti

9 | P a g e

Step 3: Configure MySQL Service (mysqld)

MySQL Service - Status

Check the status of mysql database, execute the command

service mysqld status

Output:

mysqld service status:

mysqld is stopped

MySQL Service - OS Startup Status

Check the OS startup status of mysql database service, execute the command

chkconfig mysqld --list

Output:

mysqld service start-up setting:

mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off

MySQL Service – Modify OS Startup Status

Modify OS startup of MySQL Database server; service to auto-start at levels (3, 4, 5) execute the command

chkconfig --levels 345 mysqld on

Output:

mysqld service start-up setting:

mysqld 0:off 1:off 2:off 3:on 4:on 5:on 6:off

Setup MySQL Database Server

When you start the mysqld daemon for the first time, default database would be created and further hardening can be considered later on.

service mysqld start

Output:

mysqld service starting:

Initializing MySQL database: Installing MySQL system tables... OK Filling help tables... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system

Page 12: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti

10 | P a g e

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h vcp01tst02pr password 'new-password'

Alternatively you can run:

/usr/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /usr ; /usr/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl

cd /usr/mysql-test ; perl mysql-test-run.pl Please report any problems with the /usr/bin/mysqlbug script!

[ OK ] Starting mysqld: [ OK ]

Connect MySQL Database

By default no password is set, you will be logged into mysql prompt. You can test by executing command; since we have already configured with root password. Without passing password to mysql command it will fail to connect.

mysql

mysql> \q

Set MySQL root password

To set MySQL root user password; execute the command

/usr/bin/mysqladmin -u root -h localhost password 'your-new-password' or /usr/bin/mysqladmin -u root -h vcp01tst02pr password 'your-new-password'

MySQL Login – Root User

mysql -uroot -proot123$

mysql> \q

Page 13: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti

11 | P a g e

Step 4: Configure SNMP Service

Default SNMP Configuration

No configuration changes are needed “/etc/snmp/snmpd.conf” file; to test execute the command

snmpwalk -v 1 -c public -O e 127.0.0.1 | head -1

Output:

SNMPv2-MIB::sysDescr.0 = STRING: Linux vcp01tst02pr 2.6.32-358.23.2.el6.x86_64 #1 SMP Wed Oct 16 18:37:12 UTC 2013 x86_64

Counting SNMP Line – Default Config

snmpwalk -v 1 -c public -O e 127.0.0.1 | wc -l

Output:

33

Minimal SNMP Configuration

Optionally, if you would like to customize or minimal configuration;

mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.original

Create SNMP Configuration File

vi /etc/snmp/snmpd.conf

Add the below lines;

rocommunity public

syslocation "VCP, Bangalore"

syscontact [email protected]

Test SNMP Configuration

snmpwalk -v 1 -c public -O e 127.0.0.1 | head -1

Output:

SNMPv2-MIB::sysDescr.0 = STRING: Linux vcp01tst02pr 2.6.32-358.23.2.el6.x86_64 #1 SMP Wed Oct 16 18:37:12 UTC 2013 x86_64

Counting SNMP Line – Customized Config

snmpwalk -v 1 -c public -O e 127.0.0.1 | wc -l

Output:

3304

Page 14: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti

12 | P a g e

SNMP Service - Status

Check the status of snmp service, execute the command

service snmpd status

Output:

snmpd service status:

snmpd is stopped

SNMP Service - OS Startup Status

Check the OS startup status of apache web server service, execute the command

chkconfig snmpd --list

Output:

snmpd service start-up setting:

snmpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off

SNMP Service – Modify OS Startup Status

Modify OS startup status of snmp; service to auto-start at levels (3, 4, 5) execute the command

chkconfig --levels 345 snmpd on

Output: snmpd service start-up setting: snmpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

Starting SNMP service

service snmpd start

Output: snmpd service starting: Starting snmpd: [ OK ]

Step 4: Install RRDTool Package

yum install rrdtool

Page 15: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti

13 | P a g e

Step 5: Install Cacti Package

yum install cacti

Configure MySQL for Cacti

In order to cacti to work, configuration have to be done, the steps are listed below.

Create and Configure cacti User

mysql -uroot -proot123$

mysql> create database cacti;

mysql> use cacti;

mysql> grant all privileges on *.* to cacti@localhost identified by 'cacti123$';

mysql> grant all privileges on *.* to cacti@vcp01tst02pr identified by 'cacti123$';

mysql> flush privileges;

mysql> \q

Test MySQL connection – Cacti User

mysql -ucacti -pcacti123$

mysql>

mysql> \q

Page 16: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti

14 | P a g e

Find Cacti SQL Script

rpm -ql cacti | grep "cacti.sql"

Output:

/usr/share/doc/cacti-0.8.8b/cacti.sql

Import Cacti Database Table Script

mysql -ucacti -pcacti123$ cacti < /usr/share/doc/cacti-0.8.8b/cacti.sql

Verify Cacti Database Import Status

mysql -ucacti -pcacti123$ -hlocalhost cacti

mysql> show tables;

Note: show tables; query should list 52 rows (tables).

Configure cacti DB Connection Parameters

To configure cacti application database connection parameters, update MySQL database connection parameters settings in the file

vi /etc/cacti/db.php

Edit DB Connection Parameters

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

Page 17: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti

15 | P a g e

Configure Apache for Cacti

In order to access cacti on web, edit and append below configuration lines the in file

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

Sample Configuration snippet: # # Add cacti alias and point the directory where cacti is installed. # Alias /cacti /usr/share/cacti # # Add cacti access restrictions from specific IP range / subnet # <Directory /usr/share/cacti/> Order Deny,Allow Deny from all Allow from 192.168.1.0/24 Allow from 192.168.2.0/24 </Directory>

Restart httpd Service

service httpd restart

Output:

Apache Service Restart: Stopping httpd: [ OK ] Starting httpd: [Fri Mar 18 21:15:23 2014] [warn] The Alias directive in /etc/httpd/conf.d/cacti.conf at line 59 will probably never match because it overlaps an earlier Alias.

[ OK ]

Note: In this case there are duplicate alias for “cacti”; so remove one of the aliases for defined cacti, save and restart apache service.

Page 18: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti

16 | P a g e

Set Cron job for cacti pooling

Cacti pools data every 5 minutes once, for pooling data cron job has be created, add the crontab entry as per the below line.

crontab -e

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

crontab -l

Note: data pooling is done via snmp; ensure SNMP is configured for the device / server that needs to be monitored on cacti.

Step 6: Cacti Monitoring Setup

Before you launch Cacti monitoring application, make sure you have installed all the required packages and their respective binaries exists.

For NET-SNMP & RRDTool identify the versions installed on the server, you can query for package installed, check “App Step 3 - Executables Path” section in “Launching Cacti”.

This information is required while configuring cacti application.

Tool Information

Tool Binary Find Default Path

RRDTool Rrdtool which rrdtool /usr/bin/

PHP Php which php /usr/bin/

SNMP Walk snmpwalk which snmpwalk /usr/bin/

SNMP Get snmpget which snmpget /usr/bin/

SNMP Bulk Walk snmpbulkwalk which snmpbulkwalk /usr/bin/

SNMP Get Next snmpgetnext which snmpgetnext /usr/bin/

Cacti Logger cacti.log ls /usr/share/cacti/log /usr/share/cacti/log

Page 19: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti

17 | P a g e

Identify SNMP & RRDTool Versions

SNMP Utility Version

rpm -qa | grep net-snmp

RRDTool Version

rpm -qa | grep rrdtool

Launch Cacti Application

To launch and configure cacti; in the browser access the URL http://<Your Cacti Host>/cacti/ or http://<Cacti Host IP Address>/cacti/;

App Step 1 – Welcome screen

First run; initial setup screen; click on “Next” button.

App Step 2 – Installation Type

Choose the option whether the installation is a “New Install” or “upgrade”

Page 20: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti

18 | P a g e

App Step 3 – Executables Path

From the “Tool Information” section the collated information should be validated.

Page 21: How to Install and Configure Cacti on Linux

How To Install and Configure Cacti

19 | P a g e

App Step 4 – First Login

In Login Screen, enter default username as “admin” and password as “admin”

App Step 5 – Reset Password (admin)

You need to reset the default password to a new password

App Step 6 – Create Graphs

Upon launching, click on “Create Graphs” and choose the host that you would like to get generate the graphs.