nagios配置示例

nagios安装请移步至此处

本文之谈论简单的配置


1.删除原有的配置文件

nagios又名“难构死”这个“难”就难在配置,它的配置文件太多了,嵌套太多了容易让人混淆和闷圈,所有索性上来就清空它!

我们自定义配置文件

[root@master etc]# pwd
/usr/local/nagios/etc
[root@master etc]# find
.
./htpasswd                                 //http验证文件
./nagios.cfg                               //nagios的主配置文件
./cgi.cfg                                  //cgi相关配置文件
./resource.cfg                             //定义资源路径
./nrpe.cfg                                 //此配置文件且不说,十一个外部插件的配置文件,部署于nagios自带的配置文件
./objects                                  //配置文件子目录
./objects/contacts.cfg                     // 联系人定义配置文件 
./objects/timeperiods.cfg                  //时间定义配置文件
./objects/commands.cfg                     //检测命令配置文件
./objects/hosts.cfg                        //检测主机的配置文件
./objects/service.cfg                      //检测主机和服务的配置文件
./objects/templates.cfg                    //全局定义配置文件
[root@master etc]# tar -czvf ~/nagios_cfgbackup.tar.gz ./*
[root@master etc]# rm -rf *.cfg objects/*.cfg


2.创建nagios的主配置文件

本配置文件只是去掉了注释和空行,感觉看着直观点儿,如下需要修改和核对的只有分割线中间的部分

# cat nagios.cfg

log_file=/usr/local/nagios/var/nagios.log
#########################需要核对和修改的########################
cfg_file=/usr/local/nagios/etc/objects/commands.cfg      
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/service.cfg
########################################################
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=10
max_check_result_reaper_time=30
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=0
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=0
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=us
illegal_object_name_chars=`~!$%^&*|'"<>?,()=
illegal_macro_output_chars=`~$&|'"<>
use_regexp_matching=0
use_true_regexp_matching=0
admin_email=nagios@localhost
admin_pager=pagenagios@localhost
daemon_dumps_core=0
use_large_installation_tweaks=0
enable_environment_macros=0
debug_level=0
debug_verbosity=1
debug_file=/usr/local/nagios/var/nagios.debug
max_debug_file_size=1000000
allow_empty_hostgroup_assignment=0

2.创建cgi配置文件

无需修改

# cat cgi.cfg
main_config_file=/usr/local/nagios/etc/nagios.cfg
physical_html_path=/usr/local/nagios/share
url_html_path=/nagios
show_context_help=0
use_pending_states=1
use_authentication=0
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=90
result_limit=100
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

3.创建资源定义配置文件

无需修改

# cat resource.cfg 
$USER1$=/usr/local/nagios/libexec

4.创建全局配置文件

# cat objects/templates.cfg 
define contact{
        name                            racadmin    //联系人名称
        service_notification_period     24x7	 //服务异常报警时间段 在时间配置文件中定定义的时间名称
        host_notification_period        24x7     //主机异常报警时间段 在时间配置文件中定定义的时间名称
        service_notification_options    w,u,c,r,f,s  //报价级别w警告,u未知,c紧急,r错误,f和s不详,有兴趣的可以查下资料
        host_notification_options       d,u,r,f,s   //d down,其他的和上边一样
        service_notification_commands   notify-service-by-email	//服务故障报警方式 在命令配置文件command中配置
        host_notification_commands      notify-host-by-email	//主机故障报警方式 在命令配置文件中command中配置
        register                        0      
        }
define host{
        name                            globalhost         //定义主机的全局通用配置
        notifications_enabled           1       	
        event_handler_enabled           1       
        flap_detection_enabled          1      
        process_perf_data               1     
        retain_status_information       1    
        retain_nonstatus_information    1   
	notification_period		24x7
        register                        0  
        }
define host{
	name				racnode                     //定义主机名
	use				globalhost             //引用全局主机定义的所有属性
	check_period			24x7	//检测的时间
	check_interval			1      //检测间隔
	retry_interval			1        //检测重试时间
	max_check_attempts		5       //异常检测最大次数
        check_command           	check-host-alive  //检测主机存活
	notification_period		workhours //通知的时间
	notification_interval		120          //发出通知后再次发出通知的时间   单位是分钟,如果只需要通知一次,则设置为0
	notification_options		d,u,r         //什么情况下给联系人发送通知
	contact_groups			admins      //联系人组
	register			0
	}
define host{
        name                            oggnode
        use                             globalhost
        check_period                    24x7
        check_interval                  1
        retry_interval                  1
        max_check_attempts              5
        check_command                   check-host-alive
        notification_period             workhours
        notification_interval           120
        notification_options            d,u,r
        contact_groups                  admins
        register                        0
        }
define service{
        name                   		generic-service   //定义全局服务熟悉
        active_checks_enabled           1
        passive_checks_enabled          1
        parallelize_check               1
        obsess_over_service             1
        check_freshness                 0
        notifications_enabled           1
        event_handler_enabled           1
        flap_detection_enabled          1
        process_perf_data               1
        retain_status_information       1
        retain_nonstatus_information    1
        is_volatile                     0
        check_period                    24x7
        max_check_attempts              3
        normal_check_interval           10
        retry_check_interval            2
        contact_groups                  admins //联系人配置文件中定义的联系人组
	notification_options		w,u,c,r
        notification_interval           60
        notification_period             24x7
         register                        0  
        }
