Nagios, NRPE, SNMP | 完全手动配置

以CentOS6 Minimal为例:
监控服务器:安装nagios, nagios-plugin, nrpe, net-snmp-utils
被监控机器:安装nagios-plugin, nrpe, net-snmp, net-snmp-libs
[ 原理 ]
监控服务器:
nagios提供一整套监控机制,本身不具备任何实际监控能力,完全由插件来实现。
nagios-plugin提供了一套基本的监控插件。
nrpe在监控服务器上的作用在于提供了一个check_nrpe可执行程序。
net-snmp-utils提供了一套工具,可以利用snmp协议进行通信。
被监控机器:
nrpe提供了一个入口,使得监控服务器可以通过它来调用被监控机上的程序。
net-snmp提供了一个入口,使得监控服务器可以通过snmp协议从这个入口与被监控机器通信。
net-snmp-libs提供了运行需要的库文件。
[ 基础包 ]
yum install wget make
[ 推荐包 ]
yum install vim
[ 安装与配置 ]
监控服务器-安装:
CentOS6 Minimal系统缺少的而安装指南未提及的依赖的包:perl, openssl-devel
yum install perl openssl-devel
nagios, nagios-plugin官方安装指南 http://nagios.sourceforge.net/docs/3_0/quickstart-fedora.html
net-snmp-utils安装:
yum install net-snmp-utils
官方安装指南疏漏:
设置或关闭防火墙(提供关闭的方法)
service iptables stop
chkconfig iptables off
设置或关闭selinux(提供关闭的方法)
令/etc/selinux/config中的SELINUX=disabled
监控服务器-配置:
提供一个sample:
define contact{
		contact_name                                    zhicheng
		alias                                           zhicheng
		host_notifications_enabled                      1
		service_notifications_enabled                   1
		host_notification_period                        24x7
		service_notification_period                     24x7
		host_notification_options                       d,u,r,f,s,n
		service_notification_options                    w,u,c,r,f,s,n
		host_notification_commands                      notify-host-by-email
		service_notification_commands                   notify-service-by-email
		}
#-------------------------------------------------------------------------------------
define contactgroup{
		contactgroup_name                               monitor-group
		alias                                           monitor-group
		members                                         zhicheng
		}
#-------------------------------------------------------------------------------------
define timeperiod{
        timeperiod_name 24x7
        alias           24 Hours A Day, 7 Days A Week
        sunday          00:00-24:00
        monday          00:00-24:00
        tuesday         00:00-24:00
        wednesday       00:00-24:00
        thursday        00:00-24:00
        friday          00:00-24:00
        saturday        00:00-24:00
        }
#-------------------------------------------------------------------------------------	
define command{
        command_name    check-host-alive
        command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
        }

# 'check_by_snmp' command definition
define command{
        command_name    check_snmp
        command_line    /usr/bin/snmpwalk -v 1 $HOSTADDRESS$ -c liyuanqiu $ARG1$
        }

# 'notify-host-by-email' command definition
define command{
        command_name    notify-host-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState:$
HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Al
ert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
        }

# 'notify-service-by-email' command definition
define command{
        command_name    notify-service-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\
nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT
$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }

# 'check_by_nrpe' command definition
define command {
        command_name    check_nrpe
        command_line    /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ $ARG1$
}
#-------------------------------------------------------------------------------------
define host{
		host_name                                       zc-host
		alias                                           zhicheng's host
		address                                         10.14.21.185
		max_check_attempts                              3
		check_period                                    24x7
		check_command                                   check-host-alive
		contacts                                        zhicheng
		contact_groups                                  monitor-group
		notification_interval                           5
		notification_period                             24x7
		}
#-------------------------------------------------------------------------------------
define hostgroup{
		hostgroup_name                                  zc-host-grp
		alias                                           zhicheng's host group
		members                                         zc-host
		}
#-------------------------------------------------------------------------------------
define service{
		host_name                                       zc-host
		service_description                             check-ps
		check_command                                   check_snmp!.1.3.6.1.4.1.2021.51
		max_check_attempts                              3
		check_interval                                  3
		retry_interval                                  3
		check_period                                    24x7
		notification_interval                           3
		notification_period                             24x7
		contacts                                        zhicheng
		contact_groups                                  monitor-group
		}

define service{
		host_name                                       zc-host
		service_description                             check-load
		check_command                                   check_nrpe!-c check_load
		max_check_attempts                              3
		check_interval                                  3
		retry_interval                                  3
		check_period                                    24x7
		notification_interval                           3
		notification_period                             24x7
		contacts                                        zhicheng
		contact_groups                                  monitor-group
		}
#-------------------------------------------------------------------------------------
define servicegroup{
		servicegroup_name                               service-group
		alias                                           service-group
		servicegroup_members                            check-ps,check-load
		}

被监控机器-安装:
CentOS6 Minimal系统缺少的而安装指南未提及的依赖的包:perl, openssl-devel
yum install perl openssl-devel
注意:./configure参数仅需填写安装路径:/usr/localhost/nagios,另外指南提供了nagios与nagios-plugin两个程序的安装,注意要做公共的部分
net-snmp与net-snmp-libs安装:
yum install net-snmp net-snmp-libs
官方安装指南疏漏:
设置或关闭防火墙(提供关闭的方法)
service iptables stop
chkconfig iptables off
设置或关闭selinux(提供关闭的方法)
令/etc/selinux/config中的SELINUX=disabled
添加对nrpe 5666/TCP端口的监听
在/etc/services中添加一行
nrpe      5666/TCP
保存后重启xinetd服务
被监控机器-配置:
/etc/local/nagios/etc/nrpe.cfg需要配置,用处在于check_nrpe -H localhost -c check_load中的check_load的定义
net-snmp需要配置
vim /etc/snmp/snmpd.conf
提供一个sample:
####
# First, map the community name "public" into a "security name"

#       sec.name  source          community
com2sec zhicheng  0.0.0.0/32      liyuanqiu

# Second, map the security name into a group name:

#       groupName      securityModel securityName
group   MyGRP          v1            zhicheng
group   MyGRP          v2c           zhicheng

# Third, create a view for us to let the group have rights to:

# Make at least  snmpwalk -v 1 localhost -c public system fast again.
#       name           incl/excl     subtree         mask(optional)[0m
view    all            included     .1
view    systemview     included     .1.3.6.1.2.1.1
view    systemview     included     .1.3.6.1.2.1.25.1.1

# Finally, grant the group read-only access to the systemview view.

#       group          context sec.model sec.level prefix read   write  notif[0m
access  MyGRP          ""      any       noauth    exact  all    all    all

syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)

dontLogTCPWrappersConnects yes

extend .1.3.6.1.4.1.2021.51 ps /bin/ps




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值