1、基础环境安装(系统最小安装)
yum install gcc glibc glibc-common gd gd-devel httpd
2、nagios和 nagios-plus的安装
/usr/sbin/useradd nagios /usr/sbin/groupadd nagcmd /usr/sbin/usermod -G nagcmd nagios /usr/sbin/usermod -G nagcmd apache tar -jxvf nagios-cn- 3 . 2 . 3 .tar.bz2 cd nagios-cn- 3 . 2 . 3 ./configure --with-group=nagios --with-user=nagios --with-command-group=nagcmd --with-gd-lib=/usr/lib --with -gd- inc =/usr/include make all make install make install-init make install-commandmode make install-config make install-webconf htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin ##创建web登录用户名和密码 chown -R nagios.nagios /usr/local/nagios/etc/htpasswd.users tar -zxvf nagios-plugins- 1 . 4 . 16 .tar.gz cd nagios-plus- 1 . 4 . 16 ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-gourp=nagios make&&make install
PS:当安装nagios-plugins-1.4.16时候报错如下
ps/check_http.Tpo -c -o check_http.o check_http.c check_http. c: In function ‘process_arguments’: check_http. c: 312 : error: ‘ssl_version’ undeclared (first use in this function) check_http. c: 312 : error: (Each undeclared identifier is reported only once check_http. c: 312 : error: for each function it appears in .) make[ 2 ]: *** [check_http.o] Error 1 make[ 2 ]: Leaving directory `/data/nagios-plugins- 1 . 4 . 16 /plugins ' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/data/nagios-plugins-1.4.16 ' make: *** [all] Error 2
解决办法:
1 、yum -y install openssl openssl-devel 2 、重新configure
3、配置文件修改
[root@db3 etc]# pwd/usr/local/nagios/etc[root@db3 etc]# tree.├── cgi.cfg ##需要修改├── htpasswd.users├── nagios.cfg ##需要修改├── nagiosgraph.cfg├── objects│ ├── commands.cfg ##需要修改│ ├── contacts.cfg ##需要修改│ ├── localhost.cfg│ ├── printer.cfg│ ├── switch.cfg│ ├── templates.cfg ##需要修改│ ├── timeperiods.cfg│ └── windows.cfg└── resource.cfg
[root@db3 etc]# cat cgi.cfg |grep -v "#" | awk "NF"main_config_file=/usr/local/nagios/etc/nagios.cfgphysical_html_path=/usr/local/nagios/shareurl_html_path=/nagiosshow_context_help=0use_pending_states=1use_authentication=1use_ssl_authentication=0authorized_for_system_information=nagiosadmin,commandauthorized_for_configuration_information=nagiosadmin,commandauthorized_for_system_commands=nagiosadminauthorized_for_all_services=nagiosadminauthorized_for_all_hosts=nagiosadminauthorized_for_all_service_commands=nagiosadminauthorized_for_all_host_commands=nagiosadminstatusmap_background_image=zytianbk.pngdefault_statusmap_layout=0default_statuswrl_layout=4ping_syntax=/bin/ping -n -U -c 5 $HOSTADDRESS$refresh_rate=90escape_html_tags=1action_url_target=_blanknotes_url_target=_blanklock_author_names=1ttf_file=/usr/local/nagios/sbin/simhei.ttfstatusmap_mod=2
nagios.cfg内容如下:
[root@yw_monitor_db etc]# cat nagios.cfg |grep -v "#" | awk "NF"log_file=/usr/local/nagios/var/nagios.logcfg_file=/usr/local/nagios/etc/objects/commands.cfgcfg_file=/usr/local/nagios/etc/objects/contacts.cfgcfg_file=/usr/local/nagios/etc/objects/timeperiods.cfgcfg_file=/usr/local/nagios/etc/objects/templates.cfgcfg_dir=/usr/local/nagios/etc/objects/cfgobject_cache_file=/usr/local/nagios/var/objects.cacheprecached_object_file=/usr/local/nagios/var/objects.precacheresource_file=/usr/local/nagios/etc/resource.cfgstatus_file=/usr/local/nagios/var/status.datstatus_update_interval=10nagios_user=nagiosnagios_group=nagioscheck_external_commands=1command_check_interval=-1command_file=/usr/local/nagios/var/rw/nagios.cmdexternal_command_buffer_slots=4096lock_file=/usr/local/nagios/var/nagios.locktemp_file=/usr/local/nagios/var/nagios.tmptemp_path=/tmpevent_broker_options=-1log_rotation_method=dlog_archive_path=/usr/local/nagios/var/archivesuse_syslog=1log_notifications=1log_service_retries=1log_host_retries=1log_event_handlers=1log_initial_states=0log_external_commands=1log_passive_checks=1service_inter_check_delay_method=smax_service_check_spread=30service_interleave_factor=shost_inter_check_delay_method=smax_host_check_spread=30max_concurrent_checks=0check_result_reaper_frequency=10max_check_result_reaper_time=30check_result_path=/usr/local/nagios/var/spool/checkresultsmax_check_result_file_age=3600cached_host_check_horizon=15cached_service_check_horizon=15enable_predictive_host_dependency_checks=1enable_predictive_service_dependency_checks=1soft_state_dependencies=0auto_reschedule_checks=0auto_rescheduling_interval=30auto_rescheduling_window=180sleep_time=0.25service_check_timeout=60host_check_timeout=30event_handler_timeout=30notification_timeout=30ocsp_timeout=5perfdata_timeout=5retain_state_information=1state_retention_file=/usr/local/nagios/var/retention.datretention_update_interval=60use_retained_program_state=1use_retained_scheduling_info=1retained_host_attribute_mask=0retained_service_attribute_mask=0retained_process_host_attribute_mask=0retained_process_service_attribute_mask=0retained_contact_host_attribute_mask=0retained_contact_service_attribute_mask=0interval_length=60check_for_updates=1bare_update_check=0use_aggressive_host_checking=0execute_service_checks=1accept_passive_service_checks=1execute_host_checks=1accept_passive_host_checks=1enable_notifications=1enable_event_handlers=1process_performance_data=0obsess_over_services=0obsess_over_hosts=0translate_passive_host_checks=0passive_host_checks_are_soft=0check_for_orphaned_services=1check_for_orphaned_hosts=1check_service_freshness=1service_freshness_check_interval=60check_host_freshness=0host_freshness_check_interval=60additional_freshness_latency=15enable_flap_detection=1low_service_flap_threshold=5.0high_service_flap_threshold=20.0low_host_flap_threshold=5.0high_host_flap_threshold=20.0date_format=usp1_file=/usr/local/nagios/bin/p1.plenable_embedded_perl=1use_embedded_perl_implicitly=1illegal_object_name_chars=`~!$%^&*|'"<>?,()=illegal_macro_output_chars=`~$&|'"<>use_regexp_matching=0use_true_regexp_matching=0admin_email=nagios@localhostadmin_pager=pagenagios@localhostdaemon_dumps_core=0use_large_installation_tweaks=0enable_environment_macros=1debug_level=0debug_verbosity=1debug_file=/usr/local/nagios/var/nagios.debugmax_debug_file_size=1000000
commands.cfg的内容如下:
[root@yw_monitor_db objects]# cat commands.cfg |grep -v "#" | awk "NF"define command{command_name notify-host-by-emailcommand_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$}define command{command_name notify-service-by-emailcommand_line /usr/bin/printf "Host: $HOSTALIAS$\nService: $SERVICEDESC$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\nDate/Time: $LONGDATETIME$\nInfo:$SERVICEOUTPUT$\n持续时间:$SERVICEDURATION$" | mail -s " $HOSTALIAS$ $SERVICESTATE$" $CONTACTEMAIL$}define command{command_name notify-service-by-email-163command_line /usr/bin/printf "Host: $HOSTALIAS$\nService: $SERVICEDESC$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\nDate/Time: $LONGDATETIME$\nInfo:$SERVICEOUTPUT$\n持续时间:$SERVICEDURATION$" | mail -s " $HOSTALIAS$ $SERVICESTATE$" $CONTACTEMAIL$}define command{command_name notify-service-by-email-164command_line /usr/local/nagios/bin/send_message.sh $CONTACTEMAIL$ $_SERVICETYPE$ $HOSTALIAS$-$SERVICEDESC$ info:$SERVICEOUTPUT$ Duration:$SERVICEDURATION$}define command{command_name check_mysqlcommand_line $USER1$/check_mysql -H $HOSTADDRESS$ -u nagios -d nagios -p 123456}define command{command_name check_mysql_slavecommand_line $USER1$/check_mysql -H $HOSTADDRESS$ -P13267 -S -uroot -p123456 -s /data/mysql/nagios/logs/mysql.sock}define command{command_name check-host-alivecommand_line $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5}define command{command_name check_local_diskcommand_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$}define command{command_name check_local_loadcommand_line $USER1$/check_load -w $ARG1$ -c $ARG2$}define command{command_name check_local_procscommand_line $USER1$/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$}define command{command_name check_local_userscommand_line $USER1$/check_users -w $ARG1$ -c $ARG2$}define command{command_name check_local_swapcommand_line $USER1$/check_swap -w $ARG1$ -c $ARG2$}define command{command_name check_local_mrtgtrafcommand_line $USER1$/check_mrtgtraf -F $ARG1$ -a $ARG2$ -w $ARG3$ -c $ARG4$ -e $ARG5$}define command{command_name check_ftpcommand_line $USER1$/check_ftp -H $HOSTADDRESS$ $ARG1$}define command{command_name check_hpjdcommand_line $USER1$/check_hpjd -H $HOSTADDRESS$ $ARG1$}define command{command_name check_snmpcommand_line $USER1$/check_snmp -H $HOSTADDRESS$ $ARG1$}define command{command_name check_httpcommand_line $USER1$/check_http -H $HOSTADDRESS$ $ARG1$}define command{command_name check_sshcommand_line $USER1$/check_ssh $ARG1$ $HOSTADDRESS$}define command{command_name check_dhcpcommand_line $USER1$/check_dhcp $ARG1$}define command{command_name check_pingcommand_line $USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p 5}define command{command_name check_popcommand_line $USER1$/check_pop -H $HOSTADDRESS$ $ARG1$}define command{command_name check_imapcommand_line $USER1$/check_imap -H $HOSTADDRESS$ $ARG1$}define command{command_name check_smtpcommand_line $USER1$/check_smtp -H $HOSTADDRESS$ $ARG1$}define command{command_name check_tcpcommand_line $USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$}define command{command_name check_udpcommand_line $USER1$/check_udp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$}define command{command_name check_ntcommand_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$}define command{command_name check_digcommand_line $USER1$/check_dig -H $HOSTADDRESS$ -T $ARG4$ -l $ARG1$ -w $ARG2$ -c $ARG3$}define command{command_name process-host-perfdatacommand_line /usr/bin/printf "%b" "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\n" >> /usr/local/nagios/var/host-perfdata.out}define command{command_name process-service-perfdatacommand_line /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" >> /usr/local/nagios/var/service-perfdata.out}define command{command_name check_nrpecommand_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$}
contacts.cfg的内容如下:
[root@yw_monitor_db objects]# cat contacts.cfg |grep -v "#" | awk "NF"define contact{use generic-contact-163contact_name zhaohaijun-mailalias zhaohaijun-mailemail navyaijm@sina.com}define contact{use generic-contact-164contact_name navyaijm-callalias navyaijm-callemail 18630152179}define contactgroup{contactgroup_name ops_adminalias ops_adminmembers navyaijm-call,navyaijm-mail}
templates.cfg的内容如下:
[root@yw_monitor_db objects]# cat templates.cfg |grep -v "#" | awk "NF"define contact{name generic-contact ; The name of this contact templateservice_notification_period 24x7 ; service notifications can be sent anytimehost_notification_period 24x7 ; host notifications can be sent anytimeservice_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime eventshost_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime eventsservice_notification_commands notify-service-by-email ; send service notifications via emailhost_notification_commands notify-host-by-email ; send host notifications via emailregister 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!}define contact{name generic-contact-163 ; The name of this contact templateservice_notification_period 24x7 ; service notifications can be sent anytimehost_notification_period 24x7 ; host notifications can be sent anytimeservice_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime eventshost_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime eventsservice_notification_commands notify-service-by-email-163 ; send service notifications via emailhost_notification_commands notify-host-by-email ; send host notifications via emailregister 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!}define contact{name generic-contact-164 ; The name of this contact templateservice_notification_period 24x7 ; service notifications can be sent anytimehost_notification_period 24x7 ; host notifications can be sent anytimeservice_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime eventshost_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime eventsservice_notification_commands notify-service-by-email-164 ; send service notifications via emailhost_notification_commands notify-host-by-email ; send host notifications via emailregister 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!}define host{name generic-host ; The name of this host templatenotifications_enabled 1 ; Host notifications are enabledevent_handler_enabled 1 ; Host event handler is enabledflap_detection_enabled 1 ; Flap detection is enabledfailure_prediction_enabled 1 ; Failure prediction is enabledprocess_perf_data 1 ; Process performance dataretain_status_information 1 ; Retain status information across program restartsretain_nonstatus_information 1 ; Retain non-status information across program restartsnotification_period 24x7 ; Send host notifications at any timeregister 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!}define host{name linux-server ; The name of this host templateuse generic-host ; This template inherits other values from the generic-host templatecheck_period 24x7 ; By default, Linux hosts are checked round the clockcheck_interval 5 ; Actively check the host every 5 minutesretry_interval 1 ; Schedule host check retries at 1 minute intervalsactive_checks_enabled 0max_check_attempts 10 ; Check each Linux host 10 times (max)check_command check-host-alive ; Default command to check Linux hostsnotification_period workhours ; Linux ops_admin hate to be woken up, so we only notify during the day; Note that the notification_period variable is being overridden from; the value that is inherited from the generic-host template!notification_interval 120 ; Resend notifications every 2 hoursnotification_options d,u,r ; Only send notifications for specific host statescontact_groups ops_admin ; Notifications get sent to the ops_admin by defaultregister 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!}define host{name windows-server ; The name of this host templateuse generic-host ; Inherit default values from the generic-host templatecheck_period 24x7 ; By default, Windows servers are monitored round the clockcheck_interval 5 ; Actively check the server every 5 minutesretry_interval 1 ; Schedule host check retries at 1 minute intervalsmax_check_attempts 10 ; Check each server 10 times (max)check_command check-host-alive ; Default command to check if servers are "alive"notification_period 24x7 ; Send notification out at any time - day or nightnotification_interval 30 ; Resend notifications every 30 minutesnotification_options d,r ; Only send notifications for specific host statescontact_groups ops_admin ; Notifications get sent to the ops_admin by defaulthostgroups windows-servers ; Host groups that Windows servers should be a member ofregister 0 ; DONT REGISTER THIS - ITS JUST A TEMPLATE}define host{name generic-printer ; The name of this host templateuse generic-host ; Inherit default values from the generic-host templatecheck_period 24x7 ; By default, printers are monitored round the clockcheck_interval 5 ; Actively check the printer every 5 minutesretry_interval 1 ; Schedule host check retries at 1 minute intervalsmax_check_attempts 10 ; Check each printer 10 times (max)check_command check-host-alive ; Default command to check if printers are "alive"notification_period workhours ; Printers are only used during the workdaynotification_interval 30 ; Resend notifications every 30 minutesnotification_options d,r ; Only send notifications for specific host statescontact_groups ops_admin ; Notifications get sent to the ops_admin by defaultregister 0 ; DONT REGISTER THIS - ITS JUST A TEMPLATE}define host{name generic-switch ; The name of this host templateuse generic-host ; Inherit default values from the generic-host templatecheck_period 24x7 ; By default, switches are monitored round the clockcheck_interval 5 ; Switches are checked every 5 minutesretry_interval 1 ; Schedule host check retries at 1 minute intervalsmax_check_attempts 10 ; Check each switch 10 times (max)check_command check-host-alive ; Default command to check if routers are "alive"notification_period 24x7 ; Send notifications at any timenotification_interval 30 ; Resend notifications every 30 minutesnotification_options d,r ; Only send notifications for specific host statescontact_groups ops_admin ; Notifications get sent to the ops_admin by defaultregister 0 ; DONT REGISTER THIS - ITS JUST A TEMPLATE}define service{name generic-service ; The 'name' of this service templateactive_checks_enabled 1 ; Active service checks are enabledpassive_checks_enabled 1 ; Passive service checks are enabled/acceptedparallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major performance problems)obsess_over_service 1 ; We should obsess over this service (if necessary)check_freshness 0 ; Default is to NOT check service 'freshness'notifications_enabled 1 ; Service notifications are enabledevent_handler_enabled 1 ; Service event handler is enabledflap_detection_enabled 1 ; Flap detection is enabledfailure_prediction_enabled 1 ; Failure prediction is enabledprocess_perf_data 1 ; Process performance dataretain_status_information 1 ; Retain status information across program restartsretain_nonstatus_information 1 ; Retain non-status information across program restartsis_volatile 0 ; The service is not volatilecheck_period 24x7 ; The service can be checked at any time of the daymax_check_attempts 3 ; Re-check the service up to 3 times in order to determine its final (hard) statenormal_check_interval 2 ; Check the service every 10 minutes under normal conditionsretry_check_interval 1 ; Re-check the service every two minutes until a hard state can be determinedcontact_groups ops_admin ; Notifications get sent out to everyone in the 'ops_admin' groupnotification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery eventsnotification_interval 5 ; Re-notify about service problems every hournotification_period 24x7 ; Notifications can be sent out at any timeregister 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!}define service{name local-service ; The name of this service templateuse generic-service ; Inherit default values from the generic-service definitionmax_check_attempts 4 ; Re-check the service up to 4 times in order to determine its final (hard) statenormal_check_interval 5 ; Check the service every 5 minutes under normal conditionsretry_check_interval 1 ; Re-check the service every minute until a hard state can be determinedregister 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!}