1.Установка необходимых пакетов
1 |
# yum install gcc glibc glibc-common gd gd-devel make net-snmp unzip wget |
2. Установка Nagios 4 из исходного кода
1 |
# cd /tmp |
1 |
# wget -O nagios-4.1.1.tar.gz http://sourceforge.net/projects/nagios/files/latest/download?source=files |
1 |
# tar xvfz nagios-4.1.1.tar.gz |
Создаем пользователя и группу nagios
1 |
# useradd nagios |
Сборка и установка Nagios
1 |
# cd nagios-4.1.1/ |
1 |
# ./configure |
1 |
# make all |
1 |
# make install |
1 |
# make install-init |
1 |
# make install-config |
1 |
# make install-commandmode |
1 |
# make install-webconf |
Проверка файла конфигурации
1 |
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg |
1 2 3 |
Total Warnings: 0 Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check |
Либо
1 |
# /etc/init.d/nagios configtest |
1 2 3 |
Total Warnings: 0 Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check |
Либо
1 |
# /etc/init.d/nagios checkconfig |
1 2 |
Running configuration check... OK. |
Расположение Nagios
1 |
# ls -l /usr/local/nagios/ |
1 2 3 4 5 6 |
drwxrwxr-x 2 nagios nagios 4096 Jan 4 15:27 bin drwxrwxr-x 3 nagios nagios 4096 Jan 4 15:28 etc drwxrwxr-x 2 nagios nagios 4096 Jan 4 15:27 libexec drwxrwxr-x 2 nagios nagios 4096 Jan 4 15:27 sbin drwxrwxr-x 14 nagios nagios 4096 Jan 4 15:27 share drwxrwxr-x 5 nagios nagios 4096 Jan 4 15:30 var |
3. Установка плагинов Nagios (предварительно необходимо подключить репозитарий Epel)
1 |
# yum install nagios-plugins-all |
Подключение плагинов
1 |
# rm -rf /usr/local/nagios/libexec/ |
1 |
# ln -s /usr/lib64/nagios/plugins /usr/local/nagios/libexec |
1 |
# chown -R nagios:nagios /usr/local/nagios/libexec |
4. Запуск и добавление в автозагрузку Nagios
1 |
# systemctl start nagios |
1 |
# chkconfig --level 35 nagios on |
1 |
# systemctl status nagios |
5.Создание пользователя и пароль для HTTP-авторизации
1 |
# htpasswd -c /usr/local/nagios/htpasswd nagiosadmin |
6. Создание необходимых символьных ссылок
1 |
# mkdir /usr/local/nagios/share/nagios |
1 |
# cd /usr/local/nagios/share/nagios/ |
1 |
# ln -s /usr/local/nagios/share/stylesheets/ stylesheets |
1 |
# ln -s /usr/local/nagios/share/js js |
1 |
# ls -l |
1 2 |
lrwxrwxrwx 1 root root 26 Jan 4 15:48 js -> /usr/local/nagios/share/js lrwxrwxrwx 1 root root 36 Jan 4 15:48 stylesheets -> /usr/local/nagios/share/stylesheets/ |
7.Настройка PHP-FPM
Установка
1 |
#yum install nginx php php-fpm php-common |
Добавление пользователя nginx в группу nagios
1 |
# usermod -a -G nagios nginx |
Настройка PHP-FPM
1 |
# cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/nagios.conf |
1 |
# nano /etc/php-fpm.d/nagios.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
[nagios] listen = /var/run/php5-fpm.nagios.sock; 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 ;pm.max_requests = 500 pm.status_path = /status-nagios ping.path = /ping-nagios ping.response = pong request_terminate_timeout = 300 ;request_slowlog_timeout = 0 slowlog = /var/log/php-fpm/nagios-slow.log catch_workers_output = yes ;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com ;php_flag[display_errors] = off 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-nagios |
1 |
# mkdir /var/lib/php/session-nagios |
1 |
# chown -R nagios:nagios /var/lib/php/session-nagios |
1 |
# php-fpm -t |
1 |
# systemctl restart php-fpm |
1 |
# systemctl enable php-fpm |
1 |
# systemctl status php-fpm |
8.Установка и настройка fcgiwrap
1 |
# yum groupinstall 'Development Tools' |
1 |
# yum install fcgi-devel spawn-fcgi |
1 |
# cd /usr/local/src |
1 |
# git clone git://github.com/gnosek/fcgiwrap.git |
1 |
# cd fcgiwrap |
1 |
# autoreconf -i |
1 |
# ./configure |
1 |
# make |
1 |
cc -std=gnu99 -Wall -Wextra -Werror -pedantic -O2 -g3 fcgiwrap.c -lfcgi -o fcgiwrap |
1 |
# make install |
1 2 3 4 |
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 |
Проверка наличия файла
1 |
# file /usr/local/sbin/fcgiwrap |
1 |
/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]=08075a0513c0e72c063847bc4c4b57a0bc8b544b, not stripped |
Редактирование файла /etc/sysconfig/spawn-fcgi
1 |
# nano /etc/sysconfig/spawn-fcgi |
1 2 3 4 5 6 |
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" |
1 |
# systemctl start spawn-fcgi |
Проверяем наличие запущенного процесса
1 |
# ps ax | grep [fF]cgi |
1 |
61831 ? Ss 0:00 /usr/local/sbin/fcgiwrap |
Добавляем в автозагрузку
1 |
# chkconfig --level 35 spawn-fcgi on |
9.Настройка Nginx
1 |
# nano /etc/nginx/conf.d/monitoring.mydomain.com.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
server { listen 80 ; server_name monitoring.mydomain.com; 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/php5-fpm.nagios.sock; 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; } } |
1 |
# nginx -t |
1 |
# systemctl start nginx |
1 |
# systemctl enable nginx |
1 |
# systemctl status nginx |
10.Подключение к WEB-интерфейс Nagios
1 |
http://monitoring.mydomain.com/ |
Логи Nagios
1 |
# tail -f /usr/local/nagios/var/nagios.log |
Источник
http://rtfm.co.ua/nagios-ustanovka-na-centos-7-nginx