Nagios服务器架设之二
二、Nagios服务器配置过程
Nagios的配置过程:主机,主机组,服务,服务组,联系人,联系人组,监控时间,监控命令等,配置文件及配置项之间相互关联,彼此引用。
(Nagios配置的核心思想)
最重要的4
点:
第一:要定义监控哪些主机、主机组(hosts.cfg
),服务,服务组(services.cfg)
第二:要定义这个监控项需要通过什么命令实现(commands.cfg)
第三:要定义监控的时间段(timeperiods.cfg)
最后:要定义主机或服务出现问题时要通知的联系人或联系人组(contacts.cfg)
1) 定义hosts.cfg文件(
监控哪些主机、主机组(hosts.cfg))
[root@localhost ~]# cd /usr/local/nagios/etc/
[root@localhost etc]# vi hosts.cfg
define host{
----定义主机
use
linux-server ----主机用户名
host_name
web ----主机名字
alias
benet-web ----主机别名
address 192.168.6.199
----主机IP地址
}
define host{
use
linux-server
host_name
mysql
alias
benet-mysql
address 192.168.6.200
}
define hostgroup{
---定义主机组名字
hostgroup_name sa-servers
---主机组名字
alias
sa servers ---主机组别名
members web,mysql
---有web和mysql两个成员
}
2)定义services.cfg(
监控哪些服务,服务组(services.cfg))
[root@localhost etc]# vi services.cfg
################- benet web -##########################
define service{
use
local-service ---主机用户名
host_name
web
service_description
PING ---服务描述
check_command
check_ping!100.0,20%!500.0,60% ---检测命令及检测返回值用!隔开
}
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
}
define service{
use
local-service
host_name
web
service_description
http
check_command
check_http
}
#####################- 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
}
注意:hosts.cfg和services.cfg两个文件默认在/usr/local/nagios/etc并不存在,需要手动创建。
Check_ping!100.0,20%!500.0,60%
命令!告警延时,丢包率!严重告警延时,丢包率。
Check_ssh!22!10
命令!端口!连接超时时间
3)定义contacts.cfg(
定义主机或服务出现问题时要通知的联系人或联系人组)
[root@localhost etc]# cd /usr/local/nagios/etc/objects/
[root@localhost objects]# vi contacts.cfg
35
email root@localhost ;
4)定义cgi.cfg
[root@localhost etc]# cd /usr/local/nagios/etc/
[root@localhost etc]# vi cgi.cfg
107 default_user_name=benet
119 authorized_for_system_information=nagiosadmin,benet
131 authorized_for_configuration_information=nagiosadmin,benet
144 authorized_for_system_commands=benet
157 authorized_for_all_services=nagiosadmin,benet
158 authorized_for_all_hosts=nagiosadmin,benet
171 authorized_for_all_service_commands=nagiosadmin,benet
172 authorized_for_all_host_commands=nagiosadmin,benet
5)定义nagios.cfg
[root@localhost etc]# vi nagios.cfg
19 log_file=/usr/local/nagios/var/nagios.log
30 cfg_file=/usr/local/nagios/etc/hosts.cfg
31 cfg_file=/usr/local/nagios/etc/services.cfg
32 cfg_file=/usr/local/nagios/etc/commands.cfg
33 cfg_file=/usr/local/nagios/etc/contacts.cfg
34 cfg_file=/usr/local/nagios/etc/timeperiods.cfg
35 cfg_file=/usr/local/nagios/etc/templates.cfg
[root@localhost etc]# cd objects/
[root@localhost objects]# cp commands.cfg contacts.cfg timeperiods.cfg templates.cfg localhost.cfg /usr/local/nagios/etc/
[root@localhost objects]# ls ../
cgi.cfg
hosts.cfg nagios.cfg services.cfg
commands.cfg htpasswd
objects templates.cfg
contacts.cfg localhost.cfg resource.cfg timeperiods.cfg