1、安装插件

# tar xvf nagios-plugins-1.4.13.tar.gz
# cd nagios-plugins-1.4.13
# ./configure
# make && make install

2、安装客户端

# tar xvf nrpe-2.12.tar.gz
# cd nrpe-2.12
# ./configure
# make all
# make install-plugin
cd ./src/ && make install-plugin
make[1]: Entering directory `/usr/local/src/nrpe-2.12/src'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
/usr/bin/install -c -m 775 -o nagios -g nagios check_nrpe /usr/local/nagios/libexec
make[1]: Leaving directory `/usr/local/src/nrpe-2.12/src'
# make install-daemon
cd ./src/ && make install-daemon
make[1]: Entering directory `/usr/local/src/nrpe-2.12/src'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/bin
/usr/bin/install -c -m 775 -o nagios -g nagios nrpe /usr/local/nagios/bin
make[1]: Leaving directory `/usr/local/src/nrpe-2.12/src'
# make install-daemon-config
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 644 -o nagios -g nagios sample-config/nrpe.cfg /usr/local/nagios/etc

3、修改nrpe的配置文件

# vim /usr/local/nagios/etc/nrpe.cfg

log_facility=daemon
pid_file=/var/run/nrpe/nrpe.pid
server_port=5666
nrpe_user=nrpe
nrpe_group=nrpe
allowed_hosts=127.0.0.1,192.168.1.248,117.119.33.17 添加服务端地址,允许服务端连接 dont_blame_nrpe=0
allow_bash_command_substitution=0
debug=0
command_timeout=60
connection_timeout=300 include_dir=/etc/nrpe.d/ 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_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 command[check_disk]=/usr/local/nagios/libexec/check_disk -w 15% -c 10% -A
command[check_cpu_load]=/usr/local/nagios/libexec/check_cpu_load.sh
command[check_swap]=/usr/local/nagios/libexec/check_swap -a -w 30% -c 20%
command[check_raiddisk]=/usr/local/nagios/libexec/check_megaraid_sas -m 20 -p 20 -o 20 2>/dev/null
command[check_raidbattery]=/usr/local/nagios/libexec/check_raidbattery.sh
command[check_remote_ntp]=/usr/local/nagios/libexec/check_ntp -H ntp1.oupeng.com -w 1 -c 3
command[check_mysql3307_rep]=/usr/local/nagios/libexec/check_mysql3307_rep

这里有两个监控脚本是自己写的:

检测cpu负载的脚本

# cat /usr/local/nagios/libexec/check_cpu_load.sh
#!/bin/bash
cpu=`grep -c "processor" /proc/cpuinfo`
load=(`uptime |awk -F "[ :,]+" '{print $(NF-2),$(NF-1),$NF}'`)
j=1
for i in ${load[*]};do
all_status=`awk -v a=$cpu -v b=$i 'BEGIN{print (b>=a)?2:0}'`
half_status=`awk -v a=$(($cpu/2)) -v b=$i 'BEGIN{print (b>=a)?1:0}'`
if [ $j -eq 1 ];then
time=1
elif [ $j -eq 2 ];then
time=5
else
time=15
fi
if [ $all_status -eq 2 ];then
echo "CRITICAL: - CURRENT ${time} minute CPU LOAD IS ${load[$j-1]} MORE THAN CPUS IS $cpu"
exit 2
elif [ $half_status -eq 1 ];then
echo "WARING: - CURRENT ${time} minute CPU LOAD IS ${load[$j-1]} MORE THAN HALF OF CPUS IS $(($cpu/2))"
exit 1
else
let j++
if [ $j -eq 4 ];then
echo "OK: - CURRENT CPU LOAD IS ${load[0]}, CPUS IS $cpu"
fi
continue
fi
echo "OK: - CURRENT CPU LOAD IS ${load[0]}, CPUS IS $cpu"
done

检测mysql主从状态的脚本

# cat /usr/local/nagios/libexec/check_mysql3307_rep
#!/bin/bash
SOCKET='/nh/mysql3307/mysql-3307.sock'
lines=($(mysql -uroot -pdellXdell -S $SOCKET -e 'show slave status\G' 2>&- |grep -E 'Running|Seconds_Behind_Master' |grep -v 'Slave_SQL_Running_State' |sed 's/ //g'))
if [[ -z ${lines[@]} ]];then
echo "WARNING - Don't have slave"
exit 1
fi
for line in ${lines[@]}
do
arg=$(echo $line |awk -F: '{print $1}')
value=$(echo $line |awk -F: '{print $2}')
case $line in
Slave*)
if [[ $value != 'Yes' ]];then
echo "CRITICAL - $line"
exit 2
fi
;;
Second*)
if [[ $value -ne 0 ]];then
echo "WARNING - $line"
exit 1
fi
;;
esac
done
echo 'OK - MYSQL REPLICATION OK'

启动服务

# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
# ps -ef | grep nrpe

本地测试

# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_load
OK - load average: 0.10, 0.10, 0.08|load1=0.100;15.000;30.000;0; load5=0.100;10.000;25.000;0; load15=0.080;5.000;20.000;0;

服务端测试

为root用户设置一个密码

# mysql -uroot -S mysql-3307.sock
mysql> UPDATE user SET password=password('dellXdell') WHERE user='root';

在mysql上创建一个专门用于检测的用户,给予只读权限

mysql> grant select on *.* to 'nagios'@'192.168.%' identified by 'nagiostest';

# /usr/local/nagios/libexec/check_mysql -H 192.168.1.101 -u nagios -p nagiostest -d mysql -P 3307
Uptime: 110289 Threads: 3 Questions: 684 Slow queries: 4 Opens: 18 Flush tables: 2 Open tables: 1 Queries per second avg: 0.6

