info
-
with nagios you can
-
monitor your entire it infrastructure
-
spot problem before they occur
-
know immediately when problem arise
-
share avaiability data with stakeholders
-
detect securiry breaches
-
plan and budget for it upgrades
-
reduce downtime and business losses
-
install
-
prerequisites
-
fully working lamp stack
-
install the following prerequisites
$ sudo apt-get install build-essential libgd2-xpm-dev apache2-utils
-
-
create nagios user and group
-
create
nagios
user with a password$ sudo useradd -m nagios $ sudo passwd nagios
-
create
nagcmd
group for allowing external commands to be submitted through webui$ sudo groupadd nagcmd # add both `nagios` and `apache` user to the group $ sudo usermod -a -G nagcmd nagios $ sudo usermod -a -G nagcmd www-data
-
-
download nagios and plugins
$ wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz # --2015-07-17 08:57:11-- http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz # Resolving prdownloads.sourceforge.net... 54.192.69.238, 54.230.70.184, 54.230.70.69, ... # Connecting to prdownloads.sourceforge.net|54.192.69.238|:80... connected. # HTTP request sent, awaiting response... 403 Forbidden # 2015-07-17 08:57:12 ERROR 403: Forbidden. $ wget https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.0.8.tar.gz $ wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
-
install nagios and plugin
-
install nagios
$ tar -zxf nagios-4.0.8.tar.gz $ cd nagios-4.0.8 # compile and install nagios $ sudo ./configure --with-command-group=nagcmd $ sudo make all ################### $ sudo make install ... You can continue with installing Nagios as follows (type 'make' without any arguments for a list of all possible options): make install-init - This installs the init script in /etc/init.d make install-commandmode - This installs and configures permissions on the directory for holding the external command file make install-config - This installs sample config files in /usr/local/nagios/etc make[1]: Leaving directory '/home/node5/Downloads/nagioscore-nagios-4.0.8' ######################## $ sudo make install-init /usr/bin/install -c -m 755 -d -o root -g root /etc/init.d /usr/bin/install -c -m 755 -o root -g root daemon-init /etc/init.d/nagios *** Init script installed *** ########################## $ sudo make install-config /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg /usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg *** Config files installed *** Remember, these are *SAMPLE* config files. You'll need to read the documentation for more information on how to actually define services, hosts, etc. to fit your particular needs. ############################### $ sudo make install-commandmode /usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw chmod g+s /usr/local/nagios/var/rw *** External command directory configured ***
-
install nagios web interface
# compile and install nagios web interface $ sudo make install-webconf # you may get the following error /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf /usr/bin/install: cannot create regular file ‘/etc/httpd/conf.d/nagios.conf’: No such file or directory Makefile:296: recipe for target 'install-webconf' failed make: *** [install-webconf] Error 1 # so run the following command instead of using previous one $ sudo /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.config # check $ sudo ls -l /etc/apache2/sites-enabled/ # create a `nagiosadmin` account for logging into the nagios web interface $ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin # restart apache to make setting take effect $ sudo service apache2 restart
-
install nagios plugins
$ tar -zxf nagios-plugins-2.0.3.tar.gz $ cd nagios-plugins-2.0.3 # compile and install $ sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # check additional tip $ sudo make $ sudo make install
-
-
configure nagios
-
config email id to receive alerts
$ sudo pico /usr/local/nagios/etc/object/contacts.cfg ... define contact{ contact_name nagiosadmin ; Short name of user use generic-contact ; Inherit default values from generic-contact template (defined above) alias Nagios Admin ; Full name of user email aa@bb.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** } ...
-
nagios administrative access
$ sudo pico /etc/apache2/sites-enabled/nagios.conf ... Deny from all Allow from 127.0.0.1 192.168.1.0/24 ...
-
enable apache’s rewrite and cgi modules
$ sudo a2enmod rewrite $ sudo a2enmod cgi
-
check
nagios.conf
syntax errors$ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
-
start nagios service and make it autostart
$ sudo service nagios start Failed to start nagios.service: Unit nagios.service failed to load: No such file or directory. # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # check additional tip $ sudo ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
-
-
access nagios web interface
http://nagios-server-ip/nagios
monitor
-
install
nrpe
andnagios-plugins
in our monitoring targets# CentOS/RHEL/Scientific Linux clients # add epel repo in your clients to install nrpe package # on CentOS 7 $ yum install epel-release # on CentOS 6.x # refer http://www.unixmen.com/install-epel-repository-rhel-centos-scientific-linux-6/ # install `nrpe` and `nagios-plugins` $ yum install nrpe nagios-plugins-all openssl # on debian/ubuntu clients $ sudo apt-get install nagios-nrpe-server nagios-plugins
-
install
nagios-nrpe-plugin
$ sudo apt-get install nagios-nrpe-plugin $ cd /usr/lib/nagios/plugins $ ls check_nr*
-
config monitoring targets
-
edit
/etc/nagios/nrpe.cfg
$ sudo pico /etc/nagios/nrpe.cfg ... ## find the following line and add the nagios server ip allowed_hosts=127.0.0.1 192.168.120.155
-
start nrpe service
# on centos clients # centos 7 $ systemctl start nrpe $ chkconfig nrpe on # centos 6.x $ service nrpe start $ chkconfig nrpe on # on debian/ubuntu clients $ sudo /etc/init.d/nagios-nrpe-server restart
-
-
nagios server
config-
add the clients in config file
$ sudo pico /usr/local/nagios/etc/nagios.cfg ... ## find and uncomment the following line cfg_dir=/usr/local/nagios/etc/servers # create a directory `servers` under `/usr/local/nagios/ect` $ sudo mkdir /usr/local/nagios/etc/servers # create config file to the client to be monitored $ sudo pico /usr/local/nagios/etc/servers/clients.cfg define host{ use linux-server host_name node3 alias node3 address 192.168.120.153 max_check_attempts 5 check_period 24x7 notification_interval 30 notification_period 24x7 }
-
restart nagios service
$ sudo service nagios restart # wait for few seconds # refresh nagios admin console in browser # navigate to `Hosts`
-
define services
-
monitor
ssh
service-
edit
/usr/local/nagios/etc/servers/clients.cfg
$ sudo pico /usr/local/nagios/etc/servers/clients.cfg define host{ use linux-server host_name node3 alias node3 address 192.168.120.153 max_check_attempts 5 check_period 24x7 notification_interval 30 notification_period 24x7 } define service { use generic-service host_name node3 service_description SSH check_command check_ssh notifications_enabled 0 }
-
restart nagios service
$ sudo service nagios restart # wait for few seconds # refresh nagios admin console in browser # navigate to `Services`
-
additional tip
-
trying to use
check_http
with-S
flag (for https)-
make sure install
openssl
andlibssl-dev
first# even if nagios server is checking a remote client # you need `openssl` and `libssl-dev` locally
-
configure nagios plugins add
--with-openssl
$ sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
-
-
Failed to start nagios.service: Unit nagios.service failed to load: No such file or directory.
-
solution 1 not fixed
# copy `/etc/init.d/skeleton` to `/etc/init.d/nagios` $ cp /etc/init.d/skeleton /etc/init.d/nagios # edit it $ sudo pico /etc/init.d/nagios DESC="Nagios" NAME=nagios DAEMON=/usr/local/nagios/bin/$NAME DAEMON_ARGS="-d /usr/local/nagios/etc/nagios.cfg" PIDFILE=/usr/local/nagios/var/$NAME.lock # change permissions $ sudo chmod +x /etc/init.d/nagios # start nagios using $ /etc/init.d/nagios start
-
solution 2 fixed
$ reboot
-
-
references