前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Nagios 监控远程主机

Nagios 监控远程主机

作者头像
dys
发布2018-04-03 18:02:38
2.3K0
发布2018-04-03 18:02:38
举报
文章被收录于专栏:性能与架构性能与架构

上一篇文章介绍了 Nagios服务器的安装,本文继续介绍如何添加被监控的服务器,内容比较枯燥,都是安装过程,但希望能对准备使用Nagios的小伙伴有点帮助

远程监控原理

Nagios 与远程主机的沟通有多种方式,例如 SNMP、Nrpe、SSH 等,这里使用 Nrpe Nrpe 有两部分组成: 1)check_nrpe插件,位于Nagios服务器 2)nrpe daemon,运行在远程主机上,是被监控主机的agent 监控远程主机的过程:

1)Nagios 运行 check_nrpe 插件,说明要获取哪些信息 2)check_nrpe 连接到远程的 nrpe daemon 3)nrpe daemon 运行相应的插件执行检查 4)nrpe daemon 将检查结果返回给 check_nrpe,然后交给nagios处理

安装配置过程

1)被监控主机中安装 Nagios-plugins 和 Nrpe 添加用户 $ useradd -s /sbin/nologin nagios 安装 Nagios-plugins $ yum -y install gcc gcc-c++ make openssl openssl-devel $ wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz $ tar zxf nagios-plugins-2.1.1.tar.gz $ cd nagios-plugins-2.1.1 $ ./configure --with-nagios-user=nagios --with-nagios-group=nagios $ make && make install 安装 Nrpe 下载地址 https://sourceforge.net/projects/nagios/files/latest/download?source=files 得到 nrpe-3.0.1.tar.gz $ tar xf nrpe-3.0.1.tar.gz $ cd nrpe-3.0.1 $ ./configure --with-nrpe-user=nagios \ > --with-nrpe-group=nagios \ > --with-nagios-user=nagios \ > --with-nagios-group=nagios \ > --enable-command-args \ > --enable-ssl $ make all $ make install-plugin $ make install-daemon $ cp sample-config/nrpe.cfg /usr/local/nagios/etc 编辑 /usr/local/nagios/etc/nrpe.cfg 找到 allowed_hosts(这项是设置允许哪些IP访问,多个IP间用逗号分隔),在后面添加 nagios 服务器的IP 保存后启动 nrpe $ /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d 执行 netstat -tnlp 检查 5666 端口是否正常 2)Nagios服务器的安装与配置 安装 Nrpe 下载 nrpe-3.0.1.tar.gz $ tar xf nrpe-3.0.1.tar.gz $ cd nrpe-3.0.1 $ ./configure --with-nrpe-user=nagios \ > --with-nrpe-group=nagios \ > --with-nagios-user=nagios \ > --with-nagios-group=nagios \ > --enable-command-args \ > --enable-ssl (注:user与group名称根据自己情况修改) $ make all $ make install-plugin 安装完成后,会在Nagios安装目录的libexec下生成check_nrpe的插件 $ cd /usr/local/nagios/libexec/ $ ll -d check_nrpe 检查和被监控主机是否正常沟通 ./check_nrpe -H 被监控主机IP 如果成功,会返回被监控主机中nrpe的版本号 配置 $ cd /usr/local/nagios/etc/objects 修改 commands.cfg 末尾添加: define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H "$HOSTADDRESS$" -c "$ARG1$" } 新建服务配置文件 vim myserver1.cfg 添加内容: define host{ use linux-server host_name MyServer1 alias MyServer1 address 192.168.31.188 } define hostgroup{ hostgroup_name linux-servers2 alias linux Servers members MyServer1 } define service{ use generic-service host_name MyServer1 service_description Load check_command check_nrpe!check_load } 需要修改 host 中 address 为被监控主机的IP,保存退出,这里是定义了被监控主机信息,和监控服务,只定义了一个 check_load 服务,以后需要其他服务时,就在此文件中添加 把新建的服务配置文件添加到 nagios 配置文件中 vim /usr/local/nagios/etc/nagios.cfg 找到 cfg_file 这个部分,在后面添加: cfg_file=/usr/local/nagios/etc/objects/myserver1.cfg 保存退出 配置文件语法检查 $ service nagios configtest 重新启动nagios服务 $ service nagios restart 登录 nagios web 界面,就可以看到新增加的主机信息了

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2016-09-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 JAVA高性能架构 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 远程监控原理
  • 安装配置过程
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档