(转)CentOS搭建Nagios监控
A.Nagios服务端
1.安装软件包
- yum install -y httpd
2.下载nagios
- wget http://syslab.comsenz.com/downloads/linux/nagios-3.0.5.tar.gz
- wget http://syslab.comsenz.com/downloads/linux/nagios-plugins-1.4.13.tar.gz
- wget http://syslab.comsenz.com/downloads/linux/nrpe-2.12.tar.gz
3.添加nagios账号
- useradd nagios
4.编译安装nagios
- mkdir /opt/hadoop/
- tar -xzvf nagios-3.0.5.tar.gz
- cd nagios-3.0.5
- ./configure --prefix=/opt/hadoop/nagios
- make all
- make fullinstall
- mkdir /opt/hadoop/nagios/etc
- mkdir /opt/hadoop/nagios/etc/objects
- cp ./sample-config/cgi.cfg /opt/hadoop/nagios/etc/
- cp ./sample-config/nagios.cfg /opt/hadoop/nagios/etc/
- cp ./sample-config/resource.cfg /opt/hadoop/nagios/etc/
- cp ./sample-config/template-object/commands.cfg /opt/hadoop/nagios/etc/objects/
- cp ./sample-config/template-object/contacts.cfg /opt/hadoop/nagios/etc/objects/
- cp ./sample-config/template-object/timeperiods.cfg /opt/hadoop/nagios/etc/objects/
- cp ./sample-config/template-object/templates.cfg /opt/hadoop/nagios/etc/objects/
- cp ./sample-config/template-object/localhost.cfg /opt/hadoop/nagios/etc/objects/
- touch /opt/hadoop/nagios/var/nagios.log
- chmod -R 755/opt/hadoop/nagios/etc/
- chown -R nagios:nagios /opt/hadoop/nagios
5.编译安装nagios-plugins
- tar zxvf nagios-plugins-1.4.13.tar.gz
- cd nagios-plugins-1.4.13
- ./configure --prefix=/opt/hadoop/nagios --with-nagios-user=nagios --with-nagios-group=nagios
- make && make install
检查是否已经安装成功,看这个目录下是否有插件文件
- ls /opt/hadoop/nagios/libexec/
6.安装nrpe
- tar zxvf nrpe-2.12.tar.gz
- cd nrpe-2.12
- ./configure --prefix=/opt/hadoop/nagios --enable-ssl --enable-command-args
- make all
- make install-plugin
- make install-daemon
- make install-daemon-config
7.配置httpd
添加web账号
- htpasswd -c /opt/hadoop/nagios/etc/htpasswd.users nagiosadmin
B.Nagios客户端
1.准备软件包
- wget http://syslab.comsenz.com/downloads/linux/nagios-plugins-1.4.13.tar.gz
- wget http://syslab.comsenz.com/downloads/linux/nrpe-2.12.tar.gz
2.添加nagios账号,准备安装目录
- mkdir /opt/hadoop/nagios
- useradd nagios
3.编译安装nrpe
- tar -xzvf nrpe-2.12.tar.gz
- cd nrpe-2.12
- ./configure --prefix=/opt/hadoop/nagios --enable-ssl --enable-command-args
- make all
- make install-plugin
- make install-daemon
- make install-daemon-config
4.安装nagios-plugin
- tar -xzvf nagios-plugins-1.4.13.tar.gz
- cd nagios-plugins-1.4.13
- ./configure --prefix=/opt/hadoop/nagios --with-nagios-user=nagios --with-nagios-group=nagios
- make && make install
检查是否已经安装成功,看这个目录下是否有插件文件
- ls /opt/hadoop/nagios/libexec/
5. 配置nrpe
- vim /opt/hadoop/nagios/etc/nrpe.cfg
- 找到”allowed_hosts=127.0.0.1”改成“allowed_hosts=127.0.0.1,10.130.2.72”,后边的IP是nagios服务端IP
- 找到” dont_blame_nrpe=0”改成“dont_blame_nrpe=1”
6.一段nrpe启停脚本,放在/etc/init.d/nrpe里
- #!/bin/bash
- #
- # chkconfig: 2345 55 25
- # description: NRPE Daemon
- #
- # source function library
- ./etc/rc.d/init.d/functions
- RETVAL=0
- prog='nrpe'
- NRPE_CFG='/opt/hadoop/nagios/etc/nrpe.cfg'
- NRPE_PRG='/opt/hadoop/nagios/bin/nrpe'
- NRPE_OPT='-d'
- PID_FILE='/var/run/nrpe.pid'
- start()
- {
- echo -n $"Starting $prog: "
- [-f $PID_FILE ]&& rm -f $PID_FILE
- $NRPE_PRG -c $NRPE_CFG $NRPE_OPT
- pid=`ps aux | grep -v grep | grep $NRPE_PRG | awk '{print $2}'`
- echo $pid > $PID_FILE
- if ps aux | grep -v grep | grep -q $NRPE_PRG ;then
- RETVAL=0
- success
- else
- RETVAL=1
- failure
- fi
- echo
- }
- stop()
- {
- echo -n $"Stopping $prog: "
- ps --pid=`cat $PID_FILE`&>/dev/null
- if[ $?-eq 0];then
- kill -9`cat $PID_FILE`
- RETVAL=0
- fi
- success
- echo
- RETVAL=0
- }
- case"$1"in
- start)
- start
- ;;
- stop)
- stop
- ;;
- restart)
- stop
- start
- ;;
- status)
- status -p $PID_FILE $prog
- RETVAL=$?
- ;;
- *)
- echo $"Usage: $0 {start|stop|restart|status}"
- RETVAL=1
- esac
- exit $RETVAL
6. 启动nrpe
- /etc/init.d/nrpe start
C.Nagios服务端添加被监控机
1.配置监控机目录
- mkdir /opt/hadoop/nagios/etc/servers
- vim /opt/hadoop/nagios/etc/nagios.cfg 追加cfg_dir=/opt/hadoop/nagios/etc/servers
2.添加配置的机器
- vim /opt/hadoop/nagios/etc/servers/10.130.2.22.cfg
- define host{
- use linux-server
- host_name 10.130.2.22
- alias 10.130.2.22
- address 10.130.2.22
- }
- define service{
- use generic-service
- host_name 10.130.2.22
- service_description check_ping
- check_command check_ping!100.0,20%!200.0,50%
- max_check_attempts 5
- normal_check_interval 1
- }
- define service{
- use generic-service
- host_name 10.130.2.22
- service_description check_ssh
- check_command check_ssh
- max_check_attempts 5
- normal_check_interval 1
- }
3.reload nagios服务端使配置生效
- service nagios reload
重新加载nagios后就可以在nagios的界面上看到新的被监控的机器了
4.添加使用nrpe的监控
- 在/opt/hadoop/nagios/etc/objects/commands.cfg里增加如下行
- define command{
- command_name check_nrpe
- command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
- }
在服务器监控配置文件中加入如下行,确保被监控机的nrpe服务是开的
- define service{
- use generic-service
- host_name 10.130.2.22
- service_description check_load
- check_command check_nrpe!check_load
- max_check_attempts 5
- normal_check_interval 1
- }
重新加载nagios使配置生效。
- service nagios reload
5.自定义监控脚本
编写脚本check_diskmount.sh
- vim /opt/hadoop/nagios/libexec/check_diskmount.sh
- #!/bin/bash
- num=`cat /proc/mounts | grep '/disk' | wc -l`
- if[ $num -eq 12];then
- echo "OK - mount disk is $num"
- exit 0
- else
- echo "Critical - mount disk is $num"
- exit 1
- fi
加上可执行权限
- chmod +x /opt/hadoop/nagios/libexec/check_diskmount.sh
在被监控机的nrpe里加入自定义脚本路径
- vim /opt/hadoop/nagios/etc/nrpe.cfg
- command[check_diskmount]=/opt/hadoop/nagios/libexec/check_diskmount.sh
重启nrpe
- /etc/init.d/nrpe restart
在nagios服务端加入配置
- vim /opt/hadoop/nagios/etc/servers/10.130.2.22.cfg
- define service{
- use generic-service
- host_name s9xplan2.isv.cm6
- service_description check_diskmount
- check_command check_nrpe!check_diskmount
- max_check_attempts 3
- normal_check_interval 1
- }
重新加载nagios,使得配置生效
- service nagios reload
摘自:http://www.opstool.com/article/236
(转)CentOS搭建Nagios监控的更多相关文章
- 自动安装脚本-------------基于LVMP搭建Nagios 监控
Mysql初始化参数(mysql-5.6.31) /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local ...
- 在Nginx中搭建Nagios监控平台
本文只做Nginx下Nagiox安装的说明,其它关于Nagios监控的详细配置请参考我的另一篇文章[Ubuntu 10.04下构建Nagios监控平台] Nagios依赖PHP环境和perl环境.由于 ...
- 【nagios监控】基于linux搭建nagios监控
nagios工作原理 nagios的功能是监控服务和主机,但是其自身并不包括这些功能,所有的监控.检测功能都是通过各种插件来完成的. 启动nagios后,它会周期性的自动调用插件去检测服务器状态,同时 ...
- CentOS 7.4 下安装部署Nagios监控系统详细攻略(三)
Nagios是一个流行的电脑系统和网络监控程序,它检测主机和服务,当异常发生和解除时能提醒用户.它是基于GPLv2开发的开源软件,可免费获得及使用. nagios工作原理 nagios的功能是监控服务 ...
- centos shell编程6一些工作中实践脚本 nagios监控脚本 自定义zabbix脚本 mysql备份脚本 zabbix错误日志 直接送给bc做计算 gzip innobackupex/Xtrabackup 第四十节课
centos shell编程6一些工作中实践脚本 nagios监控脚本 自定义zabbix脚本 mysql备份脚本 zabbix错误日志 直接送给bc做计算 gzip innobacku ...
- Security基础(四):OpenSSL及证书服务常用系统监控命令、搭建nagios监控服务器、配置文件及插件使用、监控远程主机的公有数据、监控远程主机的私有数据
一.OpenSSL及证书服务常用系统监控命令 目标: 本案例要求练习常用的系统监控命令完成以下任务: 使用vmstat命令监控内存及磁盘I/O信息 使用iostat命令监控CPU处理器及磁盘的I/O信 ...
- Nagios监控平台搭建
Nagios是一款开源的免费网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设置,打印机等.在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员, ...
- Centos部署nagios+apache实现服务器监控
1.Nagios介绍 nagios是 一款功能强大的网络监视工具,它可以有效的监控windows.linux.unix主机状态以及路由器交换机的网络设置,打印机工作状态等,并将状态出 现异常的服务及时 ...
- Nagios监控平台搭建及配置文件详解
Nagios是一款开源的免费网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设置,打印机等.在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员, ...
随机推荐
- 关于TCP的三次握手和四次分手(整理)
这个协议非常重要,这里把它的链接和释放整理一下 首先是三次握手: 1. 客户端发起,像服务器发送的报文SYN=1,ACK=0,然后选择了一个初始序号:seq=x. SYN是干什么用的? 在链接的时候 ...
- 怎样检查手机是否root成功
怎样检查手机是否root成功 浏览:154361 | 更新:2011-01-20 13:10 | 标签:root 总有人以为,root后就可以删除自带程序了,这个想法也对也不对,想删除自带的软件,确实 ...
- puppet证书重申
- Hibernate中Session的几个方法的简单说明
Hibernate对普通JDBC的操作进行了轻量级的封装,使得开发人员可以利用Session对象以面向对象的思想来实现对关系数据库的操作. 一般通过Configuration对象读取相应的配置文件来创 ...
- poj 1286 Necklace of Beads (polya(旋转+翻转)+模板)
Description Beads of red, blue or green colors are connected together into a circular necklace of ...
- [RxJS] Displaying Initial Data with StartWith
You often need to render out data before you stream begins from a click or another user interaction. ...
- [Redux] Extracting Presentational Components -- AddTodo
The code to be refactored: let nextTodoId = 0; class TodoApp extends Component { render() { const { ...
- Eclipse创建java webproject配置Tomacat和JDK
在学习AJAX过程中.还用Intellij就有点老旧了,这是后装个Eclipse时,发现这个配置也非常头疼.如今就叫你怎样创建一个webproject,同一时候叫你配置Eclipse. 一.创建一个w ...
- const与define的异同
1. DEFINE是预处理指令,是简单的文字替换:而const是关键字,用于变量声明的修饰. 2. DEFINE替换的结果可以是数值.表达式.字符串.甚至是一个程序:而const只能限定变量为不可修改 ...
- Dynamics CRM 常用 JS 方法集合
JS部分 拿到字段的值 var value= Xrm.Page.getAttribute("attributename").getValue(); Xrm.Page.getAttr ...