Nagios on ubuntu
In this Scenario
We have two machines: one running Ubuntu Server 10.04, which will be used for Nagios monitoring, and another running Ubuntu 10.10, serving as a remote host to be monitored. Both machines have a minimal installation.
On the Nagios Server
-
Install Required Packages:
root@nagios-ubuntu:~# apt-get -y install ssh php5-gd gcc make build-essential libgd2-xpm-dev libssl-dev -
Create a User for Nagios:
root@nagios-ubuntu:~# useradd -m nagios root@nagios-ubuntu:~# passwd nagiosWhen a new user is created, a group with the same name is typically assigned. However, it's good practice to create a dedicated Nagios group and add the Nagios user to both this group and the
www-data(Apache2) group:root@nagios-ubuntu:~# groupadd nagios root@nagios-ubuntu:~# usermod -G nagios nagios root@nagios-ubuntu:~# usermod -a -G nagios www-data -
Create a Directory for Nagios Files:
root@nagios-ubuntu:~# mkdir /garbage root@nagios-ubuntu:/garbage# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.3.1.tar.gz http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz -
Extract the Nagios Core Package:
root@nagios-ubuntu:/garbage# tar vxzf nagios-3.3.1.tar.gz root@nagios-ubuntu:/garbage# cd nagios -
Configure and Install Nagios:
root@nagios-ubuntu:/garbage# ./configure --with-gd-lib=/usr/lib --with-gd-inc=/usr/include --with-command-group=nagcmdUse
sedto prevent errors during the build process:root@nagios-ubuntu:/garbage/nagios# sed -i 's:for file in includes/rss/\*;:for file in includes/rss/\*.\*;:g' ./html/Makefile root@nagios-ubuntu:/garbage/nagios# sed -i 's:for file in includes/rss/extlib/\*;:for file in includes/rss/extlib/\*.\*;:g' ./html/MakefileBuild and install Nagios:
root@nagios-ubuntu:/garbage/nagios# make all root@nagios-ubuntu:/garbage/nagios# make install root@nagios-ubuntu:/garbage/nagios# make install-init root@nagios-ubuntu:/garbage/nagios# make install-config root@nagios-ubuntu:/garbage/nagios# make install-commandmode root@nagios-ubuntu:/garbage/nagios# make install-webconf -
Check Nagios Configuration:
root@nagios-ubuntu:/garbage/nagios# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg -
Set Up Login for Nagios Monitoring:
root@nagios-ubuntu:/garbage/nagios# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin -
Reload Apache Service:
root@nagios-ubuntu:/garbage/nagios# sudo /etc/init.d/apache2 reload -
Ensure Nagios Starts on Reboot:
root@nagios-ubuntu:/garbage/nagios# ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
Installing Nagios Plugins
-
Extract and Enter the Plugins Directory:
root@nagios-ubuntu:/garbage/nagios-plugins-1.4.15# ./configure root@nagios-ubuntu:/garbage/nagios-plugins-1.4.15# make root@nagios-ubuntu:/garbage/nagios-plugins-1.4.15# make install -
Verify Nagios Configuration Again:
root@nagios-ubuntu:/garbage/nagios-plugins-1.4.15# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg -
Access Nagios in Your Browser:
Point your browser to
http://Nagios_Machine's_IP/nagios.
Monitoring Linux Hosts
On the remote Ubuntu machine:
-
Install Required Packages:
root@ubuntu:/# apt-get install libssl-dev gcc -
Download NRPE Add-on:
root@ubuntu:/addons# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz -
Create a Nagios User:
root@ubuntu:/addons# useradd nagios root@ubuntu:/addons# passwd nagios -
Extract and Install Nagios Plugins:
root@ubuntu:/addons# tar vxzf nagios-plugins-1.4.15.tar.gz root@ubuntu:/addons# cd nagios-plugins-1.4.15/ root@ubuntu:/addons/nagios-plugins-1.4.15/# ./configure root@ubuntu:/addons/nagios-plugins-1.4.15/# make root@ubuntu:/addons/nagios-plugins-1.4.15/# make install -
Extract and Install NRPE:
root@ubuntu:/addons/nrpe-2.13# tar vxzf nrpe-2.13.tar.gz root@ubuntu:/addons/nrpe-2.13# cd nrpe-2.13/ root@ubuntu:/addons/nrpe-2.13# ./configure root@ubuntu:/addons/nrpe-2.13# make all root@ubuntu:/addons/nrpe-2.13# make install-plugin root@ubuntu:/addons/nrpe-2.13# make install-daemon root@ubuntu:/addons/nrpe-2.13# make install-daemon-config -
Run NRPE as a Service Under xinetd:
root@ubuntu:/addons/nrpe-2.13# make install-xinetd -
Edit the NRPE Configuration:
Update the
/etc/xinetd.d/nrpefile to include the IP address of the monitoring server:only_from = 127.0.0.1 192.168.56.102 -
Add NRPE Entry to /etc/services:
nrpe 5666/tcp # NRPE -
Restart xinetd Service:
root@ubuntu:/addons/nrpe-2.13# service xinetd restart -
Check if NRPE is Running:
root@ubuntu:/addons/nrpe-2.13# netstat -at | grep nrpe -
Issue Commands to Verify NRPE:
/usr/local/nagios/libexec/check_nrpe -H localhost -c check_users /usr/local/nagios/libexec/check_nrpe -H localhost -c check_load
Installing NRPE on Monitoring Server
-
Extract and Install NRPE:
root@ubuntu:/garbage/nrpe-2.13# tar vxzf nrpe-2.13.tar.gz root@ubuntu:/garbage/nrpe-2.13# cd nrpe-2.13/ root@ubuntu:/garbage/nrpe-2.13# ./configure root@ubuntu:/garbage/nrpe-2.13# make all root@ubuntu:/garbage/nrpe-2.13# make install-plugin -
Check Communication with Remote Host:
root@ubuntu:/garbage/nrpe-2.13# /usr/local/nagios/libexec/check_nrpe -H 192.168.56.103If successful, you should see
NRPE v2.13. -
Configure Nagios for Remote Host Monitoring:
Open the main Nagios config file:
root@ubuntu:/usr/local/nagios/etc/objects# vim /usr/local/nagios/etc/nagios.cfgUpdate the
admin_emailfield and add:cfg_file=/usr/local/nagios/etc/objects/ubuntu.cfg -
Create Remote Host Configuration File:
Create
ubuntu.cfgunder the same path, copying fromlocalhost.cfgas needed. Change the ownership and update parameters:hostgroup_name My remote ubuntu machines # Change the IP and hostname accordingly -
Reload Nagios:
Restart Apache and Nagios services, then access
http://your_Nagios_IP/nagiosto monitor the added host.
Monitoring a Windows Client
- Install NSClient++ on the Windows Machine: Set it to run as a service and start at boot.
-
Add Windows Object Definition in Nagios:
Update
nagios.cfgwith:cfg_file=/usr/local/nagios/etc/objects/winxp.cfg -
Create Windows Configuration File:
Create
winxp.cfgin the specified path, usingwindows.cfgas a template if needed. Update the IP andhostgroup_nameaccordingly.
Happy Monitoring!
Comments
Post a Comment