Chinaunix首页 | 论坛 | 博客
  • 博客访问: 313167
  • 博文数量: 103
  • 博客积分: 1590
  • 博客等级: 上尉
  • 技术积分: 1075
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-02 10:17
文章分类

全部博文(103)

文章存档

2013年(32)

2012年(7)

2010年(64)

我的朋友

分类: LINUX

2010-02-09 20:40:54

来源:
Linux系统监控之 Nagios详解(二)

------使用Nagios监控客户端

ChinaUnix网友:赵舜东

三、使用Nagios监控Linux 客户端Nagios监控的方式:
可以把Nagios的服务器监控分为两个部分:
第一部分是主机外监控,比如:主机是否存活,WEB服务是否正常,MySQL服务是否正常等内容,再主机外通过访问其端口即可得知。这些监控命令再安装nagios-plugins-1.4.13.tar.gz时已经生成了,再/usr/local/nagios/libexec 目录下。
第二部分是主机内监控,比如:要监控服务器的进程、磁盘使用等功能。这些功能的实现要依靠nrpe了,nrpe的工作模式是C/S模式,在被监控主机中,开启nrpe监听,当听到监控服务器上所发出的命令,让它检查该服务器上的硬盘使用信息时,它就会执行,并把信息传回,监控服务器,用一个不太恰当的比喻,就是木马的工作模式。
手机报警短信接收:
在继续前,先讲一下,怎么收到手机短信,在上一篇文章讲了,用139邮箱的短信邮件通知功能,在服务器上只需简单配置一下,Sendmail即可,Sendmail的配置,可在网站上的《Sendmail+Apache+Squid服务的配置与应用》获得。SendMail设置完成后,可以发送一个测试邮件,比如我在服务器上发送一个测试邮件,看手机是否可以正常收到短信。
[root@UnixHot ~]# echo "赵舜东" | mail -s "Nagios-Server" 1371751****@139.com
呵呵,正确收到了!没有设置好139信箱的,赶快设置一下吧。还需注意的是,千万不要用这个邮箱注册其它的什么账号,以免接收垃圾邮件,那会是一场噩梦。
(一)Nagios监控服务器的配置
1.安装nrpe
[root@UnixHot src]# tar zxvf nrpe-2.12.tar.gz
[root@UnixHot nrpe-2.12]# ./configure && make all
[root@UnixHot nrpe-2.12]# make install-plugin
[root@UnixHot nrpe-2.12]# make install-daemon
[root@UnixHot nrpe-2.12]# make install-daemon-config
[root@UnixHot nrpe-2.12]# make install-xinetd
2.配置nrep
[root@UnixHot nrpe-2.12]# vi /etc/xinetd.d/nrpe
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
only_from = 127.0.0.1 192.168.0.206 192.168.0.155 192.168.0.157
only_from 添加要监控的主机的IP地址,中间以空格隔开。
3.添加端口
[root@UnixHot nrpe-2.12]# vi /etc/services 在最后添加
nrpe 5666/tcp #nrpe
4.重新启动Xinetd服务
[root@UnixHot nrpe-2.12]# /etc/init.d/xinetd restart
[root@UnixHot nrpe-2.12]# netstat -na | grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN
以上的1-4的步骤要在客户端上做。
5.修改配置文件commands.cfg加入对nrpe的支持
[root@UnixHot ~]# vi /usr/local/nagios/etc/objects/commands.cfg
#nrpe set
define command{
command_name check_nrpe
command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
6.有哪些nrpe检测命令可以用,它们在哪里呢?
[root@UnixHot ~]# vi /usr/local/nagios/etc/nrpe.cfg
(默认有下面四个命令)
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200

7.怎么使用这些命令监控客户端呢?
其实很简单,就是在services.cfg里面添加服务即可,格式就和上篇文档讲的一样,只是命令不同罢了。
[root@UnixHot ~]# vi /usr/local/nagios/etc/objects/services.cfg
加入:
define service {
host_name Nagios-Server
service_description check-users
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups sagroup
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_nrpe!check_users
}
define service {
host_name Nagios-Server
service_description check-load
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups sagroup
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_nrpe!check_load
}
define service {
host_name Nagios-Server
service_description check-total-procs
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups sagroup
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_total_procs
}
在这里仅列出了一个客户端的配置,其它的客户端,只需修改host_name 即可。
(二)Nagios 监控客户端的配置
1.添加nagios用户
[root@prdora1 ~]# useradd -s /sbin/nologin nagios
2.安装Nagios的插件nagios-plugin
[root@prdora1 src]# tar zxvf nagios-plugins-1.4.13.tar.gz
[root@prdora1 src]# cd nagios-plugins-1.4.13
[root@prdora1 nagios-plugins-1.4.13]# ./configure --enable-redhat-pthread-workaround
注意:因为服务器是AS4.8的所以,添加了一个选项
2.同服务器端安装nrpe
唯一的不同就是修改xinetd.d/nrpe 的时候在only_from 里只加入Nagios服务器的IP地址即可。
3.修改文件所有者
[root@prdora1 ~]# chown -R nagios:nagios /usr/local/nagios
[root@prdora1 ~]# /etc/init.d/xinetd restart
四、使用Nagios 监控Windows 客户端(三)Nagios 监控服务器的配置
对与Nagios监控服务器不需要什么其它的配置,写services.cfg即可。
以下是我监控公司一台Windows 2003 Server的配置:
define service {
host_name Web-Server
service_description Check-Memory
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups sagroup
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_nt!MEMUSE!-w 80 -c 90
}
define service {
host_name Web-Server
service_description Check-Disk-C
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups sagroup
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90
}
define service {
host_name Web-Server
service_description Check-Disk-D
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups sagroup
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_nt!USEDDISKSPACE!-l d -w 80 -c 90
}
(四)Nagios 监控客户端的配置
1.安装NSClient++

下载后,双击运行即可,安装时会提示输入Nagios服务器的IP地址,安装完成后选中启动服务即可。
阅读(694) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~