这次配置主要是了解nagios的工作流程,为以后更为复杂的设置打基础!
配置的环境为之前《VMware Linux下Nagios的安装》见 http://www.linuxidc.com/Linux/2011-11/47908.htm 设置出来的
[root@localhost ~]# cd /usr/local/nagios/etc/objects/
[root@localhost objects]# ll
total 88
-rw-rw-r– 1 nagios nagios 7716 May 11 2011 commands.cfg(全局的命令的设置档案)
-rw-rw-r– 1 nagios nagios 2167 Feb 15 04:20 contacts.cfg(联系方式的设置档)
-rw-rw-r– 1 nagios nagios 305 Feb 15 04:46 host.cfg(对主机的监控设置,本来不存在是自己创建的)
-rw-rw-r– 1 nagios nagios 5403 May 11 2011 localhost.cfg(本机的监控设置)
-rw-rw-r– 1 nagios nagios 3124 May 11 2011 printer.cfg(对打印机的监控设置)
-rw-r–r– 1 root root 1768 Feb 15 04:36 services.cfg(对主机的服务的监控设置,本来不存在是自己创建的)
-rw-rw-r– 1 nagios nagios 3293 May 11 2011 switch.cfg(对路由器的监控设置)
-rw-rw-r– 1 nagios nagios 10812 May 11 2011 templates.cfg(全局的监控模板)
-rw-rw-r– 1 nagios nagios 3209 May 11 2011 timeperiods.cfg(全局的时间设置)
-rw-rw-r– 1 nagios nagios 4019 May 11 2011 windows.cfg(对windows主机控制的限制)
这里的配置流程是,在全局的配置档案中设置好相应的控制命令(宏的形式),另外在设置相应的监控设置档案的时候,调用全局的配置档案的设置,来完成对主机和服务的监控!
下边是一个自己配置的小实例
[root@localhost ~]# cd /usr/local/nagios/etc/objects/
[root@localhost objects]# vi host.cfg (设置控制主机)
define host{
use linux-server(设置监控的主机类型,调用在templates.cfg中有对这种类型的定义)
host_name web(设置主机的名称)
alias nagiosadmin-web(设置别名)
address 192.168.1.122(主机的地址)
}
define host{
use linux-server
host_name mysql
alias nagiosadmin-mysql
address 192.168.1.122
}
define hostgroup{(设置主机组)
hostgroup_name sa-servers
alias sa servers
members web,mysql
}
[root@localhost objects]# vi services.cfg (设置控制的服务)
##################### web ###########################
define service{
use local-service //调用templates.cfg中对local-service的定义
host_name web //设置服务对应的主机名
service_description PING //服务的类型
check_command check_ping!100.0.20%!500.0.60% //调用,command.cfg对check_ping的定义
}
define service{
use local-service
host_name web
service_description SSH
check_command check_ssh
}
define service{
use local-service
host_name web
service_description SSHD
check_command check_tcp!22
}
###################### mysql ########################
define service{
use local-service
host_name mysql
service_description PING
check_command check_ping!100.0.20%!500.0.60%
}
define service{
use local-service
host_name mysql
service_description SSH
check_command check_ssh
}
define service{
use local-service
host_name mysql
service_description ftp
check_command check_ftp
}
define service{
use local-service
host_name mysql
service_description mysqlport
check_command check_tcp!3306
}
define servicegroup{ //设置服务的工作组
servicegroup_name servicegroup
alias service-group
members web,PING,web,SSH,web,SSHD,mysql,PING,mysql,SSH,mysql,ftp,mysql,mysqlport //格式很重要的
}
[root@localhost objects]# cd ..
[root@localhost etc]# vi cgi.cfg (对cgi的限定,根据档案相应的注释可以查出其含义)
default_user_name=nagiosadmin //此用户是nagios的管理员用户
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
[root@localhost etc]# vi 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/services.cfg
cfg_file=/usr/local/nagios/etc/objects/host.cfg
cfg_dir=/usr/local/nagios/etc/servers //或者直接设置一个路径,让服务自动的查找
check_external_commands=1 //web下CGI命令(主机、服务启用,关闭….等等)使用的启用与否,0表示否 1表示是
nagios_user=nagios //用户
nagios_group=nagios //用户组
[root@localhost ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (对刚才的设置做一个检查,出现错误的话根据提示修改)
…………………………………………
………………………………………….
Total Warnings: 0 //出现这样的话表示成功啦
Total Errors: 0
最后是web的验证, IE地址栏http://ip/nagios 以nagiosadmin 123登录即可,稍等一段时间观察服务以及主机的状态即可。