nagios分布式配置

nagios分布式配置

作者:SA Team 2011-03-28 13:39:45

运维

系统运维

分布式 nagios的分布式是通过在主服务端开启nsca接口进行内容的接收,客户端通过调用send_nsca程序,进行内容的传输,服务端在接收到约定格式的内容后,进行告警。以下内容省略了,nagios的主服务端与分布式服务端的安装步骤。

 

 

图-nagios

nagios分布式配置具体过程如下:

  一、NSCA插件安装与配置

  http://nchc.dl.sourceforge.net/sourceforge/nagios/nsca-2.7.2.tar.gz

  编译安装nsca:

  查看源代码

  打印帮助0./configure && make all

  nagios主服务端:

  1.拷贝nsca相关文件至nagios目录

  查看源代码

  打印帮助0cp sample-config/nsca.cfg /usr/local/nagios/etc/

  1cp src/nsca /usr/local/nagios/bin/

  2chown nagios.nagios /usr/local/nagios/etc/nsca.cfg

  3chown nagios.nagios /usr/local/nagios/bin/nsca

  2.配置nsca.cfg文件中password

  查看源代码

  打印帮助0vi /usr/local/nagios/etc/nsca.cfg #去掉password前面的#,设置密码

  1password=xxx

  3.开启nsca程序

  查看源代码

  打印帮助0/usr/local/nagios/bin/nsca -c /usr/local/nagios/etc/nsca.cfg

  4.开启防火墙5667端口

  查看源代码

  打印帮助0iptables -I RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 5667 -j ACCEPT

  nagios分布式服务端:

  1.拷贝send_nsca相关文件至nagios目录

  查看源代码

  打印帮助0cp sample-config/send_nsca.cfg /usr/local/nagios/etc/

  1cp src/send_nsca /usr/local/nagios/bin/

  2chown nagios.nagios /usr/local/nagios/etc/send_nsca.cfg

  3chown nagios.nagios /usr/local/nagios/bin/send_nsca

  2.配置nsca.cfg文件中password

  查看源代码

  打印帮助0vi /usr/local/nagios/etc/send_nsca.cfg #去掉password前面的#,配置与主服务端相同的密码

  1password=xxx

