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. BAT面试必备——Java 集合类

    本文首发于我的个人博客:尾尾部落 1. Iterator接口 Iterator接口,这是一个用于遍历集合中元素的接口,主要包含hashNext(),next(),remove()三种方法.它的一个子接 ...

  2. Echarts服务端生成图片

    Echarts是百度发布的一套优秀的浏览器端图表控件,Echarts是基于html5的cavens绘图实现.而使用server端生成图片无法借用浏览器端渲染.通用的做法有两种: 是用headless浏 ...

  3. CHAPTER 24 History of Our Planet 第24章 我们行星的历史

    CHAPTER 24 History of Our Planet 第24章 我们行星的历史 Uncovering the bones of ancient beasts is only part of ...

  4. 新手Python第四天(生成器)

    Python 生成器 生成器和生成表达式 a=[i*2 for i in range(10)]#生成表达式 b=(i*2 for i in range(10))#生成器 生成器的特点:优点(不占用内存 ...

  5. 第五章 if语句

    5.2条件测试 使用==判断相当: 使用!=判断不相等: 每条if语句的核心都是一个值为Tre或False的表达式,这种表达式被称为条件测试,如果条件测试的值为Ture,则执行紧跟在if语句后面的代码 ...

  6. PCL 库存在vtk的问题导致libproj.so链接错误

    常变现为** No rule to make target '/usr/lib/x86_64-linux-gnu/libproj.so', needed by ××× vtk库的bug导致,目前尚未修 ...

  7. node child_process模块

    NodeJs是一个单进程的语言,不能像Java那样可以创建多线程来并发执行.当然在大部分情况下,NodeJs是不需要并发执行的,因为它是事件驱动性永不阻塞.但单进程也有个问题就是不能充分利用CPU的多 ...

  8. Python发送邮件(最全)

    简单邮件传输协议(SMTP)是一种协议,用于在邮件服务器之间发送电子邮件和路由电子邮件. Python提供smtplib模块,该模块定义了一个SMTP客户端会话对象,可用于使用SMTP或ESMTP侦听 ...

  9. 安装macOS Sierra后怎么找回“任何来源”选项

    安装macOS Sierra后,会发现系统偏好设置的“安全与隐私”中默认已经去除了允许“任何来源”App的选项,无法运行一些第三方应用(提示xx.app已经损坏).如果需要恢复允许“任何来源”的选项, ...

  10. spring boot开启热部署

    步骤一:添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId&g ...