Nagios4

From VoIPmonitor.org
Jump to navigation Jump to search

Download and compile latest nagios from http://sourceforge.net/projects/nagios/files/:

cd /usr/src
wget http://sourceforge.net/projects/nagios/files/nagios-4.x/nagios-4.0.8/nagios-4.0.8.tar.gz/download -O nagios-4.0.8.tar.gz
tar -xzf nagios-4.0.8.tar.gz
apt-get install -y apache2 libapache2-mod-php5 build-essential libgd2-xpm-dev libssl-dev
cd nagios-4.0.8
./configure --exec-prefix=/usr/local/nagios/ --prefix=/usr/local/nagios/ --with-nagios-user=nagios --with-nagios-group=nagios --with-command-user=nagios --with-command-group=nagcmd

groupadd -g 9000 nagios
groupadd -g 9001 nagcmd
useradd -u 9000 -g nagios -G nagcmd -d /usr/local/nagios -c 'Nagios Admin' nagios
adduser www-data nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin


Download and compile latest nagios plugins from: http://www.nagios.org/download/plugins

cd /usr/src
wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
tar -xzf nagios-plugins-2.0.3.tar.gz
cd nagios-plugins-2.0.3/
./configure --with-nagios-user=nagios --with-nagios-group=nagios  --with-openssl=/usr/bin/openssl --enable-perl-modules --enable-libtap
make
make install

Change startup options for nagios vim /etc/init.d/nagios //add following lines after # Short-Description ... line

# Default-start: 2 3 4 5
# Default-Stop:

Run commands

chmod +x /etc/init.d/nagios
update-rc.d nagios defaults

Install nagios dependences

apt-get install -y nagios-nrpe-plugin

Install mail client

apt-get install -y sendmail-bin sendmail heirloom-mailx

At end of /etc/mail/sendmail.mc switch Masq.options with DefaultMailerOpt to be in right order like this:

....
dnl # Masquerading options
FEATURE(`always_add_domain')dnl
MASQUERADE_AS(`vm-debian')dnl
FEATURE(`allmasquerade')dnl
FEATURE(`masquerade_envelope')dnl
dnl # Default Mailer setup
MAILER_DEFINITIONS
MAILER(`local')dnl 
MAILER(`smtp')dnl

And regenerate:

m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf


HTTPS enable SSL for nagios:

mkdir /etc/apache2/ssl
cd /etc/apache2/ssl
openssl req -x509 -nodes -days 365 -newkey rsa:4096 -keyout my.nagiosserver.key -out my.nagiosserver.crt
a2enmod ssl

vim /etc/apache2/conf.d/nagios.conf

uncomment all SSLRequireSSL

vim /etc/apache2/sites-available/default //replace existing data with:

<VirtualHost *:443>
   ServerAdmin webmaster@localhost
   ServerName my.nagiosserver.crt
   DocumentRoot /var/www/my.nagiosserver

   <Directory />
       Options FollowSymLinks
       AllowOverride None
   </Directory>

   <Directory /var/www/my.nagiosserver>
       Options -Indexes FollowSymLinks MultiViews
       AllowOverride All
       Order allow,deny
       allow from all
   </Directory>

    SSLEngine On
    SSLCertificateFile /etc/apache2/ssl/my.nagiosserver.crt
    SSLCertificateKeyFile /etc/apache2/ssl/my.nagiosserver.key
</VirtualHost>
service apache2 restart

create nagios-www (web pages)

mkdir /var/www/my.nagiosserver
cp -r /usr/src/nagios-4.0.8/html/* /var/www/my.nagiosserver
cp /usr/lib/nagios/plugins/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/

For debian7 - wheezy

To create privileges for www-data to restart nagios (to reload config from voipmonitor gui)////

chown www-data -R /var/lib/nagios3/spool/checkresults
chown -R nagios:www-data /usr/local/nagios/bin/nagios
chown -R www-data /usr/local/nagios/var/spool/checkresults
chown www-data:nagioscmd /usr/local/nagios/var/rw/nagios.cmd
apt-get install sudo

vim /etc/sudoers //add line www-data after root .. line

root    ALL=(ALL:ALL) ALL
www-data ALL=(ALL) NOPASSWD: /usr/bin/killall, /usr/local/nagios/bin/nagios
...

in GUI Settings->Systemconfiguration->:

Enable nagios: TRUE
Nagios user: nagios
Path to nagios binary: /usr/local/nagios/bin/nagios
Path to nagios.cfg: /usr/local/nagios/etc/objects/nagios.cfg
Path to vm.cfg: /usr/local/nagios/etc/objects/vm.cfg 
Path to status.dat: /var/cache/nagios3/status.dat
Command which reload config: /usr/bin/killall -HUP nagios
run sudo before reload command: TRUE


source: http://midactstech.blogspot.cz/2013/09/how-to-install-nagios-on-debian-wheezy.html