Professional Documents
Culture Documents
InstallandConfigureNagiosOnCentOS,RHEL,ScientificLinux6.5/6.4|Unixmen
Nagiosisanopensourcesoftwarethatcanbeusedfornetworkandinfrastructuremonitoring.
Nagios will monitor servers, switches, applications and services. It alerts the System
Administrator when something went wrong and also alerts back when the issues has been
rectified.
WithNagiosyoucan:
MonitoryourentireITinfrastructure.
Identifyproblemsbeforetheyoccur.
Knowimmediatelywhenproblemsarise.
Shareavailabilitydatawithstakeholders.hypotheticalquestion
Detectsecuritybreaches.
PlanandbudgetforITupgrades.
Reducedowntimeandbusinesslosses.
Scenario
Inthistutorialiamgoingtousetwosystemsasmentionedbelow.
Nagios server:
Operatingsystem:CentOS6.5minimalinstallation
IPAddress:192.168.1.101/24
Nagios client:
http://www.unixmen.com/installandconfigurenagiosincentos64rhel64/
1/11
8/10/2016
InstallandConfigureNagiosOnCentOS,RHEL,ScientificLinux6.5/6.4|Unixmen
OperatingSystem:Ubuntu13.04
IPAddress:192.168.1.100/24
Prerequisites
BeforeinstallingNagios,makesurethatyouveaproperlyinstalledandconfiguredLAMPstack
inyourserver.ToinstallandconfigureLAMPserver,referanyoneofthefollowinglinks.
InstallLAMPserverOnCentOS/RHEL/ScientificLinux6
Alsoinstallthefollowingprerequisitestoo.Allcommandsshouldberunasrootuser.
#yuminstallgdgddevelgccglibcglibccommon
InstallNagios
ItestedthishowtoonCentOS6.5minimalserver,althoughitshouldworkonallRHEL6.xand
itscloneslikeCentOS6.xandScientificLinux6.x.
Nagios will not be found in CentOS official repositories, so let us add the EPEL repository to
installnagios.ToaddandenableEPELrepository,referthefollowinglink.
InstallEPELRepositoryOnCentOS/RHEL/ScientificLinux6
Nextinstallnagioswithallpluginsandnagiosagents(nrpeagent)usingcommand:
#yuminstallnagios*
Note:ItworkedformeeitherifikeepSELINUXandiptablesenableordisable.Allyouneedto
doisallowtheapacheportthroughiptablesasshownbelow.
#vi/etc/sysconfig/iptables
Addthefollowingline:
[...]
AINPUTmstatestateNEWmtcpptcpdport80jACCEPT
http://www.unixmen.com/installandconfigurenagiosincentos64rhel64/
2/11
8/10/2016
InstallandConfigureNagiosOnCentOS,RHEL,ScientificLinux6.5/6.4|Unixmen
[...]
Saveandclosethefile.Restartiptables.
#serviceiptablesrestart
ConfigureNagios
Addtheadminmailaddressinthenagioscontactfiletoreceivealertsfromnagiosserver.Todo
thateditfile/etc/nagios/objects/contacts.cfg,
#vi/etc/nagios/objects/contacts.cfg
Findthefollowinglineandentertheemailid:
[...]
emailsk@unixmen.com;
[...
Saveandclosethefile.ThenEditfile/etc/httpd/conf.d/nagios.conf,
#vi/etc/httpd/conf.d/nagios.conf
Andeditthefollowinglinesifyouwanttoaccessnagiosadministrativeconsolefromaparticular
IPseries.Hereiwanttoallownagiosadministrativeaccessfrom192.168.1.0/24seriesonly.
[...]
##CommentLines15&16##
#Orderallow,deny
#Allowfromall
##UncommentandChangelines17,18&19asshownbelow##
Orderdeny,allow
Denyfromall
Allowfrom127.0.0.1192.168.1.0/24
[...]
Setnagiosadminpassword
http://www.unixmen.com/installandconfigurenagiosincentos64rhel64/
3/11
8/10/2016
InstallandConfigureNagiosOnCentOS,RHEL,ScientificLinux6.5/6.4|Unixmen
#htpasswd/etc/nagios/passwdnagiosadmin
Newpassword:
Retypenewpassword:
Updatingpasswordforusernagiosadmin
Startnagiosandhttpdservicesandletthemtostartautomaticallyoneveryboot.
#servicenagiosstart
#servicehttpdstart
#chkconfignagioson
#chkconfighttpdon
AccessNagiosadminconsole
Open nagios administrator console with URL http://nagiosserverip/nagios and enter the
usernameasnagiosadminanditspasswordwhichwecreatedintheearliersteps.
ThisishowNagiosadministrativeconsolelooks:
http://www.unixmen.com/installandconfigurenagiosincentos64rhel64/
4/11
8/10/2016
InstallandConfigureNagiosOnCentOS,RHEL,ScientificLinux6.5/6.4|Unixmen
ClickontheHostssectionintheleftpaneoftheconsole.Youwillseethenoofhoststobe
monitoredbyNagiosserver.Initially,thenagiosserver(localhost)itselfwillonlybemonitored.
Clickonthemonitoringhosttodisplaymoredetails:
http://www.unixmen.com/installandconfigurenagiosincentos64rhel64/
5/11
8/10/2016
InstallandConfigureNagiosOnCentOS,RHEL,ScientificLinux6.5/6.4|Unixmen
AddMonitoringtargetstoNagiosserver
NowletusaddsomeclientstomonitorbyNagiosserver.Todothatwehavetoinstallnrpeand
nagiospluginsinourmonitoringtargets.
OnCentOS/RHEL/ScientifcLinuxclients:
Like i said before, you have to add EPEL repository in your CentOS/RHEL/Scientific Linux 6.x
clientstoinstallnrpepackage.
Installnrpeandnagiospluginspackagesinclientsystemstobemonitored.
#yuminstallnrpenagiospluginsallopenssl
OnDebian/Ubuntuclients:
$sudoaptgetinstallnagiosnrpeservernagiosplugins
ConfigureMonitoringtargets
Edit/etc/nagios/nrpe.cfgfile,
http://www.unixmen.com/installandconfigurenagiosincentos64rhel64/
6/11
8/10/2016
InstallandConfigureNagiosOnCentOS,RHEL,ScientificLinux6.5/6.4|Unixmen
#vi/etc/nagios/nrpe.cfg
AddyourNagiosserveripaddress
[...]
##Line81AddtheNagiosserverIP##
allowed_hosts=127.0.0.1192.168.1.101
[...]
Startnrpeservice:
#servicenrpestart
#chkconfignrpeon
ForDebian/UbuntuClients,startnrpeserviceasshownbelow.
$sudo/etc/init.d/nagiosnrpeserverrestart
Now go back to your Nagios server to add the clients to be monitored through nagios server.
Edit/etc/nagios/nagios.cfgfile,
#vi/etc/nagios/nagios.cfg
anduncommentthefollowinglines.
##Line52Uncomment##
cfg_dir=/etc/nagios/servers
Createadirectorycalledserversunder/etc/nagios/.
#mkdir/etc/nagios/servers
Createconfigfiletotheclienttobemonitored:
#vi/etc/nagios/servers/clients.cfg
definehost{
http://www.unixmen.com/installandconfigurenagiosincentos64rhel64/
7/11
8/10/2016
InstallandConfigureNagiosOnCentOS,RHEL,ScientificLinux6.5/6.4|Unixmen
uselinuxserver
host_nameclient
aliasclient
address192.168.1.100
max_check_attempts5
check_period24x7
notification_interval30
notification_period24x7
}
Finallyrestartnagiosservice.
#servicenagiosrestart
NowopenthenagiosadminconsoleinthebrowserandnavigatetoHostssectionintheleft
pane.Youwillseethenewlyaddedclientwillbevisiblethere.Clickonthehosttoseeifthereis
anythingwrongoralerts.
http://www.unixmen.com/installandconfigurenagiosincentos64rhel64/
8/11
8/10/2016
InstallandConfigureNagiosOnCentOS,RHEL,ScientificLinux6.5/6.4|Unixmen
Clickonthemonitoringtarget,youllgetthedetailedoutput:
Likethisway,youcandefinemoreclientsbycreatingaseparateconfigfiles
/etc/nagios/serversdirectoryforeachclient.
Defineservices
Wediddefinethemonitoringhostbefore.Nowletusaddsomeservicesofthemonitoringhost.
Forexampletomonitorthesshservice,addthefollowinglinesshowninredcolourinthe
http://www.unixmen.com/installandconfigurenagiosincentos64rhel64/
9/11
8/10/2016
InstallandConfigureNagiosOnCentOS,RHEL,ScientificLinux6.5/6.4|Unixmen
/etc/nagios/servers/clients.cfgfile.
#vi/etc/nagios/servers/clients.cfg
definehost{
uselinuxserver
host_nameclient
aliasclient
address192.168.1.100
max_check_attempts5
check_period24x7
notification_interval30
notification_period24x7
}
defineservice{
usegenericservice
host_nameclient
service_descriptionSSH
check_commandcheck_ssh
notifications_enabled0
}
Saveandclosethefile.RestartNagios.
#servicenagiosrestart
http://www.unixmen.com/installandconfigurenagiosincentos64rhel64/
10/11
8/10/2016
InstallandConfigureNagiosOnCentOS,RHEL,ScientificLinux6.5/6.4|Unixmen
NowlogintoNagioswebconsoleandcheckfortheaddedservices.NavigatetoServices
section,youllseethesshservicethere.
ToknowmoreaboutobjectdefinitionssuchasHostdefinitions,servicedefinitions,contact
definitionsandmorepleasedovisithere.Thispagewilldescribeyouthedescriptionand
formatofallobjectdefinitions.
Thatsallaboutnow.GoodLuck!Stayhealthy!
YoumightwanttocheckNagios4installationonCentOS7.
InstallAndConfigureNagios4OnCentOS7
ReferenceLinks:
NagiosHomepage
http://www.unixmen.com/installandconfigurenagiosincentos64rhel64/
11/11