nagios配置

B.Nagios客户端
1.准备软件包
 
 
  1. wget http://syslab.comsenz.com/downloads/linux/nagios-plugins-1.4.13.tar.gz
  2. wget http://syslab.comsenz.com/downloads/linux/nrpe-2.12.tar.gz
2.添加nagios账号,准备安装目录
 
 
  1. useradd nagios
3.编译安装nrpe
 
 
  1. tar -xzvf nrpe-2.12.tar.gz
  2. cd nrpe-2.12
  3. ./configure
  4. make all
  5. make install-plugin
  6. make install-daemon
  7. make install-daemon-config
4.安装nagios-plugin
 
 
  1. useradd -s /sbin/nulgin nagios
  2. tar -xzvf nagios-plugins-1.4.13.tar.gz
  3. cd nagios-plugins-1.4.13
  4. ./configure
  5. make && make install
  6. chown -R nagios:nagios /usr/local/nagios/
检查是否已经安装成功,看这个目录下是否有插件文件
 
 
  1. ls /usr/local/nagios/libexec/
5. 配置nrpe
 
 
  1. vim /usr/local/nagios/etc/nrpe.cfg
  2. 找到”allowed_hosts=127.0.0.1 改成 allowed_hosts=127.0.0.1,192.168.188.148”,后边的IPnagios服务端IP
  3. 找到” dont_blame_nrpe=0 改成 dont_blame_nrpe=1
6.一段nrpe启停脚本,放在/etc/init.d/nrpe里
 
 
  1. #!/bin/bash
  2. #
  3. # chkconfig: 2345 55 25
  4. # description: NRPE Daemon
  5. #
  6.  
  7. # source function library
  8. . /etc/rc.d/init.d/functions
  9.  
  10. RETVAL=0
  11.  
  12. prog='nrpe'
  13. NRPE_CFG='/usr/local/nagios/etc/nrpe.cfg'
  14. NRPE_PRG='/usr/local/nagios/bin/nrpe'
  15. NRPE_OPT='-d'
  16. PID_FILE='/var/run/nrpe.pid'
  17.  
  18. start()
  19. {
  20. echo -n $"Starting $prog: "
  21. [ -f $PID_FILE ] && rm -f $PID_FILE
  22. $NRPE_PRG -c $NRPE_CFG $NRPE_OPT
  23. pid=`ps aux | grep -v grep | grep $NRPE_PRG | awk '{print $2}'`
  24. echo $pid > $PID_FILE
  25.  
  26. if ps aux | grep -v grep | grep -q $NRPE_PRG ; then
  27. RETVAL=0
  28. success
  29. else
  30. RETVAL=1
  31. failure
  32. fi
  33. echo
  34. }
  35.  
  36. stop()
  37. {
  38. echo -n $"Stopping $prog: "
  39. ps --pid=`cat $PID_FILE` &>/dev/null
  40. if [ $? -eq 0 ] ; then
  41. kill -9 `cat $PID_FILE`
  42. RETVAL=0
  43. fi
  44. success
  45. echo
  46. RETVAL=0
  47. }
  48.  
  49. case "$1" in
  50. start)
  51. start
  52. ;;
  53. stop)
  54. stop
  55. ;;
  56. restart)
  57. stop
  58. start
  59. ;;
  60. status)
  61. status -p $PID_FILE $prog
  62. RETVAL=$?
  63. ;;
  64. *)
  65. echo $"Usage: $0 {start|stop|restart|status}"
  66. RETVAL=1
  67. esac
  68. exit $RETVAL
6. 启动nrpe
 
 
  1. /etc/init.d/nrpe start
C.Nagios服务端添加被监控机
1.配置监控机目录
 
 
  1. mkdir /opt/hadoop/nagios/etc/servers
  2. vim /opt/hadoop/nagios/etc/nagios.cfg 追加cfg_dir=/opt/hadoop/nagios/etc/servers
2.添加配置的机器
 
 
  1. vim /opt/hadoop/nagios/etc/servers/192.168.188.148.cfg
  2. define host{
  3. use linux-server
  4. host_name 192.168.188.148
  5. alias 192.168.188.148
  6. address 192.168.188.148
  7. }
  8. define service{
  9. use generic-service
  10. host_name 192.168.188.148
  11. service_description check_ping
  12. check_command check_ping!100.0,20%!200.0,50%
  13. max_check_attempts 5
  14. normal_check_interval 1
  15. }
  16. define service{
  17. use generic-service
  18. host_name 192.168.188.148
  19. service_description check_ssh
  20. check_command check_ssh
  21. max_check_attempts 5
  22. normal_check_interval 1
  23. }
3.reload nagios服务端使配置生效
 
 
  1. service nagios reload
重新加载nagios后就可以在nagios的界面上看到新的被监控的机器了
4.添加使用nrpe的监控
 
 
  1. 在/opt/hadoop/nagios/etc/objects/commands.cfg里增加如下行
  2. define command{
  3. command_name check_nrpe
  4. command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
  5. }
在服务器监控配置文件中加入如下行,确保被监控机的nrpe服务是开的
 
 
  1. define service{
  2. use generic-service
  3. host_name 192.168.188.148
  4. service_description check_load
  5. check_command check_nrpe!check_load
  6. max_check_attempts 5
  7. normal_check_interval 1
  8. }
重新加载nagios使配置生效。
 
 
  1. service nagios reload
5.自定义监控脚本
编写脚本check_diskmount.sh
 
 
  1. vim /opt/hadoop/nagios/libexec/check_diskmount.sh
  2. #!/bin/bash
  3. num=`cat /proc/mounts | grep '/disk' | wc -l`
  4. if [ $num -eq 12 ] ; then
  5. echo "OK - mount disk is $num"
  6. exit 0
  7. else
  8. echo "Critical - mount disk is $num"
  9. exit 1
  10. fi
加上可执行权限
 
 
  1. chmod +x /opt/hadoop/nagios/libexec/check_diskmount.sh
在被监控机的nrpe里加入自定义脚本路径
 
 
  1. vim /opt/hadoop/nagios/etc/nrpe.cfg
  2. command[check_diskmount]=/opt/hadoop/nagios/libexec/check_diskmount.sh
重启nrpe
 
 
  1. /etc/init.d/nrpe restart
在nagios服务端加入配置
 
 
  1. vim /opt/hadoop/nagios/etc/servers/192.168.188.148.cfg
  2. define service{
  3. use generic-service
  4. host_name 192.168.188.148
  5. service_description check_diskmount
  6. check_command check_nrpe!check_diskmount
  7. max_check_attempts 3
  8. normal_check_interval 1
  9. }
重新加载nagios,使得配置生效
 
 
  1. service nagios reload
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值