Get the App
SLTechnology News&Howtos  ›  Development  › 

How does shell monitor mysql master-slave replication

Shulou Source: shulou.com Published: 2022-06-03 07:42:27 10月03日 Update

This article mainly shows you "how shell monitors mysql master-slave replication". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how shell monitors mysql master-slave replication".

Description:

The monitoring script is tested normally under rhel5. Other versions of linux system should be tested by yourself. For some preparatory work, please see this article.

Code:

The code is as follows:

# Monitoring mysql master-slave replication

Cat chk_mysql_rep.sh

#! / bin/bash

#

# script_name:chk_mysql_rep.sh

# check mysql replication

#

# ssh root@xen "/ usr/local/mysql/bin/mysql-uroot-pdongnan-e 'show slave status\ G'-ss" | awk' / Running:/ {print $2}'

# Yes

# Yes

#

# variables

Ssh=/usr/bin/ssh

Sh_dir=/root/sh/

Crondir=$ {sh_dir} crontab

Source ${sh_dir} CONFIG

Hosts= "$DB_SLAVE_HOSTS"

# main

# the main loop traverses the machine www.yisu.com

For HOST in $hosts;do

Log=$crondir/log/mysql_replication_error.log

Key=$ ($ssh root@$HOST "/ usr/local/mysql/bin/mysql-uroot-pdongnan-e 'show slave status\ G'-ss" | awk' / Running:/ {printf $2}')

# hosts that cannot be connected, skip this cycle

Test-z "$key" & & continue

# the result returned is true

If ["$key" = = "YesYes"]; then

# flag true, deactivate the alarm

If [- f "${crondir} / log/$HOST.mysql"]; then

# sms

# for mobile in $MOBILES;do

# echo "$HOST replication ok" | / usr/local/bin/gammu-- sendsms TEXT "$mobile"-unicode

# done

# mail

For mail in $MAILS;do

Echo "$HOST replication ok" | mail-s "$HOST replication ok" $mail

Done

# flag

Rm-f "${crondir} / log/$HOST.mysql"

Fi

# return result is false

Else

Check_date=$ (date'+% F% T')

# flag leave, call the police

If [!-f "${crondir} / log/$HOST.mysql"]; then

# sms www.yisu.com

# for mobile in $MOBILES;do

# echo "$HOST replication error" | / usr/local/bin/gammu-- sendsms TEXT "$mobile"-unicode

# done

# mail

For mail in $MAILS;do

Echo "$HOST replication error" | mail-s "$HOST replication error" $mail

Done

# flag

Echo "replication error" > "${crondir} / log/$HOST.mysql"

# log

Echo "$check_date $HOST mysql replicaton error" > > $log

Fi

Fi

#

Done

#

The above is all the contents of the article "how shell monitors mysql master-slave replication". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Monitoring master and slave articles content code results learning help looping alarm testing host easy to understand more machine organization version knowledge system ribbon Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Technology macOS MySQL Xiaomi