设为首页 收藏本站
查看: 1072|回复: 0

nagios监控(三)

[复制链接]

尚未签到

发表于 2019-1-16 07:27:31 | 显示全部楼层 |阅读模式
同理添加要监控的服务配置到service.cfg
vi service.cfg
define service {

use generic-service

host_name 197-etiantian-1-1

service_description Current Load

check_command check_nrpe!check_load

max_check_attempts 2

normal_check_interval 4

retry_check_interval 4

check_period 24x7

notification_interval 1440

notification_period 24x7

notification_options w,u,c,r

contact_groups admins

process_perf_data 1

}

define service {

use generic-service

host_name 197-etiantian-1-1

service_description MEM Useage

check_command check_nrpe!check_mem

max_check_attempts 2

normal_check_interval 4

retry_check_interval 4

check_period 24x7

notification_interval 1440

notification_period 24x7

notification_options w,u,c,r

contact_groups admins

process_perf_data 1

}

define service {

use generic-service
host_name 197-etiantian-1-1

service_description Swap Useage

check_command check_nrpe!check_swap

max_check_attempts 10

normal_check_interval 3

retry_check_interval 4

check_period 24x7

notification_interval 480

notification_period workhours

notification_options w,u,c,r

contact_groups admins

process_perf_data 1

}
define service {

use generic-service

host_name 197-etiantian-1-1

service_description Disk Partition

check_command check_nrpe!check_disk

max_check_attempts 8

normal_check_interval 3

retry_check_interval 2

check_period 24x7

notification_interval 360

notification_period 24x7

notification_options w,u,c,r

contact_groups admins

process_perf_data 1

}
define service {

use generic-service

host_name 197-etiantian-1-1

service_description Disk Iostat

check_command check_nrpe!check_iostat!5!11

max_check_attempts 2

normal_check_interval 4

retry_check_interval 4

check_period 24x7

notification_interval 1440

notification_period 24x7

notification_options w,u,c,r
contact_groups admins

process_perf_data 1

}
#*:

1.以上service.cfg 中添加了对磁盘分区、LoadMemSwap、磁盘io 的监控

2.以上hots.cfg service 的内容的详细解释见附录八


若此时执行如下检查nagios 语法命令:
检查语法:

/etc/init.d/nagios checkconfig

会发现报错:

Checking services...

Error: Service check command 'check_nrpe' specified in service 'Swap Useage' for host '197-etiantian-1-1' not

defined anywhere!

省略若干。。

Total Warnings: 0

Total Errors: 5
根据错误提示,我们可以知道,是check_nrpe 插件没有定义导致。

#注意没有出现

Total Warnings: 0

Total Errors: 5
而是出现的
[root@linux objects]# /etc/init.d/nagios checkconfig
Running configuration check...
Nagios Core 3.2.0
……………………….
Processing object config file '/usr/local/nagios/etc/objects/commands.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/contacts.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/timeperiods.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/templates.cfg'...
Processing object config directory '/usr/local/nagios/etc/commands'...
Error: Could not open config directory '/usr/local/nagios/etc/commands' for reading.
………………………….
CONFIG ERROR!  Check your Nagios configuration.
#配置文件没有改IP



需要在commands.cfg 中加入check_nrpe 的插件配置
#vi commands.cfg 进入后按shift+g 切到结尾加入下面内容。

# 'check_nrpe' command definition

define command{

command_name check_nrpe

command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

}
此时重新执行检查语法命令:
检查语法:

/etc/init.d/nagios checkconfig
Total Warnings: 0

Total Errors: 0
注*:修改配置不需要restart

打开网页会出现
It appears as though you do not have permission to view information for any of theservices you requested...

解决方法
[root@nagiosserver objects]#cd /usr/local/nagios/etc
[root@nagiosserver objects]#vi cgi.cfg +119
#把在1.6 节建立的用户oldboy 加到后面,注意用逗号隔开。
#default_user_name=oldboy
authorized_for_system_information=nagiosadmin,oldboy
authorized_for_configuration_information=nagiosadmin,oldboy
authorized_for_system_commands=nagiosadmin,oldboy
authorized_for_all_services=nagiosadmin,oldboy
authorized_for_all_hosts=nagiosadmin,oldboy
authorized_for_all_service_commands=nagiosadmin,oldboy
authorized_for_all_host_commands=nagiosadmin,oldboy


记得reload nagios 命令为:/etc/init.d/nagios reload




增加从nagios 服务器端发起的监控:如url 地址,端口监控
1.添加要监控的服务配置到service.cfg
########check url

#check_weburl (http://blog.etiantian.org) 197-etiantian-1-1

define service{

use generic-service

host_name 197-etiantian-1-1

service_description blog_url

check_command check_weburl!-H blog.etiantian.org

max_check_attempts 3

normal_check_interval 2

retry_check_interval 1

check_period 24x7

notification_interval 30

notification_period 24x7

notification_options w,u,c,r

contact_groups admins

}

#check_weburl(http://blog.etiantian.org/oldboy/) 197-etiantian-1-1

define service{

use generic-service
host_name 197-etiantian-1-1
service_description blog_oldboy_url

check_command check_weburl!-H blog.etiantian.org -u /oldboy/

max_check_attempts 3

normal_check_interval 2

retry_check_interval 1

check_period 24x7

notification_interval 30

notification_period 24x7

notification_options w,u,c,r

contact_groups admins

}
#请注意看以上监控URL 的不同

# 如果你的机器没有blog.etiantian.org WEB 配置, 可以直接用我的博客的公网地址

http://blog.etiantian.org/oldboy/,这样下面就不需要本地解析了。


检查语法:

/etc/init.d/nagios checkconfig

会发现报错:

Checking services...

Error: Service check command 'check_weburl' specified in service 'blog_oldboy_url' for host '197-etiantian-1-1' not defined

anywhere!

Error: Service check command 'check_weburl' specified in service 'blog_url' for host '197-etiantian-1-1' not defined anywhere!

省略若干

Total Warnings: 0

Total Errors: 2

根据错误可以知道,是check_weburl 插件没有定义导致。



、需要在commands.cfg 中加入check_weburl 的插件配置
# 'check_weburl' command definition

define command{

command_name check_weburl

command_line $USER1$/check_http $ARG1$ -w 10 -c 30

}

注意还要添加本地监控的插件:

# 'check_mem' command definition

define command{

command_name check_mem

command_line $USER1$/check_mem -w $ARG1$ -c $ARG2$

}

# 'check_load' command definition

define command{

command_name check_load
command_line $USER1$/check_load -w $ARG1$ -c $ARG2$

#command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

}

# 'check_disk' command definition

define command{

command_name check_disk

command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$

}

注意:以上三个插件命令没加也是正常的,这点有空偶在细看看

如果是测试,注意在nagios 服务器端的/etc/hosts 下加
192.168.1.106 blog.etiantian.org

192.168.1.107 www.etiantian.org

检查语法:

/etc/init.d/nagios checkconfig

Total Warnings: 0

Total Errors: 0

使配置文件生效命令/etc/init.d/nagios reload




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-663748-1-1.html 上篇帖子: nagios监控(二) 下篇帖子: nagios监控(四)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表