2007年10月18日星期四

nagios 配置


nagios 2.9 配置


网络监控软件Nagios,个人认为它最大的好处是可以发故障报警短信-只要Nagios监控的对象发生故障,系统就会自动发送短信到手机上。而且可以配置为邮件报警声音报警。最大的好处是--免费!


前几天在网上搜到的nagios配置文章貌似都是旧版本的,路径都不对,正好在这里修正下。


测试平台为FreeBSD 6.22 最小安装 + ports


前期准备


基本准备:配置IP、hostname、etc 就不相信说了



###############################安装web服务器 apache2.2######################


cd /usr/ports/www/apache13


make


make install


make clean



%%%%%%%%%%%使apache和系统一起启动%%%%%%%%%%%


vi /etc/rc.conf


添加


apache_enable="YES"



%%%%%%%%%%%%更改apache的相应设置%%%%%%%%%%%


vi /usr/local/etc/apache/httpd.conf


修改以下内容


ServerAdmin you@your.address



ServerName www.example.com


添加794


AddLanguage zh-cn .zh-cn


添加822


AddCharset GB2312 .gb2312


添加976


NameVirtualHost (your hosts ip)



%%%%%%%%%%%%启动apache%%%%%%%%%%%%%%%%%


/usr/local/sbin/apachectl start




###############################安装nagios服务器 nagios2.9######################


cd /usr/posrts/net-mgmt/nagios


make install clean


使用默认安装就行~~


安装时选中mysql


安装过程中会增加用户 nagios 和用户组 nagios


###############################配置apache 服务器 ######################


修改 /usr/local/etc/apache22/httpd.conf


启动apache 用户为


User nagios
Group nagios
ServerAdmin admin@huang.com


最后增加


#cgi-bin 目录 为/usr/local/www/nagios/cgi-bin


ScriptAlias /nagios/cgi-bin /usr/local/www/nagios/cgi-bin


<Directory "/usr/local/www/nagios/cgi-bin">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/etc/nagios/htpasswd.users
Require valid-user
</Directory>


#nagios 地址为 /usr/local/www/nagios


Alias /nagios /usr/local/www/nagios


<Directory "/usr/local/www/nagios">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/etc/nagios/htpasswd.users
Require valid-user
</Directory>

测试apache


apachectl start 启动服务器



打开浏览器,输入http://IP 如果显示正常则apache配置完成


如果使用webmin 管理服务器的话 在/usr/local/etc/ 下建立apache 链接到apache22


webmin的默认apache配置文件目录名为apache


###############################配置nagios服务器 nagios2.9######################


nagios配置文件在 /usr/local/etc/nagios 目录下 包括


cgi.cfg-sample
commands.cfg-sample
localhost.cfg-sample
nagios.cfg-sample
resource.cfg-sample


修改配置文件名称,将"-sample" 去掉


修改cgi.cfg :


default_user_name=nagios


authorized_for_system_information=nagiosadmin,nagios


authorized_for_configuration_information=nagiosadmin,nagios


authorized_for_all_services=nagiosadmin,nagios


authorized_for_all_hosts=nagiosadmin,nagios


authorized_for_all_service_commands=nagiosadmin,nagios
authorized_for_all_host_commands=nagiosadmin,nagios


增加contactgroups.cfg :


define contactgroup {
contactgroup_name nagios
alias system administrator group
members nagios,sery
}


增加 contacts.cfg :


# In this simple config file, a single contact will receive all alerts.
define contact{
contact_name nagios
alias nagios
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,r
service_notification_commands notify-by-email
#,host-notify-by-sms 如果是通过别的方式报警可以添加
host_notification_commands host-notify-by-email
#,host-notify-by-sms
email kernel@love21cn.com
pager 136811234567
}
define contact {
contact_name sery
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_commands notify-by-email
host_notification_commands host-notify-by-email
email haishi24@163.com
pager 13312345678
}
增加 hostgroup .cfg


define hostgroup {
hostgroup_name web server
alias web server
members web17
# //本例用了一个主机
}


增加 service .cfg


#service definition
##############################################################
# SERVICES #
##############################################################
# Generic service definition template - This is NOT a real service, just a template!
#(模版)
define service{
name linux-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
failure_prediction_enabled 1
process_perf_data 1
retain_status_information 1
retain_nonstatus_information 1
is_volatile 0
register 0
}
##############################################################
# web17 #
##############################################################
# Define a service to "ping" the remote machine
define service{
use linux-service
host_name web17
service_description CURRENT LOAD
check_period 24x7
max_check_attempts 5
normal_check_interval 1
retry_check_interval 1
contact_groups nagios
notification_interval 60
notification_period 24x7
notification_options w,u,c,r
check_command check_local_load
}
# Define a service to check the disk space of the all partition
# on the remote machine. Warning if < 20% free, critical if
# < 10% free space on partition.
define service{
use linux-service
host_name web17
service_description disk_var
check_period 24x7
max_check_attempts 5
normal_check_interval 30
retry_check_interval 10
contact_groups nagios
notification_interval 60
notification_period 24x7
notification_options w,u,c,r
check_command check_local_procs
}


增加 timeperiod .cfg


#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
# }


其他配置文件可以空白 或者直接在nagios.cfg里面注释掉就可以了


使用 nagios -v nagios.cfg 验证,如果没有错误就可以了。


htpasswd -c /usr/local/etc/nagios/htpasswd.users 生成口令文件,用于登录


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


启动 apachectl start


启动 nagios -d /usr/local/etc/nagios/nagios.cfg


web 登录 http://IP/nagios 输入用户名口令就可以登录 了


以上配置只能完成nagios的基本配置,监控主机的话需要修改nagios配置文件和安装nagios插件


建议安装nrpe插件,另外还有其他插件可根据使用情况选择。



没有评论: