温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Nagios 使用技巧

发布时间:2020-07-12 03:10:57 来源:网络 阅读:609 作者:secboy 栏目:移动开发

Nagios 使用技巧


需求1.Nagios针对一台主机上的多个域名进行监控

Solution:

使用 check_http插件对站点的状态码进行检测

vim command.cfg

define command{

command_name check_http

command_line $USER1$/check_http -I $ARG1$ -u $ARG2$ -e $ARG3$

}

vim services.cfg


define service{

host_name Web103

service_description check-Web103

max_check_attempts 5

normal_check_interval 3

retry_check_interval 2

check_period 24x7

notification_interval 10

notification_period 24x7

notification_options w,u,c,r

contact_groups admins

check_command check_http!10.100.100.103!http://www.pongo.cn/check/check.html!"200"

}

参数解释:

-I Ipaddress

-u uri

-e 状态码


需求2:Nagios设置报警间隔和报警次数

solution:

注:本次演示主机的,服务的也一样


1.定义从第1次到第5次通知的时间间隔为10分钟

define host {

host_name Web103

alias Web103

address 10.100.100.103

check_command check-host-alive

notification_options d,u,r

check_interval 1

max_check_attempts 2

first_notification 1

last_notification 5

contact_groups admins

notification_interval 10

notification_period 24x7

}


2.从第5次到第10次通知的间隔为30分钟

define host {

host_name Web103

alias Web103

address 10.100.100.103

check_command check-host-alive

notification_options d,u,r

check_interval 1

max_check_attempts 2

first_notification 5

last_notification 10

contact_groups admins

notification_interval 30

notification_period 24x7

}


3.从第10次以后不能通告,直到恢复

define host {

host_name Web103

alias Web103

address 10.100.100.103

check_command check-host-alive

notification_options d,u,r

check_interval 1

max_check_attempts 2

first_notification 10

last_notification 0

contact_groups admins

notification_interval 0

notification_period 24x7

}


注:每次通知都可以设置不同的身份人。


需求3:定义常用服务和主机模板

solution:


将每个服务常用的一些策略和选项放在一起,在每个服务中使用use 应用

define service {

name Web

contact_groups admins

check_period 24x7

normal_check_interval 3

retry_check_interval 2

notification_interval 10

max_check_attempts 5

notification_period 24x7

notification_options w,u,c,r

}


define service {

use Web

host_name Web103

service_description WebSite_hire.pongo.cn

check_command check_web!10.100.100.103!http://hire.pongo.cn/check/check.html!"200"

}


注:由上面可以看出,定义服务时省去了很多选项,使代码看起来越简练,主机的模板和服务的定义类似。


需求4.使用nagios的声音功能,及时了解主机或服务的状态

solution:

# Note: All audio files must be placed in the /media subdirectory

# under the HTML path (i.e. /usr/local/nagios/share/media/).


host_unreachable_sound=hostdown.wav

host_down_sound=hostdown.wav

service_critical_sound=critical.wav

service_warning_sound=warning.wav

service_unknown_sound=warning.wav

normal_sound=noproblem.wav


将声音文件放到/usr/local/nagios/share/media/即可(根据你的安装路径来定),当服务或主机触发不同级别的时候,就会发出不同的声音。



需求5:服务器数量众多,我想为同类型的服务器,主机或服务配置文件放到一个文件中。

solution:

为不同应用类型创建目录和文件

#cd /usr/local/nagios/etc/objects

#mkdir mysql web *** switch

#cd web

#touch services.cfg host.cfg

#vim /usr/local/nagios/etc/nagios.cfg

cfg_dir=/usr/local/nagios/etc/objects/web

cfg_file=/usr/local/nagios/etc/objects/web/host.cfg

cfg_file=/usr/local/nagios/etc/objects/web/services.cfg

注:其它应用类型和上面添加方法相同。


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI