👨⚕️️ Установка и настройка Nagios 4 на RHEL / CentOS 8 |

👨⚕️️ Установка и настройка Nagios 4 на RHEL / CentOS 8

Мануал

В этом руководстве объясняется, как установить и настроить Nagios 4 в RHEL / CentOS 8.

Nagios – это инструмент для мониторинга хоста, службы, процесса и сети с открытым исходным кодом для различных операционных систем, таких как Linux, Windows, BSD, AIX и т.д.

Nagios настраивается с использованием текстовых файлов и предоставляет интуитивно понятный веб-интерфейс для администрирования и мониторинга.

В случае возникновения проблемы, снижения качества обслуживания или перерыва в работе, Nagios отправит оповещения по электронной почте, SMS или даже по телефону, если настроен для этого.

Выполните следующие действия, чтобы установить и настроить сервер мониторинга Nagios 4 в RHEL / CentOS 8.

Шаг 1. Установите зависимости

Рекомендуется работать в обновленной системе.

sudo dnf update

Установите необходимые зависимости для сборки и запуска Nagios Server на RHEL / CentOS 8.

sudo dnf install @perl @httpd wget unzip glibc automake glibc-common gettext autoconf php php-cli gcc gd gd-devel net-snmp openssl-devel unzip net-snmp postfix net-snmp-utils
sudo dnf groupinstall "Development Tools"

После установки запустите и включите службы httpd и php-fpm.

sudo systemctl enable --now httpd php-fpm

Подтвердите статус службы

$ systemctl status httpd php-fpm
 ● httpd.service - The Apache HTTP Server
    Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Drop-In: /usr/lib/systemd/system/httpd.service.d
            └─php-fpm.conf
    Active: active (running) since Mon 2019-03-18 21:07:31 EAT; 17min ago
      Docs: man:httpd.service(8)
  Main PID: 794 (httpd)
    Status: "Running, listening on: port 443, port 80"
     Tasks: 213 (limit: 11510)
    Memory: 38.0M
    CGroup: /system.slice/httpd.service
            ├─794 /usr/sbin/httpd -DFOREGROUND
            ├─810 /usr/sbin/httpd -DFOREGROUND
            ├─811 /usr/sbin/httpd -DFOREGROUND
            ├─812 /usr/sbin/httpd -DFOREGROUND
            └─813 /usr/sbin/httpd -DFOREGROUND
 Mar 18 21:07:30 rhel8.local systemd[1]: Starting The Apache HTTP Server…
 Mar 18 21:07:31 rhel8.local httpd[794]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using rhel8.local. Set >
 Mar 18 21:07:31 rhel8.local httpd[794]: Server configured, listening on: port 443, port 80
 Mar 18 21:07:31 rhel8.local systemd[1]: Started The Apache HTTP Server.

 ● php-fpm.service - The PHP FastCGI Process Manager
    Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
    Active: active (running) since Mon 2019-03-18 21:07:31 EAT; 17min ago
  Main PID: 795 (php-fpm)
    Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
     Tasks: 6 (limit: 11510)
    Memory: 43.2M
    CGroup: /system.slice/php-fpm.service
            ├─ 795 php-fpm: master process (/etc/php-fpm.conf)
            ├─1023 php-fpm: pool www
            ├─1030 php-fpm: pool www
            ├─1033 php-fpm: pool www
            ├─1043 php-fpm: pool www
            └─1087 php-fpm: pool www
 Mar 18 21:07:30 rhel8.local systemd[1]: Starting The PHP FastCGI Process Manager…
 Mar 18 21:07:31 rhel8.local systemd[1]: Started The PHP FastCGI Process Manager.

Шаг 2: Загрузите Nagios Core

Проверьте страницу релизов для последних доступных Nagios.

Сначала измените ваш рабочий каталог на /usr/src.

sudo su -
cd /usr/src

Затем скачайте и распакуйте архив Nagios.

export VER="4.4.3"
curl -SL https://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-$VER/nagios-$VER.tar.gz | tar -xzf -

Перейдите в созданную папку Nagios.

cd nagios-$VER

Шаг 3: Компиляция ядра Nagios на RHEL / CentOS 8

1. После распаковки архива запустите скрипт настройки

./configure

Пример вывода

2. Запустите команду make с опцией all , чтобы скомпилировать основную программу и CGI.

make all

4. Установите скрипт инициализации в /lib/systemd/system.

# make install-init
/usr/bin/install -c -m 755 -d -o root -g root /lib/systemd/system
 /usr/bin/install -c -m 755 -o root -g root startup/default-service /lib/systemd/system/nagios.service

5.Установите и настройте разрешения для каталога для хранения внешнего командного файла.

# make install-commandmode
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw
*** External command directory configured ***

6. Установите примеры конфигурационных файлов в  /usr/local/nagios/etc.

# 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.

7.Установите файл конфигурации Apache для веб-интерфейса Nagios.

# make install-webconf
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
if [ 0 -eq 1 ]; then \
    ln -s /etc/httpd/conf.d/nagios.conf /etc/apache2/sites-enabled/nagios.conf; \
fi
*** Nagios/Apache conf file installed ***

8. Установите тему Exfoliation для веб-интерфейса Nagios.

# make install-exfoliation
*** Exfoliation theme installed ***
 NOTE: Use 'make install-classicui' to revert to classic Nagios theme

9.Установите классическую тему для веб-интерфейса Nagios.

# make install-classicui
*** Classic theme installed ***
 NOTE: Use 'make install-exfoliation' to use new Nagios theme

Шаг 4: Создание пользователя Nagios Web

Вам необходимо добавить учетную запись пользователя для доступа к веб-интерфейсу Nagios.

Для этого мы будем использовать htpasswd для записи в файл /usr/local/nagios/etc/htpasswd.users.

# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password: 
Re-type new password: 
Adding password for user nagiosadmin

Введите и подтвердите пароль для пользователя.

Вам также необходимо перезапустить службу Apache, чтобы изменения вступили в силу:

sudo systemctl restart httpd

Шаг 5: Установите плагины Nagios

Плагины Nagios используются для расширения функций мониторинга Nagios.

Перейдите в каталог /usr/src.

cd /usr/src

Загрузите плагины Nagios со страницы релизов Github.

VER="2.2.1"
curl -SL https://github.com/nagios-plugins/nagios-plugins/releases/download/release-$VER/nagios-plugins-$VER.tar.gz | tar -xzf -

Перейдите в исходный каталог плагинов:

cd nagios-plugins-$VER

Скомпилируйте и установите плагины Nagios, выполнив команды ниже.

./configure --with-nagios-user=nagios --with-nagios-group=nagios
make && make install

Вы должны увидеть вывод (как ниже)об успешной компиляции.

.....
configure: creating ./config.status
config.status: creating gl/Makefile
config.status: creating nagios-plugins.spec
config.status: creating tools/build_perl_modules
config.status: creating Makefile
config.status: creating tap/Makefile
config.status: creating lib/Makefile
config.status: creating plugins/Makefile
config.status: creating lib/tests/Makefile
config.status: creating plugins-root/Makefile
config.status: creating plugins-scripts/Makefile
config.status: creating plugins-scripts/utils.pm
config.status: creating plugins-scripts/utils.sh
config.status: creating perlmods/Makefile
config.status: creating test.pl
config.status: creating pkg/solaris/pkginfo
config.status: creating po/Makefile.in
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
config.status: executing libtool commands
config.status: executing po-directories commands
config.status: creating po/POTFILES
config.status: creating po/Makefile
.......
make[1]: Leaving directory '/usr/src/nagios-plugins-2.2.1/po'
make[1]: Entering directory '/usr/src/nagios-plugins-2.2.1'
make[2]: Entering directory '/usr/src/nagios-plugins-2.2.1'
make[2]: Nothing to be done for 'install-exec-am'.
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/usr/src/nagios-plugins-2.2.1'
make[1]: Leaving directory '/usr/src/nagios-plugins-2.2.1'

Шаг 6: Проверьте установку и запустите службу Nagios

Убедитесь, что ваша установка Nagios прошла успешно и работает.

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
 Nagios Core 4.4.3
 Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
 Copyright (c) 1999-2009 Ethan Galstad
 Last Modified: 2019-01-15
 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 check

Запустите и включите службу nagios для запуска при загрузке системы.

$ sudo systemctl  enable --now nagios
Created symlink /etc/systemd/system/multi-user.target.wants/nagios.service → /usr/lib/systemd/system/nagios.service.

Статус сервиса должен указывать на работоспособность.

$ systemctl status nagios
 ● nagios.service - Nagios Core 4.4.3
    Loaded: loaded (/usr/lib/systemd/system/nagios.service; enabled; vendor preset: disabled)
    Active: active (running) since Mon 2019-03-18 22:55:35 EAT; 18s ago
      Docs: https://www.nagios.org/documentation
   Process: 29161 ExecStart=/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
   Process: 29159 ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
  Main PID: 29162 (nagios)
     Tasks: 6 (limit: 11510)
    Memory: 2.9M
    CGroup: /system.slice/nagios.service
            ├─29162 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
            ├─29163 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
            ├─29164 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
            ├─29165 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
            ├─29166 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
            └─29167 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
 Mar 18 22:55:35 rhel8.local nagios[29162]: qh: Socket '/usr/local/nagios/var/rw/nagios.qh' successfully initialized
 Mar 18 22:55:35 rhel8.local nagios[29162]: qh: core query handler registered
 Mar 18 22:55:35 rhel8.local nagios[29162]: qh: echo service query handler registered
 Mar 18 22:55:35 rhel8.local nagios[29162]: qh: help for the query handler registered
 Mar 18 22:55:35 rhel8.local nagios[29162]: wproc: Successfully registered manager as @wproc with query handler
 Mar 18 22:55:35 rhel8.local nagios[29162]: wproc: Registry request: name=Core Worker 29165;pid=29165
 Mar 18 22:55:35 rhel8.local nagios[29162]: wproc: Registry request: name=Core Worker 29163;pid=29163
 Mar 18 22:55:35 rhel8.local nagios[29162]: wproc: Registry request: name=Core Worker 29164;pid=29164
 Mar 18 22:55:35 rhel8.local nagios[29162]: wproc: Registry request: name=Core Worker 29166;pid=29166
 Mar 18 22:55:36 rhel8.local nagios[29162]: Successfully launched command file worker with pid 29167

Шаг 7: Доступ к информационной панели Nagios

Разрешите протоколы http и https на брандмауэре.

sudo firewall-cmd --permanent  --add-service={http,https}
sudo firewall-cmd --reload

Во время установки был добавлен файл конфигурации Apache для Nagios.

Вы можете получить доступ к панели управления по адресу http:[IP/hostname]/nagios/

Авторизуйтесь, используя имя пользователя и пароль, добавленные ранее.

Вы должны увидеть Nagios Dashboard, где вы можете добавлять устройства для мониторинга.

Пожалуйста, не спамьте и никого не оскорбляйте. Это поле для комментариев, а не спамбокс. Рекламные ссылки не индексируются!
Добавить комментарий для cryptoparty Отменить ответ

  1. Aleksandr

    Забыли добавить

    make install-groups-users
    usermod -a -G nagios apache
    make install

    Ответить
    1. cryptoparty автор

      Спасибо за дополнение, может поменялось что-то

      Ответить