Install Cacti (Network Monitoring) on RHEL/CentOS 7.x/6.x/5.x and Fedora 21-12
Download Your Free eBooks NOW -10 Free Linux eBooks for Administrators
Cactitool is an open source web based network monitoring and system monitoring graphing solution forITbusiness. Cacti enables a user to poll services at regular intervals to create graphs on resulting data usingRRDtool. Generally, it is used to graph time-series data of metrics such asnetwork bandwidth utilization
Install Cacti in RHEL / CentOS / Fedora
In this how-to we are going to show you how to install and setup complete network monitoring application calledCactiusingNet-SNMPtool onRHEL 7.x/6.x/5.x,CentOS 7.x/6.x/5.xandFedora 21-12systems usingYUMpackage manager tool.
Cacti Required Packages
The Cacti required following packages to be installed on your Linux operating systems likeRHEL/CentOS/Fedora.
Apache: A Web server to display network graphs created byPHPandRRDTool.
MySQL: A Database server to store cacti information.
PHP: A script module to create graphs usingRRDTool.
PHP-SNMP: APHPextension forSNMP
NET-SNMP: A SNMP (Simple Network Management Protocol) is used to manage network.
RRDTool: A database tool to manage and retrieve time series data likeCPU load,Network Bandwidthetc.
Installing Cacti Required Packages on RHEL / CentOS / Fedora
First, we need to install following dependency packages one-by-one usingYUMpackage manager tool.
Install Apache
#yuminstallhttpdhttpd-devel
Apache Web Server Installation
Install MySQL
#yuminstallmysqlmysql-server
MySQL Installation
MariaDBis a community-developed fork of the MySQL database project, and provides a replacement for MySQL. Previously the official supported database was MySQl underRHEL/CentOS 6.x/5.xandFedora.
Recently,RedHatmakes a new transaction from MySQl to MariaDB, as MariaDB is the default implementation of MySQL inRHEL/CentOS 7.xandFedora 19onwards..
#yuminstallmariadb-server-y [OnRHEL/CentOS7.xandFedora19onwards]
Installation of MariaDB Database
Install PHP
#yuminstallphp-mysqlphp-pearphp-commonphp-gdphp-develphpphp-mbstringphp-cli
PHP Installation with Modules
Install PHP-SNMP
#yuminstallphp-snmp
SNMP Installation
Install NET-SNMP
#yuminstallnet-snmp-utilsnet-snmp-libs
Install SNMP Utils
Install RRDTool
#yuminstallrrdtool
Install Rrdtool
Staring Apache, MySQL and SNMP Services
Once you’ve installed all the required software’s forCactiinstallation, lets start them one-by-one using following commands.
On RHEL/CentOS 6.x/5.x and Fedora 18-12
[[email protected]~]#servicehttpdstart [[email protected]~]#servicemysqldstart [[email protected]~]#servicesnmpdstart
Start Services Using init
On RHEL/CentOS 7.x and Fedora 19 Onwards
[[email protected]~]#systemctlstarthttpd.service [[email protected]~]#systemctlstartmariadb.service [[email protected]~]#systemctlstartsnmpd.service
Start Services Using systemctl
Configure Start-up Links
ConfiguringApache,MySQLandSNMPServices to start on boot.
On RHEL/CentOS 6.x/5.x and Fedora 18-12
[[email protected]~]#/sbin/chkconfig--levels345httpdon [[email protected]~]#/sbin/chkconfig--levels345mysqldon [[email protected]~]#/sbin/chkconfig--levels345snmpdon
Enable Services at Boot Using chkconfig
On RHEL/CentOS 7.x and Fedora 19 Onwards
[[email protected]~]#systemctlenablehttpd.service [[email protected]~]#systemctlenablemariadb.service [[email protected]~]#systemctlenablesnmpd.service
Enable Services at Boot Using systemctl
Install Cacti on RHEL / CentOS / Fedora
Here, you need to install and enableEPEL Repository. Once you’ve enabled repository, type the following command to install Cacti application.
#yuminstallcacti
Sample Output:
Loadedplugins:fastestmirror,langpacks epel/x86_64/metalink|4.7kB00:00:00 epel|4.4kB00:00:00 (1/2):epel/x86_64/group_gz|250kB00:00:03 (2/2):epel/x86_64/primary_db|4.0MB00:02:20 (1/2):epel/x86_64/updateinfo|315kB00:00:09 (2/2):epel/x86_64/pkgtags|1.4MB00:00:59 Loadingmirrorspeedsfromcachedhostfile *base:centos.excellmedia.net *epel:ftp.cuhk.edu.hk *extras:centos.excellmedia.net *updates:centos.excellmedia.net ResolvingDependencies -->Runningtransactioncheck --->Packagecacti.noarch0:0.8.8b-7.el7willbeinstalled -->ProcessingDependency:rrdtoolforpackage:cacti-0.8.8b-7.el7.noarch -->ProcessingDependency:net-snmp-utilsforpackage:cacti-0.8.8b-7.el7.noarch -->Runningtransactioncheck --->Packagenet-snmp-utils.x86_641:5.7.2-18.el7willbeinstalled --->Packagerrdtool.x86_640:1.4.8-8.el7willbeinstalled -->FinishedDependencyResolution DependenciesResolved ============================================================================================================================================================================================= PackageArchVersionRepositorySize ============================================================================================================================================================================================= Installing: cactinoarch0.8.8b-7.el7epel2.1M Installingfordependencies: net-snmp-utilsx86_641:5.7.2-18.el7base195k rrdtoolx86_641.4.8-8.el7base368k TransactionSummary ============================================================================================================================================================================================= Install1Package(+2Dependentpackages) Totaldownloadsize:2.7M Installedsize:7.2M Isthisok[y/d/N]:y Downloadingpackages: (1/3):net-snmp-utils-5.7.2-18.el7.x86_64.rpm|195kB00:00:04 warning:/var/cache/yum/x86_64/7/epel/packages/cacti-0.8.8b-7.el7.noarch.rpm:HeaderV3RSA/SHA256Signature,keyID352c64e5:NOKEY==============-]56kB/s|2.4MB00:00:05ETA Publickeyforcacti-0.8.8b-7.el7.noarch.rpmisnotinstalled (2/3):cacti-0.8.8b-7.el7.noarch.rpm|2.1MB00:00:53 (3/3):rrdtool-1.4.8-8.el7.x86_64.rpm|368kB00:02:47 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total16kB/s|2.7MB00:02:47 Retrievingkeyfromfile:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 ImportingGPGkey0x352C64E5: Userid:"FedoraEPEL(7)" Fingerprint:91e97d7c4a5e96f17f3e888f6a2faea2352c64e5 Package:epel-release-7-5.noarch(installed) From:/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 Isthisok[y/N]:y Runningtransactioncheck Runningtransactiontest Transactiontestsucceeded Runningtransaction Warning:RPMDBalteredoutsideofyum. Installing:rrdtool-1.4.8-8.el7.x86_641/3 Installing:1:net-snmp-utils-5.7.2-18.el7.x86_642/3 Installing:cacti-0.8.8b-7.el7.noarch3/3 /var/tmp/rpm-tmp.mR0t1v:line1:fg:nojobcontrol warning:%post(cacti-0.8.8b-7.el7.noarch)scriptletfailed,exitstatus1 Non-fatalPOSTINscriptletfailureinrpmpackagecacti-0.8.8b-7.el7.noarch Verifying:1:net-snmp-utils-5.7.2-18.el7.x86_641/3 Verifying:rrdtool-1.4.8-8.el7.x86_642/3 Verifying:cacti-0.8.8b-7.el7.noarch3/3 Installed: cacti.noarch0:0.8.8b-7.el7 DependencyInstalled: net-snmp-utils.x86_641:5.7.2-18.el7rrdtool.x86_640:1.4.8-8.el7 Complete!
Configuring MySQL Server for Cacti Installation
We need to configureMySQLforCacti, to do this we need to set password for our newly installedMySQLserver and then we will createCactidatabase with userCacti. If you’reMySQLis already password protected, then don’t need to set it again.
Set MySQL Password
To set new password forMySQLserver, use the following command. (Note:This is for new MySQL installation only).
[[email protected]~]#mysqladmin-urootpasswordYOUR-PASSWORD-HERE
Create MySQL Cacti Database
Login intoMySQLserver with newly created password and createCactidatabase with userCactiand set the password for it.
On RHEL/CentOS 6.x/5.x and Fedora 18-12
[[email protected]~]#mysql-uroot-p Enterpassword: WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnectionidis3 Serverversion:5.1.73Sourcedistribution Copyright(c)2000,2013,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. mysql>createdatabasecacti; QueryOK,1rowaffected(0.00sec) mysql>GRANTALLONcacti.*TO[email protected]IDENTIFIEDBY'tecmint'; QueryOK,0rowsaffected(0.00sec) mysql>FLUSHprivileges; QueryOK,0rowsaffected(0.00sec) mysql>quit; Bye
On RHEL/CentOS 7.x and Fedora 19 Onwards
[[email protected]~]#mysql-uroot-p Enterpassword: WelcometotheMariaDBmonitor.Commandsendwith;or\g. YourMariaDBconnectionidis3 Serverversion:5.5.41-MariaDBMariaDBServer Copyright(c)2000,2014,Oracle,MariaDBCorporationAbandothers. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. MariaDB[(none)]>createdatabasecacti; QueryOK,1rowaffected(0.00sec) MariaDB[(none)]>GRANTALLONcacti.*TO[email protected]IDENTIFIEDBY'tecmint'; QueryOK,0rowsaffected(0.00sec) MariaDB[(none)]>FLUSHprivileges; QueryOK,0rowsaffected(0.00sec) MariaDB[(none)]>quit; Bye
Install Cacti Tables to MySQL
Find out the database file path usingRPMcommand, to install cacti tables into newly createdCactidatabase, use the following command.
#rpm-qlcacti|grepcacti.sql
Sample Output:
/usr/share/doc/cacti-0.8.8b/cacti.sql
Now we’ve of the location ofCacti.sqlfile, type the following command to install tables, here you need to type the Cacti userpassword.
[[email protected]~]#mysql-ucacti-pcacti</usr/share/doc/cacti-0.8.8b/cacti.sql Enterpassword:
Configure MySQL settings for Cacti
Open the file called/etc/cacti/db.phpwith any editor.
#vi/etc/cacti/db.php
Make the following changes and save the file. Make sure you set password correctly.
/*makesurethesevaluesreflectyouractualdatabase/host/user/password*/ $database_type="mysql"; $database_default="cacti"; $database_hostname="localhost"; $database_username="cacti"; $database_password="your-password-here"; $database_port="3306"; $database_ssl=false;
Configuring Firewall for Cacti
On RHEL/CentOS 6.x/5.x and Fedora 18-12
[[email protected]~]#iptables-AINPUT-pudp-mstate--stateNEW--dport80-jACCEPT [[email protected]~]#iptables-AINPUT-ptcp-mstate--stateNEW--dport80-jACCEPT [[email protected]~]#serviceiptablessave
On RHEL/CentOS 7.x and Fedora 19 Onwards
[[email protected]~]#firewall-cmd--permanent--zone=public--add-service=http [[email protected]~]#firewall-cmd--reload
Configuring Apache Server for Cacti Installation
Open file called/etc/httpd/conf.d/cacti.confwith your choice of editor.
#vi/etc/httpd/conf.d/cacti.conf
You need to enabled access toCactiapplication for your local network or per IP level. For example we've enabled access to our local LAN network172.16.16.0/20. In your case, it would be different.
Alias/cacti/usr/share/cacti <Directory/usr/share/cacti/> OrderDeny,Allow Denyfromall Allowfrom172.16.16.0/20</Directory>
In latest version of Apache (ex:Apache 2.4), you may need to change according to the following settings.
Alias/cacti/usr/share/cacti <Directory/usr/share/cacti/> <IfModulemod_authz_core.c> #httpd2.4Requireallgranted </IfModule> <IfModule!mod_authz_core.c> #httpd2.2 Orderdeny,allow Denyfromall Allowfromall </IfModule> </Directory>
Finally, restart theApacheservice.
[[email protected]~]#servicehttpdrestart [OnRHEL/CentOS6.x/5.xandFedora18-12] [[email protected]~]#systemctlrestarthttpd.service [OnRHEL/CentOS7.xandFedora19onwards]
Setting Cron for Cacti
Open file/etc/cron.d/cacti.
#vi/etc/cron.d/cacti
Uncomment the following line. Thepoller.phpscript runs every5minsand 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/null2>&1
Running Cacti Installer Setup
Finally, Cacti is ready, just go tohttp://YOUR-IP-HERE/cacti/& follow the installer instruction through the following screens. ClickNextbutton.
Cacti Setup Screen
Please choose installation Type as "New Install".
Select Cacti New Install
Make sure all the following values are correct before continuing. ClickFinishbutton.
Cacti Installation Directories
Cacti Login Screen, enter username as admin and password as admin.
Cacti Login Screen
Once you've entered username and password, it will ask you to enter a new password for cacti.
Cacti Force Password Screen
Cacti Console Screen.
Cacti Console Screen
How to Create New Graphs
To create graphs, Click onNew Graphs-->Select Host-->Select SNMP-Interface Statisticsand Select a graph typeIn/Out Bits. Click onCreatebutton. Please refer screen below.
How to Create Graphs in Cacti
Cacti Monitoring Graphs
For more information and usage please visit theCacti Page.
轉載於:https://blog.51cto.com/netyunwei/1658493