Nagios: установка на CentOS 7 + NGINX

Автор: | 07/01/2015
 

nagios_logoКраткая статья, без особых подробностей.

Установка выполняется на CentOS 7.

Вместо Apache HTTP — будет использоваться NGINX.

Установка Nagios

Важно: у Nagios 3.5 есть проблемы при работе с NGINX. Поэтому — будем устанавливать 4.

Находим тут>>> последнюю версию (на момент написания — это была 4.1), качаем:

# cd /tmp/
# wget http://downloads.sourceforge.net/project/nagios/nagios-4.x/nagios-4.1.0/nagios-4.1.0rc1.tar.gz
# tar xfp nagios-4.1.0rc1.tar.gz

Создаём пользователя и группу:

# useradd nagios

Собираем и устанавливаем Nagios:

# cd nagios-4.1.0rc1
# ./configure

# make all
# make install
# make install-init
# make install-config
# make install-commandmode
# make install-webconf

Проверяем файл конфигурации:

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
...
Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check

Nagios будет установлен в /usr/local/nagios:

# ls -l /usr/local/nagios/
total 12
drwxrwxr-x  2 nagios nagios   36 Jul  2 07:57 bin
drwxrwxr-x  3 nagios nagios   70 Jul  2 07:57 etc
drwxrwxr-x  2 nagios nagios    6 Jul  2 07:57 libexec
drwxrwxr-x  2 nagios nagios 4096 Jul  2 07:57 sbin
drwxrwxr-x 14 nagios nagios 4096 Jul  2 07:57 share
drwxrwxr-x  5 nagios nagios 4096 Jul  2 08:04 var

Устанавливаем репозиторий Epel и плагины Nagios:

# yum install nagios-plugins-all

Подключаем плагины:

# rm -rf /usr/local/nagios/libexec
# ln -s /usr/lib64/nagios/plugins /usr/local/nagios/libexec
# chown -R nagios:nagios /usr/local/nagios/libexec

Запускаем Nagios:

# systemctl start nagios
# systemctl status nagios
nagios.service - SYSV: Starts and stops the Nagios monitor
 Loaded: loaded (/etc/rc.d/init.d/nagios)
 Active: active (running) since Wed 2015-07-01 09:45:00 UTC; 4s ago

Добавляем в автозапуск:

# chkconfig --add nagios

Создаём пользователя и пароль для HTTP-авторизации:

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

Создаём симлинки:

# mkdir /usr/local/nagios/share/nagios
# cd /usr/local/nagios/share/nagios/
# ln -s /usr/local/nagios/share/stylesheets/ stylesheets
# ln -s /usr/local/nagios/share/js js
# ls -l
total 0
lrwxrwxrwx 1 root root 26 Jul  2 09:04 js -> /usr/local/nagios/share/js
lrwxrwxrwx 1 root root 36 Jul  2 09:01 stylesheets -> /usr/local/nagios/share/stylesheets/

Установка NGINX и PHP-FPM

Устанавливаем NGINX, PHP и прочее:

# yum install nginx php php-fpm php-common gcc glibc glibc-common gd gd-devel make net-snmp

Проверяем статус старого Apache HTTP:

# systemctl status httpd
Redirecting to /bin/systemctl status  httpd.service
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
   Active: inactive (dead)

Если запущен — останавливаем и удаляем из автозагрузки:

# systemctl stop httpd.service
# systemctl disable httpd.service

НЕ удаляйте его, т.к. он зависимостями удалит и PHP.

Запускаем NGINX:

# systemctl start nginx.service
# systemctl status nginx.service
nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled)
   Active: active (running) since Tue 2015-06-30 14:48:50 UTC; 2s ago
...

Проверяем:

# systemctl list-unit-files -t service | grep nginx
nginx.service                          enabled

Добавляем в автозапуск:

# systemctl enable nginx.service

Готово:

nagios_install_centos_7_1

Добавляем пользователя nginx в группу nagios:

# usermod -G nagios nginx

Создаём файл настроек PHP для Nagios — /etc/php-fpm.d/nagios.conf:

[nagios]

;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/nagios.socket

listen.allowed_clients = 127.0.0.1

