監控mysql狀態 監控mysql狀態指令碼

2021-10-17 22:51:08 字數 2973 閱讀 9022

監控mysql狀態, 發現宕後, 自動重啟, 每秒檢查一次。

check.sh

#!/bin/bash

while [ true ]; do

/bin/sleep 1

sh mysql_status.sh

done

chengkill

#!/bin/sh

#pid kill thread for chenglee

#if fileformat=dos, update fileformat=unix

#code:set fileformat=unix

#check:set ff ?

if [ $# -lt 1 ]

then

echo "not procedure_name"

exit 1

fiprocess=`ps -ef|grep $1|grep -v grep|grep -v ppid|awk ''`

for i in $process

doecho "kill the $1 process [ $i ]"

kill -9 $i

done

chengkill授執行權扔/usr/bin

mysql_status.sh

#!/bin/bash

#/usr/bin/nmap localhost | grep 3306

#lsof -i:3306

mysqlport=`netstat -tlnp | grep "3306"|awk -f[:" "]+ ''`

str_time=$ date "+%y-%m-%d %h:%m:%s"

function checkmysqlstatus(){

/usr/bin/mysql -uroot -plizhenghua --connect_timeout=5 -e "show databases;" &>/dev/null 2>&1

if [ $? -ne 0 ]

then

restartmysqlservice

if [ "$mysqlport" == "3306" ];then

echo "mysql restart successful......"

else

echo "mysql restart failure......"

python mail.py

fielse

echo "mysql is running..."

fifunction restartmysqlservice(){

cat code.txt

echo "測試重啟mysql服務!"

echo "清除mysql殘餘!"

chengkill mysqld

echo "準備重啟!"

service mysqld restart

echo "重啟成功!"

# python mail.py

if [ "$mysqlport" == "3306" ]

then

checkmysqlstatus

else

restartmysqlservice

fimail.py

#!/usr/bin/python

#-*- coding:utf-8 -*-

#python mail for chenglee

#if fileformat=dos, update fileformat=unix

#code:set fileformat=unix

#check:set ff ?

import smtplib

from email.mime.text import mimetext

from email.utils import formataddr

my_sender='[email protected]' # 發件人郵箱賬號

my_pass = 'mwbajizijah' # 發件人郵箱密碼(當時申請smtp給的口令)

my_user='[email protected]' # 收件人郵箱賬號,我這邊傳送給自己

my_content='系統管理員您好,該系統的mysql程序已經崩潰並重啟失敗,請手動重啟!!'

my_title='程序告警'

def mail():

ret=true

try:

msg=mimetext(my_content,'plain','utf-8')

msg['from']=formataddr(["發件人暱稱",my_sender]) # 括號裡的對應發件人郵箱暱稱、發件人郵箱賬號

msg['to']=formataddr(["收件人暱稱",my_user]) # 括號裡的對應收件人郵箱暱稱、收件人郵箱賬號

msg['subject']=my_title # 郵件的主題,也可以說是標題

server=smtplib.smtp_ssl("smtp.qq.com", 465) # 發件人郵箱中的smtp伺服器,埠是465

server.login(my_sender, my_pass) # 括號中對應的是發件人郵箱賬號、郵箱密碼

server.sendmail(my_sender,[my_user,],msg.as_string()) # 括號中對應的是發件人郵箱賬號、收件人郵箱賬號、傳送郵件

server.quit()# 關閉連線

except exception:# 如果 try 中的語句沒有執行,則會執行下面的 ret=false

ret=false

return ret

ret=mail()

if ret:

print("郵件傳送成功")

else:

print("郵件傳送失敗")

code.txt

|(*(t)*)

/  0と  )  /

chenglee

前後兩個放在同乙個目錄, 中間chengkill扔bin, 然後守護模式執行check.sh。

監控mysql鎖定狀態 mysql常用監控命令

adb pull sdcard walktour xycrash e qqqqqq adb shell rm sdcard walktour xycrash log 1 鏈結數 select host,count host from information schema.processlist gr...

mysql 監控指令碼 監控mysql狀態指令碼

監控mysql狀態,發現宕後,自動重啟,每秒檢查一次。check.sh bin bash while true do bin sleep 1 sh mysql status.sh done chengkill bin sh pid kill thread for chenglee if filefo...

服務監控 PHP FPM狀態監控

root linux node1 vim etc zabbix zabbix agentd.conf 編輯配置檔案引用key include etc zabbix zabbix agentd.d conf root linux node1 mkdir etc zabbix scripts 存放she...