mysql資料庫監控

2021-08-20 09:28:00 字數 1563 閱讀 2142

方法一

netstat -lanp|grep tcp|grep 3306|wc -l

方法二

/usr/bin/lsof -i:3306|wc -l

方法三

mysql -u使用者名稱 -p密碼 -e 「select version();』 &>/dev/null

echo $?

判斷返回值

方法四

ps -ef|grep mysql|grep -v grep|wc -l

// 在利用程序判斷時,如果語句放置於指令碼中,指令碼的名稱就不要包含有mysql的字樣了,否則就會產生判斷不準確的情況出現,因為會把指令碼也grep了一次,導致結果不準確;

**如下:

#!/bin/bash

status=`/etc/init.d/mysqld status|grep running|wc -l`

process=`ps -ef |grep mysqld|grep -v grep|wc -l`

port=`lsof -i:3305|grep -i listen|wc -l`

ip_now=$(ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk ''|tr -d

"addr:")

colony="200.200.169.10"

result=$(echo

$ip_now | grep "$")

mysql -uroot -psangfordb-e

"show databases;" >/dev/null 2>/dev/null

a=$?

if [ $a

-eq0 ] && [ $port

-ne0 ] && [ $process

-ne0 ] && [ $status

-ne0 ]

then

echo

"mysql is running"

else

echo

"mysql is not running"

/etc/init.d/mysqlaccd stop

if [[ "$result" != "" ]]

then

echo

"替換hosts"

#判斷是否為集群,如果是,則替換hosts檔案

echo

"$ip_now"

sed -i "s/^.*workflowdb的服務網域名稱.*$/$ip_now workflowdb的服務網域名稱/" /etc/hosts

sed -i "s/^.*reimbursedb的服務網域名稱.*$/$ip_now reimbursedb的服務網域名稱/" /etc/hosts

sed -i "s/^.*storedb的服務網域名稱.*$/$ip_now storedb的服務網域名稱/" /etc/hosts

echo

"替換hosts檔案成功"

fiecho

"重啟mysql"

/etc/init.d/mysqld restart

fi

zabbix監控mysql資料庫

zabbix3後的版本自帶mysql監控,因此我們只需要配置並使用自帶的mysql模板即可監控mysql資料庫。建立mysql使用者,使zabbix anget可以使用賬號連線本地mysql mysql grant all on to zabbix localhost identified by z...

MySQL 資料庫 效能監控

show status flush status 檢視當前連線數 show status like thread thread cached 被快取的執行緒的個數 thread running 處於啟用狀態的執行緒的個數 thread connected 當前連線的執行緒的個數 thread cre...

MySQL 資料庫 效能監控

show status flush status 檢視當前連線數 show status like thread thread cached 被快取的執行緒的個數 thread running 處於啟用狀態的執行緒的個數 thread connected 當前連線的執行緒的個數 thread cre...