среда, 30 марта 2016 г.

Установка Nagios 4.1.1 на Ubuntu 14.04


Опишу установку Nagios 4.1.1, Nagios Plugins 2.1.1 NRPE 2.15 на Ubuntu 14.04 на nginx, php-fpm и fcgiwrap:

1. Установка nginx:
Обновим пакеты:
# apt-get update
# apt-get upgrade
# apt-get install build-essential

Подключим репозиторий nginx:
# cat /etc/apt/sources.list.d/nginx.list
deb http://nginx.org/packages/ubuntu/ trusty nginx
deb-src http://nginx.org/packages/ubuntu/ trusty nginx

Получим ключ репозитория nginx:
# wget http://nginx.org/keys/nginx_signing.key
# apt-key add nginx_signing.key



Установим nginx:
# apt-get update
# apt-get install nginx
# service nginx status
 * nginx is running

2. Установка Nagios Core:

2.1 Установка зависимостей:
# apt-get install libgd2-xpm-dev
# apt-get install php5-fpm
# apt-get install spawn-fcgi fcgiwrap
# apt-get install zip

2.2 Добавим пользователя nagios:
# adduser --system --no-create-home --disabled-login --group nagios
Adding system user `nagios' (UID 106) ...
Adding new group `nagios' (GID 113) ...
Adding new user `nagios' (UID 106) with group `nagios' ...
Not creating home directory `/home/nagios'.

Добавим в нужные группы:
# groupadd nagcmd
# usermod -G nagcmd nagios
# usermod -a -G nagcmd www-data

2.3 Установка Nagios Core:
# cd /usr/local/src
# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz
# tar xzf nagios-4.1.1.tar.gz
# cd nagios-4.1.1

Сконфигурируем Nagios Core:
# ./configure --prefix=/usr/local/nagios-4.1.1 --sysconfdir=/etc/nagios --with-command-group=nagcmd
 General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagcmd
             Event Broker:  yes
        Install ${prefix}:  /usr/local/nagios-4.1.1
    Install ${includedir}:  /usr/local/nagios-4.1.1/include/nagios
                Lock file:  ${prefix}/var/nagios.lock
   Check result directory:  ${prefix}/var/spool/checkresults
           Init directory:  /etc/init.d
  Apache conf.d directory:  /etc/httpd/conf.d
             Mail program:  /bin/mail
                  Host OS:  linux-gnu
          IOBroker Method:  epoll

 Web Interface Options:
 ------------------------
                 HTML URL:  http://localhost/nagios/
                  CGI URL:  http://localhost/nagios/cgi-bin/
 Traceroute (used by WAP):  

Установим:
# make all
# make install
# make install-init
# make install-config
# make install-commandmode

Создадим симлинк:
# ln -s /usr/local/nagios-4.1.1/ /usr/local/nagios

2.4 Создание пользователя
Так как у нас php-fpm, а не Apache, создадим небольшой скрипт для генерации логина и пароля базовой авторизации:
# vim /usr/local/bin/htpasswd.pl
#!/usr/bin/perl
 use strict;
 if ( @ARGV != 2 ){
    print "usage: /usr/local/bin/htpasswd.pl <username> <password>\n";
}
else {
    print $ARGV[0].":".crypt($ARGV[1],$ARGV[1])."\n";
}

# chmod +x /usr/local/bin/htpasswd.pl

И сгенерируем пару логин пароль:
# /usr/local/bin/htpasswd.pl username password >> /etc/nagios/htpasswd.users

Отредактируем конфигурационные файлы, заменив nagiosadmin на вновь созданного юзера:
# vim /etc/nagios/cgi.cfg 
:%s/nagiosadmin/<username>/g
# vim /etc/nagios/objects/contacts.cfg 
:%s/nagiosadmin/<user>/g

2.5 Создание директории для логов:
# mkdir /var/log/nagios
# chown nagios:nagios /var/log/nagios
# vim /etc/nagios/nagios.cfg
log_file=/var/log/nagios/nagios.log

3. Установка Nagios Plugins 2.1.1:

3.1. Установим зависимости
# apt-get install libssl-dev
# apt-get install libmysqlclient-dev
# apt-get install mysql-client

3.2 Соберем Nagios Plugins из исходников:
# cd /usr/local/src
# wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz
# tar xzf nagios-plugins-2.1.1.tar.gz
# cd nagios-plugins-2.1.1/
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make
# make install

4. Установка NRPE 2.15:
# cd /usr/local/src
# wget http://kent.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
# tar xzf nrpe-2.15.tar.gz
# cd nrpe-2.15
# root@mon:/usr/local/src/nrpe-2.15# ./configure --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu


5. Настройка

Добавим в загрузку nagios:
# update-rc.d -f nagios defaults

Проверим конфигурационный файл:
# /usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg 

Вывод должен быть примерно таким:
Nagios Core 4.1.1
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-19-2015
License: GPL
Website: https://www.nagios.org
Reading configuration data...
   Read main config file okay...
   Read object config files okay...
Running pre-flight check on configuration data...
Checking objects...
Checked 8 services.
Checked 1 hosts.
Checked 1 host groups.
Checked 0 service groups.
Checked 1 contacts.
Checked 1 conNagios Core 4.1.1
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-19-2015
License: GPL
Website: https://www.nagios.org
Reading configuration data...
   Read main config file okay...
   Read object config files okay...
Running pre-flight check on configuration data...
Checking objects...
Checked 8 services.
Checked 1 hosts.
Checked 1 host groups.
Checked 0 service groups.
Checked 1 contacts.
Checked 1 contact groups.
Checked 24 commands.
Checked 5 time periods.
Checked 0 host escalations.
Checked 0 service escalations.
Checking for circular paths...
Checked 1 hosts
Checked 0 service dependencies
Checked 0 host dependencies
Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors:   0
Things look okay - No serious problems were detected during the pre-flight checktact groups.
Checked 24 commands.
Checked 5 time periods.
Checked 0 host escalations.
Checked 0 service escalations.
Checking for circular paths...
Checked 1 hosts
Checked 0 service dependencies
Checked 0 host dependencies
Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors:   0
Things look okay - No serious problems were detected during the pre-flight check

6. Запустим службы
# service nagios start
# service fcgiwrap restart
# service php5-fpm restart

7. Создадим конфигурационный файл для nginx:
# vim /etc/nginx/conf.d/mon.domain.com.conf
server {
    server_name mon.domain.com www.mon.domain.com;
    access_log /var/log/nginx/mon.domain.com.access.log;
    error_log /var/log/nginx/mon.domain.com.error.log;

    auth_basic "Private";
    auth_basic_user_file /etc/nagios/htpasswd.users;

    root /usr/local/nagios/share;
    index index.php index.html;

    location / {
        try_files $uri $uri/ index.php /nagios;
    }

    location /nagios {
        alias /usr/local/nagios/share;
    }

    location ~ ^/nagios/(.*\.php)$ {
        alias /usr/local/nagios/share/$1;
        include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

    location ~ \.cgi$ {
            root /usr/local/nagios/sbin/;
            rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
            include /etc/nginx/fastcgi_params;
fastcgi_param AUTH_USER $remote_user;
          fastcgi_param REMOTE_USER $remote_user;
    fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin/$fastcgi_script_name;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
      }

    location ~ \.php$ {
            include /etc/nginx/fastcgi_params;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
      }
}

Проверим не допустили ли ошибок и перезагружаем nginx:
# nginx -t
# service nginx reload

Установка Postfix для отправки уведомлений:
# apt-get install postfix (Internet site)
# apt-get install heirloom-mailx


Ссылки:

Комментариев нет:

Отправить комментарий