#p#

  二、Nagios主服务端与分布式服务端配置

  nagios主服务端:

  1.修改nagios.cfg文件

  查看源代码

  打印帮助0vi /usr/local/nagios/etc/nagios.cfg

  1#修改以下参数值

  2check_external_commands=1

  3accept_passive_service_checks=1

  4accept_passive_host_checks=1

  2.修改服务与主机的监控,以下为配置示例,该示例定义的服务与主机应该与分布式服务端相同

  查看源代码

  打印帮助00define host{

  01name test

  02use generic-host

  03address 192.168.0.8 #分布式服务端内监控的主机地址

 

  04check_freshness 1 #开启强制刷新

  05freshness_threshold 480 #主服务端强制刷新的时间,具体含义请参考手册

  06passive_checks_enabled 1 #开启被动检测模式

  07active_checks_enabled 0 #关闭主服务端对该服务的主动检测

  08

     

      09}

      10define service{

      11use generic-service #根据实际情况修改

      12host_name test

      13service_description CPU Load

      14check_command check_nrpe!check_load

      15

      16check_freshness 1 #开启强制刷新

      17freshness_threshold 480 #主服务端强制刷新的时间,具体含义请参考手册

      18passive_checks_enabled 1 #开启被动检测模式

      19active_checks_enabled 0 #关闭主服务端对该服务的主动检测

      20}

    #p#

      nagios分布式服务端:

      1.修改nagios.cfg文件

      查看源代码

      打印帮助0vi /usr/local/nagios/etc/nagios.cfg

      1#修改以下参数值

      2enable_notifications=0

      3obsess_over_services=1

      4ocsp_command=submit_service_check_result

      5obsess_over_hosts=1

      6ochp_command=submit_host_check_result

      2.创建submit_service_check_result脚本

      查看源代码

      打印帮助00vi /usr/local/nagios/libexec/submit_service_check_result

      01#!/bin/sh

      02# Arguments:

      03# = host_name (Short name of host that the service is

      04# associated with)

      05# = svc_description (Description of the service)

      06# = state_string (A string representing the status of

      07# the given service – “OK”, “WARNING”, “CRITICAL”

      08# or “UNKNOWN”)

      09# = plugin_output (A text string that should be used

      10# as the plugin output for the service checks)

      11#

      12# Convert the state string to the corresponding return code

      13return_code=-1

      14case “$3” in

      15OK)

      16return_code=0

      17;;

      18WARNING)

      19return_code=1

      20;;

      21CRITICAL)

      22return_code=2

      23;;

      24UNKNOWN)

      25return_code=-1

      26;;

      27esac

      28# pipe the service check info into the send_nsca program, which

      29# in turn transmits the data to the nsca daemon on the central

      30# monitoring server

      31/usr/bin/printf “%s\t%s\t%s\t%s\n” “$1” “$2” “$return_code” “$4” | /usr/local/nagios/bin/send_nsca -H 1.1.1.1(修改为主服务端的ip) -c /usr/local/nagios/etc/send_nsca.cfg

      查看源代码

      打印帮助0chmod +x /usr/local/nagios/libexec/submit_service_check_result

      1chown nagios.nagios submit_service_check_result

      3.创建submit_host_check_result脚本

      查看源代码

      打印帮助00vi /usr/local/nagios/libexec/submit_host_check_result

      01#!/bin/sh

      02# Arguments:

      03# = host_name (Short name of host that the service is

      04# associated with)

      05# = svc_description (Description of the service)

      06# = state_string (A string representing the status of

      07# the given service – “OK”, “WARNING”, “CRITICAL”

      08# or “UNKNOWN”)

      09# = plugin_output (A text string that should be used

      10# as the plugin output for the service checks)

      11#

      12# Convert the state string to the corresponding return code

      13return_code=-1

      14case “$2” in

      15UP)

      16return_code=0

      17;;

      18DOWN)

      19return_code=1

      20;;

      21UNREACHABLE)

      22return_code=2

      23;;

      24esac

      25# pipe the service check info into the send_nsca program, which

      26# in turn transmits the data to the nsca daemon on the central

      27# monitoring server

      28/usr/bin/printf “%s\t%s\t%s\n” “$1” “$return_code” “$3” | /usr/local/nagios/bin/send_nsca -H 1.1.1.1(修改为主服务端的ip) -c /usr/local/nagios/etc/send_nsca.cfg

    #p#

      查看源代码

      打印帮助0chmod +x /usr/local/nagios/libexec/submit_host_check_result

      1chown nagios.nagios submit_host_check_result

      3.在command.cfg文件中定义submit_service_check_result,submit_host_check_result命令

      查看源代码

      打印帮助0vi /usr/local/nagios/etc/objects/command.cfg #加入以下内容

      1define command{

      2command_name submit_service_check_result

      3command_line /usr/local/nagios/libexec/submit_service_check_result $HOSTNAME$ ‘$SERVICEDESC$’ $SERVICESTATE$ ‘$SERVICEOUTPUT$’

      4}

      5define command{

      6command_name submit_host_check_result

      7command_line /usr/local/nagios/libexec/submit_host_check_result $HOSTNAME$ $HOSTSTATE$ ‘$HOSTOUTPUT$’

      8}

      4.配置示例

      查看源代码

      打印帮助00define host{

      01name test

      02use generic-host

      03address 192.168.0.8 #分布式服务端内监控的主机地址

      04}

      05define service{

      06use generic-service #根据实际情况修改

      07host_name test

      08service_description CPU Load

      09check_command check_nrpe!check_load

      10}

      BTW:请注意分布式服务端与主服务端定义主机与服务配置的区别,当分布式服务端定义了主机与服务时,同样需要在主服务端定义一次。以下几个参数无需在分布式服务端特殊定义。

      check_freshness,freshness_threshold,passive_checks_enabled,active_checks_enabled

      freshness_threshold 强制刷新时间,主要的作用是当分布式服务端未提交新的数据时,服务端可以强制进行状态刷新,进行及时的预警。

      如何在不安装分布式nagios的情况下,监控另一防火墙后的内网主机呢?其实方法很多,比如check_ssh,这里共享一个方法,该方法是同事nonamexz想到的。

      通过nagios的自定义变量,在nrpe的命令行增加一个端口的参数,自定义端口,通过防火墙进行映射至内网不同的服务器

      查看源代码

      打印帮助00define command{

      01command_name check_NRPE #定义一个新的命令

      02command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -p $_HOSTPORT$ -t 60

      03}

      04define host{

      05name test

      06use generic-host

      07address 2.2.2.2 #需要监控的服务器的外网地址,比如防火墙地址

      08_PORT 5668 #自定义的外网端口,改端口是通过防火墙进行内的需要监控的服务器的nrpe的端口映射

      09}

      10define service{

      11use generic-service

      12host_name test

      13service_description CPU Load

      14check_command check_NRPE!check_load #这里定义的时候,使用自定义的nrpe

通过文章的介绍,我们清楚的知道了nagios分布式配置全过程!

【编辑推荐】

  • RHEL安装nagios
  • Nagios :扩展提示信息发送方式(smtp, msn, fetion)
  • nagios 安装过程
  • 启动nagios服务
  • 如何编写 Nagios 插件
  • 配置 新的Nagios

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/240705.html<

(0)
运维的头像运维
上一篇2025-04-24 00:09
下一篇 2025-04-24 00:11

相关推荐

  • 个人主题怎么制作?

    制作个人主题是一个将个人风格、兴趣或专业领域转化为视觉化或结构化内容的过程,无论是用于个人博客、作品集、社交媒体账号还是品牌形象,核心都是围绕“个人特色”展开,以下从定位、内容规划、视觉设计、技术实现四个维度,详细拆解制作个人主题的完整流程,明确主题定位:找到个人特色的核心主题定位是所有工作的起点,需要先回答……

    2025-11-20
    0
  • 社群营销管理关键是什么?

    社群营销的核心在于通过建立有温度、有价值、有归属感的社群,实现用户留存、转化和品牌传播,其管理需贯穿“目标定位-内容运营-用户互动-数据驱动-风险控制”全流程,以下从五个维度展开详细说明:明确社群定位与目标社群管理的首要任务是精准定位,需明确社群的核心价值(如行业交流、产品使用指导、兴趣分享等)、目标用户画像……

    2025-11-20
    0
  • 香港公司网站备案需要什么材料?

    香港公司进行网站备案是一个涉及多部门协调、流程相对严谨的过程,尤其需兼顾中国内地与香港两地的监管要求,由于香港公司注册地与中国内地不同,其网站若主要服务内地用户或使用内地服务器,需根据服务器位置、网站内容性质等,选择对应的备案路径(如工信部ICP备案或公安备案),以下从备案主体资格、流程步骤、材料准备、注意事项……

    2025-11-20
    0
  • 如何企业上云推广

    企业上云已成为数字化转型的核心战略,但推广过程中需结合行业特性、企业痛点与市场需求,构建系统性、多维度的推广体系,以下从市场定位、策略设计、执行落地及效果优化四个维度,详细拆解企业上云推广的实践路径,精准定位:明确目标企业与核心价值企业上云并非“一刀切”的方案,需先锁定目标客户群体,提炼差异化价值主张,客户分层……

    2025-11-20
    0
  • PS设计搜索框的实用技巧有哪些?

    在PS中设计一个美观且功能性的搜索框需要结合创意构思、视觉设计和用户体验考量,以下从设计思路、制作步骤、细节优化及交互预览等方面详细说明,帮助打造符合需求的搜索框,设计前的规划明确使用场景:根据网站或APP的整体风格确定搜索框的调性,例如极简风适合细线条和纯色,科技感适合渐变和发光效果,电商类则可能需要突出搜索……

    2025-11-20
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注