A.Nagios服务端
1.安装软件包

  1. yum install -y httpd

2.下载nagios

  1. wget http://syslab.comsenz.com/downloads/linux/nagios-3.0.5.tar.gz
  2. wget http://syslab.comsenz.com/downloads/linux/nagios-plugins-1.4.13.tar.gz
  3. wget http://syslab.comsenz.com/downloads/linux/nrpe-2.12.tar.gz

3.添加nagios账号

  1. useradd nagios

4.编译安装nagios

  1. mkdir /opt/hadoop/
  2. tar -xzvf nagios-3.0.5.tar.gz
  3. cd nagios-3.0.5
  4. ./configure --prefix=/opt/hadoop/nagios
  5. make all
  6. make fullinstall
  7. mkdir /opt/hadoop/nagios/etc
  8. mkdir /opt/hadoop/nagios/etc/objects
  9. cp ./sample-config/cgi.cfg /opt/hadoop/nagios/etc/
  10. cp ./sample-config/nagios.cfg /opt/hadoop/nagios/etc/
  11. cp ./sample-config/resource.cfg /opt/hadoop/nagios/etc/
  12. cp ./sample-config/template-object/commands.cfg /opt/hadoop/nagios/etc/objects/
  13. cp ./sample-config/template-object/contacts.cfg /opt/hadoop/nagios/etc/objects/
  14. cp ./sample-config/template-object/timeperiods.cfg /opt/hadoop/nagios/etc/objects/
  15. cp ./sample-config/template-object/templates.cfg /opt/hadoop/nagios/etc/objects/
  16. cp ./sample-config/template-object/localhost.cfg /opt/hadoop/nagios/etc/objects/
  17. touch /opt/hadoop/nagios/var/nagios.log
  18. chmod -R 755/opt/hadoop/nagios/etc/
  19. chown -R nagios:nagios /opt/hadoop/nagios

5.编译安装nagios-plugins

  1. tar zxvf nagios-plugins-1.4.13.tar.gz
  2. cd nagios-plugins-1.4.13
  3. ./configure --prefix=/opt/hadoop/nagios --with-nagios-user=nagios --with-nagios-group=nagios
  4. make && make install

检查是否已经安装成功,看这个目录下是否有插件文件

  1. ls /opt/hadoop/nagios/libexec/

6.安装nrpe

  1. tar zxvf nrpe-2.12.tar.gz
  2. cd nrpe-2.12
  3. ./configure --prefix=/opt/hadoop/nagios --enable-ssl --enable-command-args
  4. make all
  5. make install-plugin
  6. make install-daemon
  7. make install-daemon-config

7.配置httpd
添加web账号

  1. htpasswd -c /opt/hadoop/nagios/etc/htpasswd.users nagiosadmin

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. mkdir /opt/hadoop/nagios
  2. useradd nagios

3.编译安装nrpe

  1. tar -xzvf nrpe-2.12.tar.gz
  2. cd nrpe-2.12
  3. ./configure --prefix=/opt/hadoop/nagios --enable-ssl --enable-command-args
  4. make all
  5. make install-plugin
  6. make install-daemon
  7. make install-daemon-config

4.安装nagios-plugin

  1. tar -xzvf nagios-plugins-1.4.13.tar.gz
  2. cd nagios-plugins-1.4.13
  3. ./configure --prefix=/opt/hadoop/nagios --with-nagios-user=nagios --with-nagios-group=nagios
  4. make && make install

检查是否已经安装成功,看这个目录下是否有插件文件

  1. ls /opt/hadoop/nagios/libexec/

