Чистая система Debian 8.8 из netinstall.
1 2 3 4 |
useradd nagios groupadd nagcmd usermod -a -G nagcmd nagios usermod -a -G nagcmd www-data |
1 |
apt-get install apache2 php5-gd libapache2-mod-php5 ca-certificates build-essential unzip openssl libssl-dev libgd2-xpm-dev apache2-utils |
1 2 3 4 5 6 7 8 9 10 11 12 |
cd /tmp wget https://downloads.sourceforge.net/project/nagios/nagios-4.x/nagios-4.3.2/nagios-4.3.2.tar.gz tar -xvf nagios-4.3.2.tar.gz rm nagios-4.3.2.tar.gz cd nagios-4.3.2 ./configure --with-nagios-group=nagios --with-command-group=nagcmd make all make install make install-init make install-config make install-commandmode |
1 2 3 4 5 6 7 8 9 |
a2enmod rewrite a2enmod cgi cp sample-config/httpd.conf /etc/apache2/sites-available/nagios4.conf chmod 644 /etc/apache2/sites-available/nagios4.conf a2ensite nagios4.conf htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin service apache2 restart cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/ |
1 2 3 4 5 6 7 8 |
cd /tmp wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz tar -zxf nagios-plugins-2.2.1.tar.gz rm nagios-plugins-2.2.1.tar.gz cd nagios-plugins-2.2.1 ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl make make install |
Проверка синтаксиса конфигурационных файлов Nagios
1 |
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg |
Запуск
nano /etc/systemd/system/nagios.service
1 2 3 4 5 6 7 8 9 10 11 12 |
[Unit] Description=Nagios BindTo=network.target [Install] WantedBy=multi-user.target [Service] User=nagios Group=nagios Type=simple ExecStart=/usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg |
1 2 |
systemctl enable nagios.service systemctl start nagios |
Настройка
1 2 |
mkdir -p /usr/local/nagios/etc/{commands.d,contacts.d,hosts.d,services.d,misc.d} chown -R nagios:nagios /usr/local/nagios/etc/{commands.d,contacts.d,hosts.d,misc.d,services.d} |
nano /usr/local/nagios/etc/cgi.cfg
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 |
main_config_file=/usr/local/nagios/etc/nagios.cfg physical_html_path=/usr/local/nagios/share url_html_path=/nagios show_context_help=1 use_pending_states=1 use_authentication=1 use_ssl_authentication=0 authorized_for_system_information=nagiosadmin authorized_for_configuration_information=nagiosadmin authorized_for_system_commands=nagiosadmin authorized_for_all_services=nagiosadmin authorized_for_all_hosts=nagiosadmin authorized_for_all_service_commands=nagiosadmin authorized_for_all_host_commands=nagiosadmin default_statusmap_layout=5 default_statuswrl_layout=4 ping_syntax=/bin/ping -n -U -c 5 $HOSTADDRESS$ refresh_rate=60 result_limit=0 escape_html_tags=1 action_url_target=_blank notes_url_target=_blank lock_author_names=1 navbar_search_for_addresses=1 navbar_search_for_aliases=1 |
nano /usr/local/nagios/etc/nagios.cfg
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
log_file=/usr/local/nagios/var/nagios.log cfg_dir=/usr/local/nagios/etc/commands.d cfg_dir=/usr/local/nagios/etc/contacts.d cfg_dir=/usr/local/nagios/etc/hosts.d cfg_dir=/usr/local/nagios/etc/services.d cfg_dir=/usr/local/nagios/etc/misc.d object_cache_file=/usr/local/nagios/var/objects.cache precached_object_file=/usr/local/nagios/var/objects.precache resource_file=/usr/local/nagios/etc/resource.cfg status_file=/usr/local/nagios/var/status.dat status_update_interval=10 nagios_user=nagios nagios_group=nagios check_external_commands=1 command_file=/usr/local/nagios/var/rw/nagios.cmd lock_file=/usr/local/nagios/var/nagios.lock temp_file=/usr/local/nagios/var/nagios.tmp temp_path=/tmp event_broker_options=-1 log_rotation_method=d log_archive_path=/usr/local/nagios/var/archives use_syslog=1 log_notifications=1 log_service_retries=1 log_host_retries=1 log_event_handlers=1 log_initial_states=0 log_current_states=1 log_external_commands=1 log_passive_checks=1 service_inter_check_delay_method=s max_service_check_spread=30 service_interleave_factor=s host_inter_check_delay_method=s max_host_check_spread=30 max_concurrent_checks=0 check_result_reaper_frequency=2 max_check_result_reaper_time=5 check_result_path=/usr/local/nagios/var/spool/checkresults max_check_result_file_age=3600 cached_host_check_horizon=15 cached_service_check_horizon=15 enable_predictive_host_dependency_checks=1 enable_predictive_service_dependency_checks=1 soft_state_dependencies=1 auto_reschedule_checks=0 auto_rescheduling_interval=30 auto_rescheduling_window=180 service_check_timeout=60 host_check_timeout=30 event_handler_timeout=30 notification_timeout=30 ocsp_timeout=5 perfdata_timeout=5 retain_state_information=1 state_retention_file=/usr/local/nagios/var/retention.dat retention_update_interval=60 use_retained_program_state=1 use_retained_scheduling_info=1 retained_host_attribute_mask=0 retained_service_attribute_mask=0 retained_process_host_attribute_mask=0 retained_process_service_attribute_mask=0 retained_contact_host_attribute_mask=0 retained_contact_service_attribute_mask=0 interval_length=60 check_for_updates=1 bare_update_check=1 use_aggressive_host_checking=0 execute_service_checks=1 accept_passive_service_checks=1 execute_host_checks=1 accept_passive_host_checks=1 enable_notifications=1 enable_event_handlers=1 process_performance_data=0 obsess_over_services=0 obsess_over_hosts=0 translate_passive_host_checks=0 passive_host_checks_are_soft=0 check_for_orphaned_services=1 check_for_orphaned_hosts=1 check_service_freshness=1 service_freshness_check_interval=60 service_check_timeout_state=c check_host_freshness=0 host_freshness_check_interval=60 additional_freshness_latency=15 enable_flap_detection=1 low_service_flap_threshold=5.0 high_service_flap_threshold=20.0 low_host_flap_threshold=5.0 high_host_flap_threshold=20.0 date_format=euro illegal_object_name_chars=`~!$%^&*|'"<>?,()= illegal_macro_output_chars=`~$&|'"<> use_regexp_matching=0 use_true_regexp_matching=0 admin_email=mail@domen.ru admin_pager=mail@domen.ru daemon_dumps_core=0 use_large_installation_tweaks=1 enable_environment_macros=1 debug_level=0 debug_verbosity=0 debug_file=/usr/local/nagios/var/nagios.debug max_debug_file_size=1000000 allow_empty_hostgroup_assignment=0 host_down_disable_service_checks=1 |
Описание временных периодов
nano /usr/local/nagios/etc/misc.d/timeperiods.cfg
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 |
define timeperiod { timeperiod_name 24x7 alias 24 Hours A Day, 7 Days A Week sunday 00:00-24:00 monday 00:00-24:00 tuesday 00:00-24:00 wednesday 00:00-24:00 thursday 00:00-24:00 friday 00:00-24:00 saturday 00:00-24:00 } define timeperiod { timeperiod_name workhours alias Normal Work Hours monday 08:00-19:00 tuesday 08:00-19:00 wednesday 08:00-19:00 thursday 08:00-19:00 friday 08:00-19:00 } define timeperiod { timeperiod_name non-workhours alias Normal Work Off Hours monday 00:00-08:00,19:00-24:00 tuesday 00:00-08:00,19:00-24:00 wednesday 00:00-08:00,19:00-24:00 thursday 00:00-08:00,19:00-24:00 friday 00:00-08:00,19:00-24:00 saturday 00:00-24:00 sunday 00:00-24:00 } define timeperiod { timeperiod_name none alias Never } |
Контакты оповещения
Общий шаблон контактов
nano /usr/local/nagios/etc/contacts.d/contacts-template.cfg
1 2 3 4 5 6 7 8 9 10 11 12 13 |
define contact { name contact-template-generic host_notifications_enabled 1 service_notifications_enabled 1 host_notification_period 24x7 service_notification_period 24x7 host_notification_options d,u,r service_notification_options w,u,c,r can_submit_commands 1 retain_status_information 1 retain_nonstatus_information 1 register 0 } |
Контакы для оповещения по E-Mail
nano /usr/local/nagios/etc/contacts.d/contacts-email.cfg
1 2 3 4 5 6 7 |
define contact { name contact-template-email use contact-template-generic host_notification_commands notify-host-by-email service_notification_commands notify-service-by-email register 0 } |
Группа контактов
nano /usr/local/nagios/etc/contacts.d/contactgroups-administrator.cfg
1 2 3 4 5 |
define contactgroup { contactgroup_name admins alias All Administrators members admin } |
Контакт
nano /usr/local/nagios/etc/contacts.d/contacts.cfg
1 2 3 4 5 6 |
define contact { contact_name admin alias MyName MyUserName email admin@mydomain.com use contact-template-email } |
Описания хоста
Общий шаблон хоста
nano /usr/local/nagios/etc/hosts.d/host-template-generic.cfg
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
define host { name host-template-generic check_command check-host-alive initial_state u max_check_attempts 3 check_interval 1 retry_interval 1 active_checks_enabled 1 passive_checks_enabled 1 check_period 24x7 obsess_over_host 1 check_freshness 1 event_handler_enabled 1 flap_detection_enabled 0 process_perf_data 0 retain_status_information 1 retain_nonstatus_information 1 notification_interval 20 first_notification_delay 3 notification_period 24x7 notification_options d,u,r,s notifications_enabled 1 register 0 } |
Шаблон с оповещением группы
nano /usr/local/nagios/etc/hosts.d/host-template.cfg
1 2 3 4 5 6 7 |
define host { name host-template use host-template-generic contact_groups admins notification_options d,r,s register 0 } |
Хост группа
nano /usr/local/nagios/etc/hosts.d/hostgroup.cfg
1 2 3 4 5 |
define hostgroup { hostgroup_name localhost alias Local servers members localhost } |
Описания хоста localhost
nano /usr/local/nagios/etc/hosts.d/host.cfg
1 2 3 4 5 6 7 |
define host { host_name localhost alias localhost display_name localhost address 127.0.0.1 use host-template } |
Шаблон описания служб
Общий шаблон
nano /usr/local/nagios/etc/services.d/service-template-generic.cfg
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
define service { name service-template-generic is_volatile 0 initial_state u max_check_attempts 3 check_interval 1 retry_interval 1 active_checks_enabled 1 passive_checks_enabled 1 check_period 24x7 check_freshness 1 event_handler_enabled 1 flap_detection_enabled 0 process_perf_data 0 retain_status_information 1 retain_nonstatus_information 1 notification_interval 20 first_notification_delay 3 notification_period 24x7 notification_options w,u,c,r,f,s notifications_enabled 1 register 0 } |
Шаблон с оповещением группы
nano /usr/local/nagios/etc/services.d/service-template.cfg
1 2 3 4 5 6 7 |
define service { name service-template use service-template-generic notification_options w,u,c,r,s contact_groups admins register 0 } |
Описания служб для хоста localhost
nano /usr/local/nagios/etc/services.d/services.cfg
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 41 42 43 44 45 46 47 48 49 |
define service { hostgroup_name localhost use service-template service_description PING check_command check_ping!100.0,20%!500.0,60% max_check_attempts 10 } define service { hostgroup_name localhost use service-template service_description Root Partition check_command check_local_disk!20%!10%!/ } define service { hostgroup_name localhost use service-template service_description Current Users check_command check_local_users!20!50 } define service { hostgroup_name localhost use service-template service_description Total Processes check_command check_local_procs!250!400!RSZDT } define service { hostgroup_name localhost use service-template service_description Current Load check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0 } define service { hostgroup_name localhost use service-template service_description Swap Usage check_command check_local_swap!20!10 } define service { hostgroup_name localhost use service-template service_description SSH check_command check_ssh } define service { hostgroup_name localhost use service-template service_description HTTP check_command check_http } |
Описанием команд
nano /usr/local/nagios/etc/commands.d/commands.cfg
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 41 42 43 44 |
define command { command_name notify-host-by-email command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$ } define command { command_name notify-service-by-email command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ } define command { command_name check-host-alive command_line $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5 } define command { command_name check_local_disk command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$ } define command { command_name check_local_load command_line $USER1$/check_load -w $ARG1$ -c $ARG2$ } define command { command_name check_local_procs command_line $USER1$/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$ } define command { command_name check_local_users command_line $USER1$/check_users -w $ARG1$ -c $ARG2$ } define command { command_name check_local_swap command_line $USER1$/check_swap -w $ARG1$ -c $ARG2$ } define command { command_name check_http command_line $USER1$/check_http -I $HOSTADDRESS$ $ARG1$ } define command { command_name check_ssh command_line $USER1$/check_ssh $ARG1$ $HOSTADDRESS$ } define command { command_name check_ping command_line $USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p 5 } |
Проверяем синтаксис Nagios и перезапускаем Nagios.
1 2 3 |
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg systemctl restart nagios |