Three small surveillance scripts

Source: Internet
Author: User

  1. Monitor MySQL master-slave and send email alerts with scheduled tasks.

    #!/bin/bash
    # check MySQL slave status

    Mysql_path=/wqdata/mysql/bin/mysql
    user= "root"
    password= "[email protected]"
    [email protected]
    date= ' (date +%y-%m-%d--%h:%m:%s) '
    ip=$ (/sbin/ifconfig | grep "inet addr" | Grep-v "127.0.0.1" | awk ' {print $;} ' | Awk-f ': ' {print $;} ' | head-1)
    slave_io_running=$ ($mysql _path-u$user-p$password-e ' show Slave status\g ' | grep "slave_io_running" | awk ' { Print $ {} ')
    slave_sql_running=$ ($mysql _path-u$user-p$password-e ' show Slave status\g ' | grep "Slave_sql_running" | A WK ' {print $} ')
    if ["$Slave _io_running" = "yes"-a "$Slave _sql_running" = "Yes"]
    then
      echo "Slave is RU nning! "
    Else
      echo "#######  $date   #########" >>/wqdata/check_mysql_slave.log
      echo " Slave is not running! ">>/wqdata/check_mysql_slave.log
    echo" {$ip}_replicate_error "|mail-s" WARNING:--- 83slave fail "[email protected]
    Fi

  2. Monitor whether the Sersync is running or restart



    #!/bin/sh

    Sersync= "/usr/local/sersync/sersync2"

    Confxml= "/usr/local/sersync/confxml.xml"

    status=$ (PS aux |grep ' sersync2 ' |grep-v ' grep ' |wc-l)

    If [$status-eq 0];

    Then

    $sersync-D-r-o $confxml &

    Else

    Exit 0;

    Fi

  3. Scheduled backup MYSQSL



    #!/bin/bash
    #此脚本用来进行数据库的全备份, complete with scheduled tasks

    #注意: The following variable values may have to be modified, carefully confirm the following
    Mysqluser=root
    Rsyncuser=rsync_backup
    rsync_hostip= ' 233 '
    ip= ' 223 ' #本机ip
    mysqlpassword=t3011
    mysqlsocket= '/tmp/mysql.sock '
    Mysql_defaults_file= '/wqdata/mysql/my.cnf '

    Backuptodir= '/wqdata/mofidbbak/' #备份到目录
    Binlogdir= '/wqdata/mydata/data ' #二进制日志目录
    Binlogname= ' mysql-bin.0* ' #二进制日志文件名
    Rsyncmodule=mofidbbak #rsync的模块

    if [!-D $backuptodir];then
    Mkdir-p $backuptodir
    Fi

    #进行全备份
    Innobackupex--user= $mysqluser--password= $mysqlpassword--socket= $mysqlsocket--defaults-file= $mysql _defaults_ File $backuptodir 2>/dev/null | | Exit 1

    #删除一天前的全备份文件, which is to keep two backup files
    Find $backuptodir-type f-mtime +1-exec rm-f {} \;

    #删除一天前的二进制日志文件, which is to keep binary log files for two days
    CD $binlogdir
    Onedayago_binlog= ' Find. -type f-mtime +1-name "$binlogname" | Sort | tail-n1 | Awk-f '/' {print $} '
    Mysql-u $mysqluser-p$mysqlpassword-e "PURGE MASTER LOGS to ' $onedayago _binlog '" 2>/dev/null

    #找出最后一个全备份文件, Compress
    CD $backuptodir
    lastfull_backup= ' Ls-l | grep ' ^d ' | awk ' {print $9} ' | Sort | Tail-n1 '
    TAR-ZCF mysql_full_${ip}_${lastfull_backup}.tar.gz ${lastfull_backup}

    #将压缩文件rsync同步到备份机
    Rsync-az--password-file=/etc/rsync.password ${backuptodir}mysql_full_${ip}_${lastfull_backup}.tar.gz [email Protected]${rsync_hostip}:: $rsyncmodule | | Exit 1

    #删除压缩文件
    Rm-f ${backuptodir}mysql_full_${ip}_${lastfull_backup}.tar.gz

4. Third party e-mail software

Yum-y Install MAILX

Vim/etc/mail.rc

Set [email protected] smtp=smtp.139.com

Set [email protected] Smtp-auth-password=we

Set Smtp-auth=login

echo "Zabbix test Mail" |mail-s "title Zabbix" [Email protected]


[Email protected] iosupload]# crontab-l
*/1 * * * */etc/init.d/iptables start
*/5 * * * * root/wqdata/84jiaoben/check_sersync.sh >/dev/null 2>&1
* 1 * * */wqdata/84jiaoben/mysqlfullbak.sh

Three small surveillance scripts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.