5. 配置nrpe

  1. vim /opt/hadoop/nagios/etc/nrpe.cfg
  2. 找到”allowed_hosts=127.0.0.1”改成“allowed_hosts=127.0.0.1,10.130.2.72”,后边的IP是nagios服务端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. # source function library
  7. ./etc/rc.d/init.d/functions
  8. RETVAL=0
  9. prog='nrpe'
  10. NRPE_CFG='/opt/hadoop/nagios/etc/nrpe.cfg'
  11. NRPE_PRG='/opt/hadoop/nagios/bin/nrpe'
  12. NRPE_OPT='-d'
  13. PID_FILE='/var/run/nrpe.pid'
  14. start()
  15. {
  16. echo -n $"Starting $prog: "
  17. [-f $PID_FILE ]&& rm -f $PID_FILE
  18. $NRPE_PRG -c $NRPE_CFG $NRPE_OPT
  19. pid=`ps aux | grep -v grep | grep $NRPE_PRG | awk '{print $2}'`
  20. echo $pid > $PID_FILE
  21. if ps aux | grep -v grep | grep -q $NRPE_PRG ;then
  22. RETVAL=0
  23. success
  24. else
  25. RETVAL=1
  26. failure
  27. fi
  28. echo
  29. }
  30. stop()
  31. {
  32. echo -n $"Stopping $prog: "
  33. ps --pid=`cat $PID_FILE`&>/dev/null
  34. if[ $?-eq 0];then
  35. kill -9`cat $PID_FILE`
  36. RETVAL=0
  37. fi
  38. success
  39. echo
  40. RETVAL=0
  41. }
  42. case"$1"in
  43. start)
  44. start
  45. ;;
  46. stop)
  47. stop
  48. ;;
  49. restart)
  50. stop
  51. start
  52. ;;
  53. status)
  54. status -p $PID_FILE $prog
  55. RETVAL=$?
  56. ;;
  57. *)
  58. echo $"Usage: $0 {start|stop|restart|status}"
  59. RETVAL=1
  60. esac
  61. 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/10.130.2.22.cfg
  2. define host{
  3. use linux-server
  4. host_name 10.130.2.22
  5. alias 10.130.2.22
  6. address 10.130.2.22
  7. }
  8. define service{
  9. use generic-service
  10. host_name 10.130.2.22
  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 10.130.2.22
  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 10.130.2.22
  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/10.130.2.22.cfg
  2. define service{
  3. use generic-service
  4. host_name s9xplan2.isv.cm6
  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

摘自:http://www.opstool.com/article/236

(转)CentOS搭建Nagios监控的更多相关文章

  1. 自动安装脚本-------------基于LVMP搭建Nagios 监控

    Mysql初始化参数(mysql-5.6.31) /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local ...

  2. 在Nginx中搭建Nagios监控平台

    本文只做Nginx下Nagiox安装的说明,其它关于Nagios监控的详细配置请参考我的另一篇文章[Ubuntu 10.04下构建Nagios监控平台] Nagios依赖PHP环境和perl环境.由于 ...

  3. 【nagios监控】基于linux搭建nagios监控

    nagios工作原理 nagios的功能是监控服务和主机,但是其自身并不包括这些功能,所有的监控.检测功能都是通过各种插件来完成的. 启动nagios后,它会周期性的自动调用插件去检测服务器状态,同时 ...

  4. CentOS 7.4 下安装部署Nagios监控系统详细攻略(三)

    Nagios是一个流行的电脑系统和网络监控程序,它检测主机和服务,当异常发生和解除时能提醒用户.它是基于GPLv2开发的开源软件,可免费获得及使用. nagios工作原理 nagios的功能是监控服务 ...

  5. centos shell编程6一些工作中实践脚本 nagios监控脚本 自定义zabbix脚本 mysql备份脚本 zabbix错误日志 直接送给bc做计算 gzip innobackupex/Xtrabackup 第四十节课

    centos   shell编程6一些工作中实践脚本   nagios监控脚本 自定义zabbix脚本 mysql备份脚本 zabbix错误日志  直接送给bc做计算  gzip  innobacku ...

  6. Security基础(四):OpenSSL及证书服务常用系统监控命令、搭建nagios监控服务器、配置文件及插件使用、监控远程主机的公有数据、监控远程主机的私有数据

    一.OpenSSL及证书服务常用系统监控命令 目标: 本案例要求练习常用的系统监控命令完成以下任务: 使用vmstat命令监控内存及磁盘I/O信息 使用iostat命令监控CPU处理器及磁盘的I/O信 ...

  7. Nagios监控平台搭建

    Nagios是一款开源的免费网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设置,打印机等.在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员, ...

  8. Centos部署nagios+apache实现服务器监控

    1.Nagios介绍 nagios是 一款功能强大的网络监视工具,它可以有效的监控windows.linux.unix主机状态以及路由器交换机的网络设置,打印机工作状态等,并将状态出 现异常的服务及时 ...

  9. Nagios监控平台搭建及配置文件详解

    Nagios是一款开源的免费网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设置,打印机等.在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员, ...

随机推荐

  1. cf D. Sereja ans Anagrams

    http://codeforces.com/contest/368/problem/D #include <cstdio> #include <cstring> #includ ...

  2. 学EE做硬件找工作不如学CS做软件,为什么会这样?

    学EE做硬件找工作不如学CS做软件,为什么会这样? 电子工程(EE)就业最好的方向居然是转计算机,也许让有的人觉得很不公平,EE也是很重要的学科,我们学习也很努力,为什么就业会不如CS?也有的人好奇, ...

  3. ASP.NET MVC4中的Model验证 移除指定验证信息

    MVC中通过Model在页面间传值使的程序开发变得更加的快捷,但是很多时候,我们在数据传递的时候为了确保数据的有效性,要对Model的相关属性做基本的数据验证. 不多说直接上个代码,Model的实体类 ...

  4. bzoj4002

    http://www.lydsy.com/JudgeOnline/problem.php?id=4002 好吧,完全不会做,在考场只能爆零. 膜拜PoPoQQQ大神 #include<cstdi ...

  5. Quartz集成springMVC 的方案一

    Quartz是一个开放源码项目,专注于任务调度器. springMVC 具体的搭建框架就不具体说明,接下来直接描述把Quartz集成到springMVC 框架中. 步骤: 1.引入所需要的jar包 2 ...

  6. 设计模式--观察者(Observer)

    GOF给出的定义: Define a one-to-many dependency between objects so that when one object changes state, all ...

  7. MyBatis 通过包含的jdbcType类型和java中对应的数据类型

    MyBatis 通过包含的jdbcType类型 BIT         FLOAT      CHAR           TIMESTAMP       OTHER       UNDEFINED ...

  8. (转)iOS Wow体验 - 第四章 - 为应用的上下文环境而设计

    本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第四章译文精选,其余章节将陆续放出.上一篇:Wow ...

  9. JS~对img标签进行优化,使用onerror进行默认图像显示

    对于网站图像的不显示有很多原因,网络问题,文件本身问题,文件URL问题等,而当图像加载失败时会触发onerror这个事件,我们利用这点,可以有效的避免图像加载失败的尴尬! JS代码 //图像加载出错时 ...

  10. jQuery中ready与load事件的区别

    1.摘要 大家在编程中使用jQuery还有JS的时候一定会在使用之前这样: //document ready $(document).ready(function(){ ...code... }) / ...