二、监控linux系统
通过上节的学习,我已经把nagios这个平台建立起来了,这节将来实现对linux系统的监控。可以用NRPE插件来实现对linux的监控。插件的工作原理如下:

1.配置被监控的linux主机
1)安装nagios-plugins
#useradd nagios
#tar zxvf nagios-plugins-1.4.14.tar.gz
#cd nagios-plugins-1.4.14
#./configure
#make
#make install
#chown nagios.nagios /usr/local/nagios/
#chown -R nagios.nagios /usr/local/nagios/libexec/
2)安装nrpe
3)配置nrpe
修改allowed_hosts=127.0.0.1为
allowed_hosts=127.0.0.1,192.168.1.168 192.168.1.168是我的nagios监控服务器的地址。
4)开启nrpe daemon
注意:我在学习过程中,全部机器的iptables、SElinux都是关闭的。
5)检测
netstat -lunt查看是否在监听5566端口。如果是就证明已经成功启动。
/usr/local/nagios/libexec/check_nrpe -H localhost 查是否可以利用本地的nrpe插件来监听本地的nrpe daemon检测到的信息。
2.配置nagios监控服务器
1)配置命令定义配置文件
vi /usr/local/nagios/etc/objects/commands.cfg
如果要实现更多的功能,可以在这里定要命令。比如:要定义发送邮件命令,发送手机短信等。
2)配置联系人和联系人组配置文件
vi /usr/local/nagios/etc/objects/contacts.cfg
在定义联系人的时候注意这条语句:use generic-contact,这个是引用模板文件(/usr/local/nagios/etc/objects/templates.cfg)里的。在这个文件里可以增加多个联系人和组。
3)配置监控时间配置文件
(待续)
通过上节的学习,我已经把nagios这个平台建立起来了,这节将来实现对linux系统的监控。可以用NRPE插件来实现对linux的监控。插件的工作原理如下:

1.配置被监控的linux主机
1)安装nagios-plugins
#useradd nagios
#tar zxvf nagios-plugins-1.4.14.tar.gz
#cd nagios-plugins-1.4.14
#./configure
#make
#make install
#chown nagios.nagios /usr/local/nagios/
#chown -R nagios.nagios /usr/local/nagios/libexec/
#wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
#tar xzvf nrpe-2.12.tar.gz
#cd nrpe-2.12
#./configure
#make all
#make install-plugin
#make install-daemon
#make install-daemon-config
#tar xzvf nrpe-2.12.tar.gz
#cd nrpe-2.12
#./configure
#make all
#make install-plugin
#make install-daemon
#make install-daemon-config
#vi /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,192.168.1.168 192.168.1.168是我的nagios监控服务器的地址。
4)开启nrpe daemon
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
5)检测
netstat -lunt查看是否在监听5566端口。如果是就证明已经成功启动。
/usr/local/nagios/libexec/check_nrpe -H localhost 查是否可以利用本地的nrpe插件来监听本地的nrpe daemon检测到的信息。
2.配置nagios监控服务器
1)配置命令定义配置文件
vi /usr/local/nagios/etc/objects/commands.cfg
# 'check-host-alive' command definition
define command{
define command{
command_name
check-host-alive
command_line $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
}
command_line $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
}
# 'check_nrpe ' command definition
define command{
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
2)配置联系人和联系人组配置文件
vi /usr/local/nagios/etc/objects/contacts.cfg
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email nagios@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin
}
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email nagios@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin
}
3)配置监控时间配置文件
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
}
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
}
(待续)
转载于:https://blog.51cto.com/junlee/270125