以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-develnagios, nagios-plugin官方安装指南http://nagios.sourceforge.net/docs/3_0/quickstart-fedora.html
nrpe官方安装指南http://nagios.sourceforge.net/docs/nrpe/NRPE.pdf
net-snmp-utils安装:
yum install net-snmp-utils
官方安装指南疏漏:
设置或关闭防火墙(提供关闭的方法)
service iptables stop
chkconfig iptables off
设置或关闭selinux(提供关闭的方法)
令/etc/selinux/config中的SELINUX=disabled
监控服务器-配置:
nagios配置官方中文指南:http://nagios-cn.sourceforge.net/nagios-cn/cgiconfig.html#objectdefinitions_contact
提供一个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
nagios-plugin官方安装指南http://nagios.sourceforge.net/docs/3_0/quickstart-fedora.html
注意:./configure参数仅需填写安装路径:/usr/localhost/nagios,另外指南提供了nagios与nagios-plugin两个程序的安装,注意要做公共的部分
nrpe官方安装指南http://nagios.sourceforge.net/docs/nrpe/NRPE.pdf
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
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com