;listen.owner = nagios
;listen.group = nagios
;listen.mode = 0666

user = nagios
group = nagios

pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35

;request_slowlog_timeout = 0

slowlog = /var/log/php-fpm/www-slow.log

;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
php_flag[display_errors] = on
php_admin_value[error_log] = /var/log/php-fpm/nagios-error.log
php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 128M

php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session

Запускаем и проверяем PHP-FPM:

# systemctl start php-fpm
# file /var/run/php-fpm/nagios.socket
/var/run/php-fpm/nagios.socket: socket
# systemctl status php-fpm
php-fpm.service - The PHP FastCGI Process Manager
 Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled)
 Active: active (running) since Wed 2015-07-01 09:44:00 UTC; 17s ago
# systemctl enable php-fpm.service
ln -s '/usr/lib/systemd/system/php-fpm.service' '/etc/systemd/system/multi-user.target.wants/php-fpm.service'

Устанавливаем fcgiwrap.

# yum groupinstall 'Development Tools'
# yum install fcgi-devel spawn-fcgi

Загружаем и собираем его:

# cd /usr/local/src/
# git clone git://github.com/gnosek/fcgiwrap.git
Cloning into 'fcgiwrap'...
remote: Counting objects: 270, done.
remote: Total 270 (delta 0), reused 0 (delta 0), pack-reused 270
Receiving objects: 100% (270/270), 62.89 KiB | 0 bytes/s, done.
Resolving deltas: 100% (139/139), done.
# cd fcgiwrap
# autoreconf -i
# ./configure
# make
cc -std=gnu99 -Wall -Wextra -Werror -pedantic -O2 -g3    fcgiwrap.c  -lfcgi  -o fcgiwrap
# make install
install -d -m 755 /usr/local/sbin
install -m 755 fcgiwrap /usr/local/sbin
install -d -m 755 /usr/local/man/man8
install -m 644 fcgiwrap.8 /usr/local/man/man8

Проверяем — появился ли файл:

# file /usr/local/sbin/fcgiwrap
/usr/local/sbin/fcgiwrap: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=0x09dfb20974c770c2679722f7df7311f616711481, not stripped

Редактируем файл /etc/sysconfig/spawn-fcgi и приводим его к такому виду:

FCGI_SOCKET=/var/run/fcgiwrap.socket
FCGI_PROGRAM=/usr/local/sbin/fcgiwrap
FCGI_USER=nginx
FCGI_GROUP=nginx
FCGI_EXTRA_OPTIONS="-M 0700"
OPTIONS="-u $FCGI_USER -g $FCGI_GROUP -s $FCGI_SOCKET -S $FCGI_EXTRA_OPTIONS -F 1 -P /var/run/spawn-fcgi.pid -- $FCGI_PROGRAM"

Запускаем его:

# systemctl start spawn-fcgi

Проверяем, что бы появился файл сокета:

# file /var/run/fcgiwrap.socket
/var/run/fcgiwrap.socket: socket

Добавляем в автозапуск:

# chkconfig --add spawn-fcgi

Настройка NGINX

Создаём файл /etc/nginx/conf.d/nagios.conf:

server {
        listen   80;
        server_name   52.***.***.174;

        access_log  /var/log/nginx/nagios-access.log;
        error_log   /var/log/nginx/nagios-error.log info;

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

        auth_basic "Nagios Restricted Access";
        auth_basic_user_file /usr/local/nagios/passwd;

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

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

        location ~ .php$ {
                include fastcgi_params;
                fastcgi_pass unix:/var/run/php-fpm/nagios.socket;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /usr/local/nagios/share$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_script_name;
                }

         location ~ (.*.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf))$ {
                root /usr/local/nagios/share/;
                rewrite ^/nagios/(.*) /$1 break;
                access_log off;  expires max;
        }

}

Проверяем, и перезапускаем:

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# systemctl restart nginx
# systemctl status nginx
nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled)
   Active: active (running) since Wed 2015-07-01 10:35:24 UTC; 11s ago

Готово:

nagios_install_centos_7_2

 

Ссылки по теме

http://www.tecmint.com
http://geekpeek.net
http://nightbook.info
http://rtfm.co.ua
http://rtfm.co.ua