define service{
	name				oraclerac
	use				generic-service
        max_check_attempts              4
        normal_check_interval           5
        retry_check_interval            1
        register                        0
	}
define service{
        name                            oracleogg  //定义服务的名字
        use                             generic-service //引用全局服务属性的所有参数
        max_check_attempts              4
        normal_check_interval           5
        retry_check_interval            1
        register                        0
        }

5.建立命令配置文件

无需修改


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" | /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" | /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_local_mrtgtraf
	command_line	$USER1$/check_mrtgtraf -F $ARG1$ -a $ARG2$ -w $ARG3$ -c $ARG4$ -e $ARG5$
	}
define command{
        command_name    check_ftp
        command_line    $USER1$/check_ftp -H $HOSTADDRESS$ $ARG1$
        }
define command{
        command_name    check_hpjd
        command_line    $USER1$/check_hpjd -H $HOSTADDRESS$ $ARG1$
        }
define command{
        command_name    check_snmp
        command_line    $USER1$/check_snmp -H $HOSTADDRESS$ $ARG1$
        }
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_dhcp
	command_line	$USER1$/check_dhcp $ARG1$
	}
define command{
        command_name    check_ping
        command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p 5
        }
define command{
        command_name    check_pop
        command_line    $USER1$/check_pop -H $HOSTADDRESS$ $ARG1$
        }
define command{
        command_name    check_imap
        command_line    $USER1$/check_imap -H $HOSTADDRESS$ $ARG1$
        }
define command{
        command_name    check_smtp
        command_line    $USER1$/check_smtp -H $HOSTADDRESS$ $ARG1$
        }
define command{
	command_name	check_tcp
	command_line	$USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$
	}
define command{
	command_name	check_udp
	command_line	$USER1$/check_udp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$
	}
define command{
	command_name	check_nt
	command_line	$USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$
	}
define command{
	command_name	process-host-perfdata
	command_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-perfdata
	command_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_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ 
	}

6.建立主机配置文件

# cat objects/hosts.cfg 
define host{
	use		oggnode     //引用主机定义熟悉 全局配置文件中定义
	host_name	OGG_master  //主机名
	alias		GGmaster    //别名
	address		127.0.0.1   //主机的IP地址
 }
define host{
        use             oggnode
        host_name       OGG_slave
        alias           GGslave
        address         192.168.10.168
}
define hostgroup{
	hostgroup_name	oracle_ogg    //主机组
	alias		goldenget      //别名
	members		OGG_master,OGG_slave     //如上定义的成员
}

7.建立服务监控配置文件

# cat objects/service.cfg 
#############OGG_MASTER###################### 此主机加测两个服务,一个是httpd一个是sshd
define service{
        use                             oracleogg            //全局服务定义 中定义的
        host_name                       OGG_master            //主机配置文件中定义
        service_description             HTTP
	check_command			check_http             //commond配置文件中定义的检测命令
	notifications_enabled		0
        }
define service{
        use                             oracleogg    
        host_name                       OGG_master
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           0
        }
#############OGG_SLAVE###################### 此主集检测一个服务 ssh
define service{
        use                             oracleogg
        host_name                       OGG_slave
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           0
        }

6.建立联系人配置文件

# cat objects/contacts.cfg 
define contact{
        contact_name                   nagiosdba 
	use				racadmins    //全局配置文件中定义
        alias                           Nagios Admin		; Full name of user
        email                           XXXXX@qq.com
        }
define contactgroup{
        contactgroup_name       admins        //定义一个联系人组 全局配置文件中引用
        alias                   Nagios Administrators
        members                 nagiosdba        //定义组的成员
        }

7.建立时间配置文件

# cat objects/timeperiods.cfg       //时间定义在全局配置文件中use
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		09:00-17:00
	tuesday		09:00-17:00
	wednesday	09:00-17:00
	thursday	09:00-17:00
	friday		09:00-17:00
	}
define timeperiod{
	timeperiod_name	none
	alias		No Time Is A Good Time
	}
define timeperiod{
	name			us-holidays
        timeperiod_name         us-holidays
        alias                   U.S. Holidays
        january 1               00:00-00:00     ; New Years
        monday -1 may           00:00-00:00     ; Memorial Day (last Monday in May)
        july 4                  00:00-00:00     ; Independence Day
        monday 1 september      00:00-00:00     ; Labor Day (first Monday in September)
        thursday 4 november     00:00-00:00     ; Thanksgiving (4th Thursday in November)
        december 25             00:00-00:00     ; Christmas
        }
define timeperiod{
        timeperiod_name 24x7_sans_holidays
        alias           24x7 Sans Holidays
	use		us-holidays		; Get holiday exceptions from other timeperiod
        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
        }

8.检测nagios配置文件

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 

Nagios Core 4.0.2
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 11-25-2013
License: GPL

Website: http://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 5 services.
	Checked 2 hosts.
	Checked 1 host groups.
	Checked 0 service groups.
	Checked 1 contacts.
	Checked 1 contact groups.
	Checked 25 commands.
	Checked 5 time periods.
	Checked 0 host escalations.
	Checked 0 service escalations.
Checking for circular paths...
	Checked 2 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       //检测通过
# /etc/init.d/nagios restart
正在启动 nagios:                                          [确定]

打完手工


##########################

迷途小运维原创

作者:john

转载请注明出处

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值