当前位置:Gxlcms > mysql > Nagios监控MySQL主从状态的简单脚本

Nagios监控MySQL主从状态的简单脚本

时间:2021-07-01 10:21:17 帮助过:33人阅读

使用nagios监控mysql主从,在监控主机上需要安装nrpe软件包以及nagios软件包,安装步骤就不多说了,下面进入正题

使用nagios监控mysql主从,在监控主机上需要安装nrpe软件包以及nagios软件包,,安装步骤就不多说了,下面进入正题

在监控主机上:

首先定义主机:

vim /usr/local/nagios/etc/objects/localhost.cfg
define host {
host_name joker
alias test
address 192.168.xx.xx
check_command check-host-alive
notification_options d,u,r
check_interval 1
max_check_attempts 2
contact_groups admins
notification_interval 10
notification_period 24x7
}

定义服务:

define service {
host_name joker
service_description nrpe
check_period 24x7
normal_check_interval 2
retry_check_interval 1
max_check_attempts 5
notification_period 24x7
notification_options w,u,c,r
check_command check_nrpe!check_mysql
}

定义command:

define command {
command_name check_nrpe
command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

在被监控主机上:

安装nrpe
tar fvxz nrpe*.tar.gz
./configure --prefix=/usr/local/nagios
useradd nagios
make all
make install
make install-daemon
make install-daemon-config
make install-xinetd

scp /usr/local/nagios/libexec/check_nrpe root@192.168.18.105:/usr/local/nagios/libexec

vim /etc/xinetd.d/nrpe
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
only_from = 192.168.18.105
}
vim /etc/services

在最后添加nrpe 5666/tcp
service xinetd restart

vim /usri/local/nagios/etc/nrpe.cfg
command[check_mysql]=/usr/local/nagios/libexec/check_mysql

vim /usr/local/nagios/libexec/check_mysql
#!/bin/bash
master=`mysql -h 192.168.18.165 -u hello -p123 -e 'show master status' &> /tmp/123 | awk 'NR==2{print $2}' /tmp/123`
slave=`mysql -e 'show slave status' &> /tmp/234 | awk =F: '{if($1~/Exec/)print $2}' /tmp/234`
if [ $master -eq $slave ]; then
echo "ok"
rm -fr /tmp/123
rm -fr /tmp/234
exit 0
else
echo "error"
mv /tmp/123 /tmp/err1
mv /tmp/234 /tmp/err2
exit 2

最后进行测试,本人亲测OK~~~

linux

人气教程排行