Home > Database > Mysql Tutorial > shell实战之:mysql index文件检查机制

shell实战之:mysql index文件检查机制

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 15:09:19
Original
1337 people have browsed it

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 本文将重点讲述 shell实战中的 mysql index 文件检查机制问题,请先看代码: 01#!/bin/sh 02def_check_index() 03{ 04#code by scpman 05#http://.scpman. 06#mail:freeddser@gmail.com 07#需求: 08#

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  本文将重点讲述 shell实战中的 mysql index 文件检查机制问题,请先看代码:

  01#!/bin/sh

  02def_check_index()

  03{

  04#code by scpman

  05#http://.scpman.

  06#mail:freeddser@gmail.com

  07#需求:

  08#

  09# 1.通过show master logs; 列出binlog文件序列如果顺序不对,或记录重复发告警 发邮件告警。

  10# 2、查看mysql目录下的index文件,如果顺序不对,或记录重复发告警

  11#

  12#实现

  13#发送告警函数

  14def_send_mail()

  15{

  16msgip="10.0.7.44" #syslog服务器

  17ser_IP=`cat /etc/rc.conf | grep -E "ifconfig_[em1|bce1]" | awk '{print "IP:"$2}'| sed -n 1p ` #本机的ip

  18#echo $1 函数接收的第一个值

  19if [ -n "$1" ] && [ `echo "$1"|grep -c 'chongfu'` -gt 0 ] #判断$1是否在,并且统计下chongfu这个字符是否大于0

  20then

  21echo /usr/bin/logger -p local1.info -h $msgip "the services: $IP mysql index file $1 " #大于0说明有错误的,就得告警

  22exit

  23elif [ -n "$1" ] && [ `echo "$1"|grep -c 'luanle'` -gt 0 ] #判断$1是否在,并且统计下luanle这个字符是否大于0

  24then

  25echo /usr/bin/logger -p local1.info -h $msgip "the services: $IP mysql index file $1 " #大于0说明有错误的,就得告警

  26exit

  27else

  28echo ok

  29fi

  30}

  31#1、判断index是否有重复的情况

  32def_index_is_one()

  33{

  34if [ -n "$1" ]

  35then

  36static_index=$1

  37def_send_mail `awk '{a[$1]++}END{for (j in a) print j,a[j]}' $static_index | awk -v flag="$static_index" '{if($2>1) print "chongfu-->"$0}'`

  38else

  39echo 'def_index_is_one $1 is null!exit'

  40exit

  41fi

  42}

  43#检查mysql目录下的index文件内容顺序是否正常

  44def_static_index_shunxu()

  45{

  46bzfile='/usr/dlm_db/mysql/zqtx-bin.index'

  47current_line=`cat ${bzfile}|head -n 1|sed -e "s#./zqtx-bin.##g"`

  48for i in `cat ${bzfile}`

  49do

  50if [ `echo $i|sed -e "s#./zqtx-bin.##g"` -lt "$current_line" ]

  51then

  52def_send_mail "luanle:${bzfile}_${current_line}"

  53exit

  54fi

  55current_line=`echo $i|sed -e "s#./zqtx-bin.##g"`

  56done

  57}

  58#检查mysql中show master logs的index文件内容顺序是否正常

  59def_masterlog_index_shunxu()

  60{

  61mysql -uroot -p123456 -s -s -e "show master logs;" | awk '{print $1}' | sed -e "s/zqtx-bin.//g">/usr/dlm_db/mysql/flag_index

  62bzfile=/usr/dlm_db/mysql/flag_index

  63current_line=`cat ${bzfile}|head -n 1`

  64for i in `cat ${bzfile}`

  65do

  66if [ "$i" -lt "$current_line" ]

  67then

  68def_send_mail "luanle:master_logs_${i}"

  69exit

  70fi

  71current_line="$i"

  72done

  73}

  74def_index_is_one '/usr/dlm_db/mysql/zqtx-bin.index'

  75def_static_index_shunxu

  76def_masterlog_index_shunxu

  77def_index_is_one '/usr/dlm_db/mysql/flag_index'

  78}

  79def_check_index

shell实战之:mysql index文件检查机制

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template