4、服务端配置

# cd /usr/local/nagios/etc/
# vim nagios.cfg
cfg_dir=/usr/local/nagios/etc/objects

创建一个配置文件

# cd objects/
# vim ansible_auto/public/uy-s-43.cfg
define host{
use Linuxserver
host_name uy-s-43
contact_groups group-sa
alias uy-s-43
address 192.168.1.101
hostgroups product-servers
}
define service{
use oupeng
host_name uy-s-43
contact_groups group-sa
service_description mysql_public_3307
check_command check_mysql!nagios!nagiostest!mysql!3307
}
define service{
use oupeng
host_name uy-s-43
contact_groups group-sa
service_description check_mysql3307_rep
check_command check_nrpe!check_mysql3307_rep
}

重载配置

# /etc/init.d/nagios reload

编译安装nrpe,配置监控mysql端口和主从状态的更多相关文章

  1. cacti系列(一)之cacti的安装及配置监控mysql服务

    简介 Cacti是通过 snmpget来获取数据,使用 RRDtool绘画图形,而且你完全可以不需要了解RRDtool复杂的参数.它提供了非常强大的数据和用户管理功能,可以指定每一个用户能查看树状结构 ...

  2. CentOS6.7下使用非root用户(普通用户)编译安装与配置mysql数据库并使用shell脚本定时任务方式实现mysql数据库服务随机自动启动

    CentOS6.7下使用非root用户(普通用户)编译安装与配置mysql数据库并使用shell脚本定时任务方式实现mysql数据库服务随机自动启动1.关于mysql?MySQL是一个关系型数据库管理 ...

  3. RHEL6 最小化系统 编译安装部署zabbix (mysql)

    RHEL6 最小化系统 编译安装部署zabbix (mysql)官方说明详细见:https://www.zabbix.com/documentation/4.0/manual/installation ...

  4. 使用Ubuntu系统编译安装Zabbix企业级监控系统

    使用Ubuntu系统编译安装Zabbix企业级监控系统   作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. Ubuntu系统部署笔记:https://www.cnblogs.com/ ...

  5. CentOS 7上源码编译安装和配置LNMP Web+phpMyAdmin服务器环境

    CentOS 7上源码编译安装和配置LNMP Web+phpMyAdmin服务器环境 什么是LNMP? LNMP(别名LEMP)是指由Linux, Nginx, MySQL/MariaDB, PHP/ ...

  6. php编译安装与配置

    php编译安装与配置 =========================================== 官网:http://php.net/ 官网下载:http://php.net/downlo ...

  7. [转帖]安装prometheus+grafana监控mysql redis kubernetes等

    安装prometheus+grafana监控mysql redis kubernetes等 https://www.cnblogs.com/sfnz/p/6566951.html plug 的模式进行 ...

  8. libCURL开源库在VS2010环境下编译安装,配置详解

    libCURL开源库在VS2010环境下编译安装,配置详解 转自:http://my.oschina.net/u/1420791/blog/198247 http://blog.csdn.net/su ...

  9. 【MySQL】源码编译安装和配置MySql 5.5.32(单实例)

    [需求描述] 在CentOS环境中,通过编译源码的方式,安装并且配置“单实例”的MySQL5.5.32数据库. MySQL的安装目录为:/application/mysql-5.5.32 MySQL数 ...

随机推荐

  1. 32bit 天堂2 windows 2003 server架设教程

    安装环境::[注意:本教程newauth要用不加密的版本] windows 2003 enterprise server 100用户license Microsoft sql server 2000 ...

  2. java多线程相关代码

    1.创建线程的三种方式 使用Thread package com.wpbxx.test; //1.自定义一个类,继承java.lang包下的Thread类 class MyThread extends ...

  3. TensorFlow学习之路1-TensorFlow介绍

    TensorFlow是一个采用数据流图(data flow graphs),用于数据计算的开源软件库. 什么是数据流图? TensorFlow的数据流图是由“节点”(nodes)和“线”(edges) ...

  4. mybatis学习------打包xml映射文件

    编译mybatis时,idea不会将mybatis的xml映射文件一起打包进jar,即在编译好的jar包里缺少mybatis映射文件,导致网站加载失败 为解决这个问题,可在mybatis对应modul ...

  5. 第一阶段Spring个人总结

    通过这一阶段的冲刺,我感到的是名义上的团队,而实际上却是一个人的事,每个人跟每个人都不一样,都有自己的特点,总会出些不必要的麻烦. 还有团队的进展也是看不到什么东西,说实话,这次我并没有太多关注团队的 ...

  6. 第一次spring冲刺第9天

    明天是这个阶段的最后一天了,今天讨论关于容错的方面,例如输入空白或其他字符等方面会出现的问题 ,部分代码如下: public void checkout(int trueResult) { Strin ...

  7. [Elite 2008 Dec USACO]Jigsaw Puzzles

    #include <iostream> #include <cstdio> #include <cstring> using namespace std; #def ...

  8. JAVA对象的初始化过程

    出处:http://blog.csdn.net/andrew323/article/details/4665379 下面我们通过两个例题来说明对象的实例化过程. 例1:   编译并运行该程序会有以下输 ...

  9. mysubmail 短信报警

    https://www.mysubmail.com/chs/documents/developer/YPWD84   文本文档  官网:www.mysubmail.com 操作流程:快速接入短信 AP ...

  10. bash简介1

    bash脚本语言文件格式 第一行#!/bin/bash :定义bash脚本解释器 注释信息:# 代码注释: 缩进,适度添加空白行 bash中的变量介绍: 局部变量  本地变量   环境变量  位置参数 ...