Nagios的安装与配置(2)
本帖最后由 monicazhang 于 2015-10-30 21:41 编辑20151030淡然续上
} 添加小太阳模版,镶嵌在nagios页面上。#vi /usr/local/nagios/etc/objects/templates.cfg## 在最后添加define host {name host-pnpaction_url /pnp4nagios/graph?host=$HOSTNAME$&srv=_HOST_register 0}define service {name srv-pnpaction_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$register 0} 最后在hosts.cfg和services.cfg中调用host-pnp和srv-pnp模板#vi hosts.cfgdefine host { use host-pnp host_name nagios-test1 alias nagios test1 address 172.26.188.202 contact_groups admins check_command check-host-alive max_check_attempts 5 notification_interval 10 notification_period 24x7 notification_options d,u,r }#vi services.cfgdefine service { use srv-pnp host_name nagios-test1 service_description check_tcp 80 check_period 24x7 max_check_attempts 4 normal_check_interval 3 retry_check_interval2 contact_groups admins notification_interval 10 notification_period 24x7 notification_options w,u,c,r event_handler_enabled 1 event_handler restart-httpd check_command check_tcp!80
}Nagios的配置配置apache #vi/etc/httpd/conf/httpd.conf找到:ServerName www.example.com:80 nagios安装修改为:ServerName 172.26.188.201 找到:User nobodyGroup #-1修改为:User nagiosGroup nagios找到:DirectoryIndex index.html index.html.var修改为DirectoryIndex index.html index.php接着增加如下内容:AddType application/x-httpd-php .php
为了安全其间,一般情况下要让nagios的web监控界面必须经过授权才能访问,这需要增加验证配置,即在httpd.conf文件最后添加如下信息:#setting for nagiosScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" 开源监控软件<Directory "/usr/local/nagios/sbin">AuthType BasicOptions ExecCGIAllowOverride NoneOrder allow,denyAllow from allAuthName "Nagios Access"AuthUserFile /usr/local/nagios/etc/htpasswdRequire valid-user</Directory>Alias /nagios "/usr/local/nagios/share"<Directory "/usr/local/nagios/share">AuthType BasicOptions NoneAllowOverride NoneOrder allow,denyAllow from allAuthName "nagios Access"AuthUserFile /usr/local/nagios/etc/htpasswd nagios配置Require valid-user</Directory>
创建apache目录验证文件 在上面的配置中,指定了目录验证文件htpasswd,下面要创建这个文件:# htpasswd -c /usr/local/nagios/etc/htpasswd ixdbaNew password: (输入密码) Re-type new password: (再输入一次密码) Adding password for user ixdba这样就在/usr/local/nagios/etc目录下创建了一个htpasswd验证文件,当通过http://ip/nagios/访问时就需要输入用户名和密码了。
配置nagios修改cgi.cfg refresh_rate=30 #nagios主页的刷新时间,我设置成30秒自动刷新use_authentication=1 #开启认证功能default_user_name=ixdba
修改nagios.cfg 去掉以下注释,没有的行添加上去:cfg_file=/usr/local/nagios/etc/objects/commands.cfg #nagios可调用的监控命令cfg_file=/usr/local/nagios/etc/objects/contacts.cfg #联系人配置cfg_file=/usr/local/nagios/etc/objects/contactgroups.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/services.cfg #监控服务配置 监控软件
check_external_commands=1 #允许web下重启nagioscommand_check_interval=10s #命令检查时间间隔
修改commands.cfg 添加nrpe的定义:# 'check_nrpe ' command definitiondefine command{command_namecheck_nrpecommand_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$}
修改contacts.cfg 添加联系人信息,内容如下:define contact { contact_name test1 alias system administrator service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r host_notification_options d,u,r service_notification_commandsnotify-service-by-email host_notification_commands notify-host-by-email email test1@ nagios实施 }
修改contactgroups.cfg 添加联系人组信息,内容如下:define contactgroup { contactgroup_name admins alias system administrator group members test1}
添加被监控机监控机配置 首先/usr/local/nagios/libexec/check_nrpe -H $被监控主机ip应该都能输出 NRPE 的版本: NRPE v2.13nagios的全部配置文件在:/usr/local/nagios/etc目录下面 nagios培训
修改hosts.cfg hosts.cfg定义被监控机的主机信息,配置如下:
待续:http://ITIL-foundation.cn/thread-53044-1-1.html
本帖关键字:Nagios
页:
[1]