mysql 從庫狀態監控shell

來源:互聯網
上載者:User

標籤:mysql---slave狀態監控

監控mysql 

Slave_IO_Running: 

Slave_SQL_Running:

狀態,為NO 郵件警示

最近剛發現一個發郵件的工具,簡單好用 sendEmail,免安裝的 個人感覺非常好用

參考:http://blog.chinaunix.net/uid-10697776-id-3185073.html

vim slave.sh

思路:

過濾Slave_IO_Running && Slave_SQL_Running的值。為No郵件警示,同時寫入日誌slave.log。。當然就得定期清空日誌(我做的是每次查看日誌的行數超過1152行,清空日誌。同時判斷日誌中是否有No

欄位,有則不執行清空操作,方便記錄故障時間)

變數:TEST_TIME=記錄時間

      SLAVE_IO=Slave_IO_Running:的狀態

      SLAVE_SQL=Slave_SQL_Running:的狀態

相關:mysql -uuser -h ip -ppasswd -e "命令"(不登陸mysql執行mysql命令)


#!/bin/bashTEST_TIME=`date -d today +"%Y%m%d--%H:%M:%S"`SLAVE_IO=`/usr/local/bin/mysql -uroot -h 127.0.0.1  -e "show slave status\G;"|grep Slave_IO_Running|awk ‘{print $2}‘`SLAVE_SQL=`/usr/local/bin/mysql -uroot -h 127.0.0.1  -e "show slave status\G;"|grep Slave_SQL_Running|sed -n ‘1p‘|awk ‘{print $2}‘`CAT_LOG=`cat /tmp/shell/slave/slave.log|wc -l`if [ ${SLAVE_IO} = Yes ]; then        echo "Slave_IO_Running: Yes"${TEST_TIME} >> /tmp/shell/slave/slave.log else        echo "Slave_IO_Running: No"${TEST_TIME} >> /tmp/shell/slave/slave.log        /usr/local/sendEmail/sendEmail-v1.56/sendEmail -f [email protected] -t [email protected] -xp xxx -s smtp.163.com -xu xxx -u test -m Slave_IO_Running: No__${TEST_TIME}fi###if [ ${SLAVE_SQL} = Yes ]; then        echo "Slave_SQL_Running: Yes"${TEST_TIME} >> /tmp/shell/slave/slave.log else        echo "Slave_SQL_Running: No"${TEST_TIME} >> /tmp/shell/slave/slave.log        /usr/local/sendEmail/sendEmail-v1.56/sendEmail -f [email protected] -t [email protected] -xp xxx -s smtp.163.com -xu xxx -u test -m Slave_SQL_Running: No__${TEST_TIME}fi###cat /tmp/shell/slave/slave.log|grep Noif [ $? != 0 ]; then#       echo $?   if [ ${CAT_LOG} -gt 1152 ];        then        echo "" > /tmp/shell/slave/slave.log   fifi

初來乍到~請多指教~~~

本文出自 “分享是一種美德” 部落格,請務必保留此出處http://passers.blog.51cto.com/9686614/1587514

mysql 從庫狀態監控shell

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.