溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Mysql如何實(shí)現(xiàn)主從延遲監(jiān)控

發(fā)布時間:2021-11-02 14:52:35 來源:億速云 閱讀:208 作者:小新 欄目:MySQL數(shù)據(jù)庫

這篇文章主要介紹了Mysql如何實(shí)現(xiàn)主從延遲監(jiān)控,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

Mysql 主從延時監(jiān)控

pt-heartbeat -uroot -proot  -D chenmh --create-table --update  --daemonize

-u:連接主庫的用戶

-p:連接主庫的用戶密碼

-D:主庫上存在的數(shù)據(jù)庫,這個數(shù)據(jù)庫隨便指定,但是必須存在

--create-table:默認(rèn)會在主庫指定的數(shù)據(jù)庫中創(chuàng)建一個“heartbeat”表

2.監(jiān)控從庫

pt-heartbeat -uroot -proot -D chenmh --table=heartbeat --master-server-id=10 --monitor -h 192.168.137.20 --interval=1

這里面的參數(shù)除了--master-server-id是主庫的serverid,其它的都是指從庫,特別注意--master-server-id一定不能寫錯否則結(jié)果就是錯誤的,記錄了日志之后就可以對該值做監(jiān)控預(yù)警了

3.寫入監(jiān)控日志做預(yù)警分析

pt-heartbeat -uroot -proot -D chenmh --table=heartbeat --master-server-id=10 --monitor -h 192.168.137.20 --interval=1 --file=/tmp/heart.log
cat /tmp/heart.log |awk -F "s" '{print $1}'

 4.停止后臺更新操作

pt-heartbeat --stop

 當(dāng)你停止了后臺更新進(jìn)程會在/tmp目錄下面產(chǎn)生一個pt-heartbeat-sentinel文件,下次再啟動該后臺進(jìn)程之前必須先刪除該文件,否則無法啟動。

rm -rf /tmp/pt-heartbeat-sentinel

參數(shù)

Usage: pt-heartbeat [OPTIONS] [DSN] --update|--monitor|--check|--stop
其中--update, --moniter,--check,--stop都是單獨(dú)使用的,并且--update, --monitor, and --check are mutually exclusive
--daemonize and --check are mutually exclusive.他們之間還是存在互斥。
Options: --ask-pass                  使用密碼進(jìn)行mysql連接時給予提示
  --charset=s             -A  默認(rèn)的字符選項(xiàng)
  --check                     執(zhí)行一次從庫的監(jiān)控就結(jié)束 --check-read-only           如果是只讀的服務(wù)器那么使用該選項(xiàng)會保持插入
  --config=A                  使用逗號分隔,如果指定了,那么該參數(shù)作為命令行的第一個選項(xiàng)
  --create-table              如果表不存在創(chuàng)建表heartbeat
  --daemonize                 創(chuàng)建后臺的更新shell
  --database=s            -D  指定連接的數(shù)據(jù)庫
  --dbi-driver=s              Specify a driver for the connection; mysql and Pg
                              are supported (default mysql) --defaults-file=s       -F  通過提供的文件進(jìn)行mysql連接
  --file=s                    輸出最新的  --monitor監(jiān)控信息到指定的文件
  --frames=s                  設(shè)置時間周期(default 1m,5m,15m) --help                      顯示幫助信息 --host=s                -h  指定連接的host --[no]insert-heartbeat-row  在使用--tables的時候默認(rèn)是插入一條記錄到表heartbeat前提是表中不存在該記錄行 
  --interval=f                指定更新和監(jiān)控heartbeat表的頻率默認(rèn)是1S
  --log=s                     當(dāng)使用daemonized進(jìn)行后臺更新操作時輸出所有的信息到指定的該文件 --master-server-id=s        指定主的server-id
  --monitor                   監(jiān)控從服務(wù)器的參數(shù)選項(xiàng) --password=s            -p  指定密碼 --pid=s                     創(chuàng)建pid文件 --port=i                -P  指定連接時使用的端口
  --print-master-server-id    打印輸出master-server-id
  --recurse=i                 Check slaves recursively to this depth in --check
                              mode --recursion-method=a        Preferred recursion method used to find slaves ( default processlist,hosts) --replace                   使用replace替換--UPDATE操作
  --run-time=m                指定監(jiān)控的時長,單位有: s=seconds, m=minutes, h=hours, d=days; 如果比指定默認(rèn)是以秒為單位一直監(jiān)控下去
  --sentinel=s                Exit if this file exists (default /tmp/pt- heartbeat-sentinel) --set-vars=A                Set the MySQL variables in this comma-separated
                              list of variable=value pairs --skew=f                    指定執(zhí)行從庫檢查的延時時長默認(rèn)是0.5
  --socket=s              -S  指定連接時使用的socket文件
  --stop                      停止后臺更新進(jìn)程并生成--sentinel指定的文件 --table=s                   指定更新的表(默認(rèn)是heartbeat) --update                    更新主的heartbeat表,這個參數(shù)是后臺進(jìn)程必須的參數(shù)也可以用--replace替代 --user=s                -u  指定用戶名
  --utc                       忽略系統(tǒng)時間僅使用UTC --version                   顯示版本信息 --[no]version-check         Check for the latest version of Percona Toolkit,
                              MySQL, and other programs (default yes)

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“Mysql如何實(shí)現(xiàn)主從延遲監(jiān)控”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI