How to install Nagios Server in Ubuntu
To install Nagios Server in Ubuntu
Nagios is an open source Network monitoring tool that monitors system, networks and infrastructure. It also detects the protocol failures and network outages. It provides monitoring and alerting services for switches, applications, servers, and services. Nagios installation in Ubuntu is explained in this manual.
To install Nagios Server
Before starting with the Nagios server installation, initialize the following repositories that are necessary for the installation.
root@linuxhelp:~# apt-get install wget build-essential apache2 php apache2-mod-php7.0 php-gd libgd-dev sendmail -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting ' libapache2-mod-php7.0' for regex ' apache2-mod-php7.0'
build-essential is already the newest version (12.1ubuntu2).
build-essential set to manually installed.
wget is already the newest version (1.17.1-1ubuntu1.1).
wget set to manually installed.
.
.
.
Setting up procmail (3.22-25) ...
Setting up sensible-mda (8.15.2-3) ...
Setting up sendmail (8.15.2-3) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Processing triggers for systemd (229-4ubuntu10) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
Processing triggers for libapache2-mod-php7.0 (7.0.8-0ubuntu0.16.04.3) ...
After adding the repositories, add Nagios user and group.
root@linuxhelp:~# useradd nagios
root@linuxhelp:~# groupadd nagcmd
Then add the Nagios and Apache user into Nagios group as follows.
root@linuxhelp:~# usermod -a -G nagcmd nagios
root@linuxhelp:~# usermod -a -G nagios,nagcmd www-data
Use wget command as shown below to download and extract the Nagios core.
root@linuxhelp:~# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.0.tar.gz --2016-10-13 03:57:03-- https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.0.tar.gz Resolving assets.nagios.com (assets.nagios.com)... 72.14.181.71, 2600:3c00::f03c:91ff:fedf:b821 Connecting to assets.nagios.com (assets.nagios.com)|72.14.181.71|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 11155104 (11M) [application/x-gzip] Saving to: ‘ nagios-4.2.0.tar.gz’ nagios-4.2.0.tar.gz 100%[========================================================================================> ] 10.64M 780KB/s in 21s 2016-10-13 03:57:26 (513 KB/s) - ‘ nagios-4.2.0.tar.gz’ saved [11155104/11155104] root@linuxhelp:~# ls Desktop Documents Downloads examples.desktop Music nagios-4.2.0.tar.gz Pictures Public Templates Videos root@linuxhelp:~# tar -xzvf nagios-4.2.0.tar.gz nagios-4.2.0/ nagios-4.2.0/.gitignore nagios-4.2.0/Changelog nagios-4.2.0/INSTALLING nagios-4.2.0/LEGAL nagios-4.2.0/LICENSE nagios-4.2.0/Makefile.in nagios-4.2.0/README nagios-4.2.0/README.asciidoc nagios-4.2.0/THANKS . . . nagios-4.2.0/xdata/xcddefault.h nagios-4.2.0/xdata/xodtemplate.c nagios-4.2.0/xdata/xodtemplate.h nagios-4.2.0/xdata/xpddefault.c nagios-4.2.0/xdata/xpddefault.h nagios-4.2.0/xdata/xrddefault.c nagios-4.2.0/xdata/xrddefault.h nagios-4.2.0/xdata/xsddefault.c nagios-4.2.0/xdata/xsddefault.h
Now compile the Nagios core as shown below.
root@linuxhelp:~# cd nagios-4.2.0/
root@linuxhelp:~/nagios-4.2.0# ./configure --with-nagios-group=nagios --with-command-group=nagcmd
checking for a BSD-compatible install... /usr/bin/install -c
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether make sets $(MAKE)... yes
.
.
.
Web Interface Options:
------------------------
HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP):
Review the options above for accuracy. If they look okay,
type ' make all' to compile the main program and CGIs.
Then run make script to install Nagios.
root@linuxhelp:~/nagios-4.2.0# make all
cd ./base & & make
make[1]: Entering directory ' /home/user1/nagios-4.2.0/base'
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o nagios.o nagios.c
nagios.c: In function ‘ main’ :
nagios.c:594:4: warning: ignoring return value of ‘ asprintf’ , declared with attribute warn_unused_result [-Wunused-result]
asprintf(& mac-> x[MACRO_PROCESSSTARTTIME], " %llu" , (unsigned long long)program_start)
.
.
.
before you post a question to one of the mailing lists.
Also make sure to include pertinent information that could
help others help you. This might include:
- What version of Nagios you are using
- What version of the plugins you are using
- Relevant snippets from your config files
- Relevant error messages from the Nagios log file
For more information on obtaining support for Nagios, visit:
https://support.nagios.com
*************************************************************
Enjoy.
root@linuxhelp:~/nagios-4.2.0# make install
cd ./base & & make install
make[1]: Entering directory ' /home/user1/nagios-4.2.0/base'
make install-basic
make[2]: Entering directory ' /home/user1/nagios-4.2.0/base'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/bin
/usr/bin/install -c -m 774 -o nagios -g nagios nagios /usr/local/nagios/bin
.
.
.
make install-config
- This installs sample config files in /usr/local/nagios/etc
make[1]: Leaving directory ' /home/user1/nagios-4.2.0'
root@linuxhelp:~/nagios-4.2.0# 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 *** root@linuxhelp:~/nagios-4.2.0# 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 *** root@linuxhelp:~/nagios-4.2.0# 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 . . . 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. root@linuxhelp:~/nagios-4.2.0# /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf
Then copy the directory as shown below command.
root@linuxhelp:~/nagios-4.2.0# cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
Change the ownership for the directory.
root@linuxhelp:~/nagios-4.2.0# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
Next we need to download and install Nagios plugins.
root@linuxhelp:~# wget https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz --2016-10-13 04:10:58-- https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz Resolving nagios-plugins.org (nagios-plugins.org)... 72.14.186.43 Connecting to nagios-plugins.org (nagios-plugins.org)|72.14.186.43|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 2695301 (2.6M) [application/x-gzip] Saving to: ‘ nagios-plugins-2.1.2.tar.gz’ nagios-plugins-2.1.2.tar.gz 100%[========================================================================================> ] 2.57M 627KB/s in 4.4s 2016-10-13 04:11:04 (593 KB/s) - ‘ nagios-plugins-2.1.2.tar.gz’ saved [2695301/2695301] root@linuxhelp:~# tar -xzvf nagios-plugins-2.1.2.tar.gz nagios-plugins-2.1.2/ nagios-plugins-2.1.2/perlmods/ nagios-plugins-2.1.2/perlmods/Config-Tiny-2.14.tar.gz nagios-plugins-2.1.2/perlmods/parent-0.226.tar.gz nagios-plugins-2.1.2/perlmods/Test-Simple-0.98.tar.gz nagios-plugins-2.1.2/perlmods/Makefile.in nagios-plugins-2.1.2/perlmods/version-0.9903.tar.gz nagios-plugins-2.1.2/perlmods/Makefile.am . . . nagios-plugins-2.1.2/pkg/solaris/ nagios-plugins-2.1.2/pkg/solaris/preinstall nagios-plugins-2.1.2/pkg/solaris/solpkg nagios-plugins-2.1.2/pkg/solaris/pkginfo.in nagios-plugins-2.1.2/pkg/solaris/pkginfo nagios-plugins-2.1.2/pkg/redhat/ nagios-plugins-2.1.2/pkg/redhat/requires
To configure Nagios Plugins
Then run the following command to configure Nagios plugin.
root@linuxhelp:~# cd nagios-plugins-2.1.2/
root@linuxhelp:~/nagios-plugins-2.1.2# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether to disable maintainer-specific portions of Makefiles... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
.
.
.
--with-gnutls: no
--enable-extra-opts: yes
--with-perl: /usr/bin/perl
--enable-perl-modules: no
--with-cgiurl: /nagios/cgi-bin
--with-trusted-path: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
--enable-libtap: no
Run the make scripts to install Nagios.
root@linuxhelp:~/nagios-plugins-2.1.2# make make all-recursive make[1]: Entering directory ' /home/user1/nagios-plugins-2.1.2' Making all in gl make[2]: Entering directory ' /home/user1/nagios-plugins-2.1.2/gl' . . . make[2]: Leaving directory ' /home/user1/nagios-plugins-2.1.2/po' make[2]: Entering directory ' /home/user1/nagios-plugins-2.1.2' make[2]: Leaving directory ' /home/user1/nagios-plugins-2.1.2' make[1]: Leaving directory ' /home/user1/nagios-plugins-2.1.2' root@linuxhelp:~/nagios-plugins-2.1.2# make install Making install in gl make[1]: Entering directory ' /home/user1/nagios-plugins-2.1.2/gl' make install-recursive make[2]: Entering directory ' /home/user1/nagios-plugins-2.1.2/gl' . . . make[2]: Entering directory ' /home/user1/nagios-plugins-2.1.2' make[2]: Nothing to be done for ' install-exec-am' . make[2]: Nothing to be done for ' install-data-am' . make[2]: Leaving directory ' /home/user1/nagios-plugins-2.1.2' make[1]: Leaving directory ' /home/user1/nagios-plugins-2.1.2'
Now configure Nagios file by uncommenting the following line.
root@linuxhelp:~# vim /usr/local/nagios/etc/nagios.cfg
cfg_dir=/usr/local/nagios/etc/servers
Now create the directory for servers.
root@linuxhelp:~# mkdir -p /usr/local/nagios/etc/servers
After creating the directory open the contacts.cfg file and replace the default mail id with yours to receive mail alerts.
root@linuxhelp:~# vim /usr/local/nagios/etc/objects/contacts.cfg
Next enable the following Apache modules.
root@linuxhelp:~# a2enmod rewrite Enabling module rewrite. To activate the new configuration, you need to run: service apache2 restart root@linuxhelp:~# a2enmod cgi AH00557: apache2: apr_sockaddr_info_get() failed for linuxhelp AH00558: apache2: Could not reliably determine the server' s fully qualified domain name, using 127.0.0.1. Set the ' ServerName' directive globally to suppress this message Enabling module cgi. To activate the new configuration, you need to run: service apache2 restart
Then add password for Nagios user “ nagiosadmin” .
root@linuxhelp:~# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
Enable the Nagios virtual host by creating the soft link.
root@linuxhelp:~# ln -s /etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enabled/
Create file to start the services for Nagios and add the following services.
root@linuxhelp:~# vim /etc/systemd/system/nagios.service
[Unit]
Description=Nagios
BindTo=network.target
[Install]
WantedBy=multi-user.target
[Service]
User=nagios
Group=nagios
Type=simple
ExecStart=/usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg
Now start the services for Nagios and Apache.
root@linuxhelp:~# systemctl start apache2
root@linuxhelp:~# systemctl start nagios
root@linuxhelp:~# systemctl enable nagios
Synchronizing state of nagios.service with SysV init with /lib/systemd/systemd-sysv-install...
Executing /lib/systemd/systemd-sysv-install enable nagios
Open and edit the Nagios file and make the following entry into it.
root@linuxhelp:~# vim /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
Now make the Nagios file into an executable format.
root@linuxhelp:~# chmod +x /etc/init.d/nagios
Once again restart the services.
root@linuxhelp:~# systemctl restart apache2
root@linuxhelp:~# systemctl restart nagios
Open the browser and navigate to the URL http://< IP_address> /nagios
Then Login to the Nagios using the user credentials.
Comments ( 0 )
No comments available