体验MySQL MMM
?? ?今天試驗了一把MySQL MMM.(MySQL Master-Master Replication Manager)一個主主復制的管理工具,它提供了主機監控,MySQL服務監控,復制線程等多個方位的監控,使用VIP自動漂移,可以對應用程序實現透明。
?? ?下面是試驗步驟:
OS: Ubuntu 11.04 X64DB1:192.168.1.186 (MASTER1)DB2:192.168.1.187 (MASTER2)DB3:192.168.1.184 (SLAVE)Monitor: 192.168.1.175虛擬ip:192.168.1.200(writer),192.168.1.201/202(reader)?? ?MySQL V5.1.50(源碼安裝)
?? ?MMM V2.2.1 下載地址:http://mysql-mmm.org/downloads
?? ?安裝部分參考地址:參考地址:http://mysql-mmm.org/mmm2:guide
?? ?Note:在建立復制環境時需要注意的幾點:
1、server_id 要設置不同2、Auto_increment_offset=1 Auto_increment_increment=2 (master1 上設置)Auto_increment_offset=2 Auto_increment_increment=2 (master2上設置)?? ? ? 可以防止在某master假死并恢復的瞬間,兩個“master” 都出現數據的更新,導致復制失敗
?? ?3、master上都要啟用 log_slave_updates,log_bin
?? ?MMM 安裝:
?? ?所需用戶:
| monitor user | used by the mmm monitor to check the health of the MySQL servers | REPLICATION CLIENT |
| agent user | used by the mmm agent to change read-only mode, replication master, etc. | SUPER, REPLICATION CLIENT, PROCESS |
| relication user | used for replication | REPLICATION SLAVE ? |
?? ? perl 依賴包安裝:
?? ??(DB需要安裝部分:)
?? ?monitoring ?安裝部分:
perl -MCPAN -e shell cpan> install Algorithm::Diff cpan> install Class::Singleton cpan> install Log::Dispatch cpan> install Log::Log4perl cpan> install Mail::Send cpan> install Proc::Daemon cpan> install Thread::Queue cpan> install Time::HiRes cpan> install DBIcpan>install DBD::mysql?? ?下載的二進制包,直接make ?install (在所有機器上)
???? MMM主要的功能通過下面三個腳本來實現:
mmm_mond
監控進程,負責所有的監控工作,決定和處理所有節點角色活動
???? mmm_agentd
運行在每個mysql服務器上的代理進程,完成監控的探針工作和執行簡單的遠端服務設置
??? mmm_control
?一個簡單的腳本,提供管理mmm_mond進程的命令
?? ?配置文件部分:
active_master_role writer <host default>cluster_interface eth0pid_path /var/run/mmm_agentd.pidbin_path /usr/lib/mysql-mmm/replication_user abcreplication_password MMMagent_user mmm_agentagent_password MMMmysql_port 3308 </host> <host db1>ip 192.168.1.186mode masterpeer db2 </host> <host db2>ip 192.168.1.187mode masterpeer db1 </host> <host db3>ip 192.168.1.184mode slave </host> <role writer>hosts db2,db1ips 192.168.1.200mode exclusive </role> <role reader>hosts db2,db3ips 192.168.1.201,192.168.1.202mode balanced </role>?? ?monitoring 部分:
active_master_role writer <host default>cluster_interface eth0pid_path /var/run/mmm_agentd.pidbin_path /usr/lib/mysql-mmm/replication_user abcreplication_password MMMagent_user mmm_agentagent_password MMMmysql_port 3308 </host> <host db1>ip 192.168.1.186mode masterpeer db2 </host> <host db2>ip 192.168.1.187mode masterpeer db1 </host> <host db3>ip 192.168.1.184mode slave </host> <role writer>hosts db2,db1ips 192.168.1.200mode exclusive </role> <role reader>hosts db2,db3ips 192.168.1.201,192.168.1.202mode balanced </role> 安裝好后: mmm_control show 查看狀態: db1(192.168.1.186) master/ONLINE. Roles: writer(192.168.1.200)db2(192.168.1.187) master/ONLINE. Roles: reader(192.168.1.201)db3(192.168.1.184) slave/ONLINE. Roles: reader(192.168.1.202)?? ?測試一、db2 宕機,恢復情況:
?? ?日志分析:
2012/08/23 17:02:59 WARN Check 'rep_backlog' on 'db2' is in unknown state! Message: UNKNOWN: Connect error (host = 192.168.1.187:3308, user = mmm_monitor)! Lost connection to MySQL server at 'reading initial communication packet', system error: 1112012/08/23 17:02:59 WARN Check 'rep_threads' on 'db2' is in unknown state! Message: UNKNOWN: Connect error (host = 192.168.1.187:3308, user = mmm_monitor)! Lost connection to MySQL server at 'reading initial communication packet', system error: 1112012/08/23 17:03:09 ERROR Check 'mysql' on 'db2' has failed for 10 seconds! Message: ERROR: Connect error (host = 192.168.1.187:3308, user = mmm_monitor)! Lost connection to MySQL server at 'reading initial communication packet', system error: 1112012/08/23 17:03:09 ERROR Check 'rep_threads' on 'db1' has failed for 10 seconds! Message: ERROR: Replication is broken2012/08/23 17:03:10 FATAL State of host 'db2' changed from ONLINE to HARD_OFFLINE (ping: OK, mysql: not OK)2012/08/23 17:03:10 INFO Removing all roles from host 'db2':2012/08/23 17:03:10 INFO Removed role 'reader(192.168.1.201)' from host 'db2'2012/08/23 17:03:10 INFO Orphaned role 'reader(192.168.1.201)' has been assigned to 'db3'?? ?其中我們可以看到,monitor 通過10次 mysql檢查,判定DB2已經從 online狀態到?HARD_OFFLINE ?主機存在,但是數據庫已“死”,DB1的線程也已經停止,從 DB2上移除 reader角色到 DB3.
?? ?當把DB2啟動起來之后,它的狀態會變為:changed from HARD_OFFLINE to AWAITING_RECOVERY,
Check 'rep_threads' on 'db1' is ok!mmm_control set_online db2 手動變為online狀態,它會重新獲得reader角色:Admin changed state of 'db2' from AWAITING_RECOVERY to ONLINEINFO Moving role 'reader(192.168.1.202)' from host 'db3' to host 'db2'?? ?測試二:
?? ?DB1宕機, DB2應該變為writer,db3 slave 把主定向為db2.
?? ?日志分析:
2012/08/23 17:14:51 WARN Check 'rep_threads' on 'db1' is in unknown state! Message: UNKNOWN: Connect error (host = 192.168.1.186:3308, user = mmm_monitor)! Lost connection to MySQL server at 'reading initial communication packet', system error: 1112012/08/23 17:14:51 WARN Check 'rep_backlog' on 'db1' is in unknown state! Message: UNKNOWN: Connect error (host = 192.168.1.186:3308, user = mmm_monitor)! Lost connection to MySQL server at 'reading initial communication packet', system error: 1112012/08/23 17:15:00 ERROR Check 'mysql' on 'db1' has failed for 10 seconds! Message: ERROR: Connect error (host = 192.168.1.186:3308, user = mmm_monitor)! Lost connection to MySQL server at 'reading initial communication packet', system error: 1112012/08/23 17:15:01 ERROR Check 'rep_threads' on 'db2' has failed for 10 seconds! Message: ERROR: Replication is broken2012/08/23 17:15:01 ERROR Check 'rep_threads' on 'db3' has failed for 10 seconds! Message: ERROR: Replication is broken2012/08/23 17:15:02 FATAL State of host 'db1' changed from ONLINE to HARD_OFFLINE (ping: OK, mysql: not OK)2012/08/23 17:15:02 INFO Removing all roles from host 'db1':2012/08/23 17:15:02 INFO Removed role 'writer(192.168.1.200)' from host 'db1'2012/08/23 17:15:02 INFO Orphaned role 'writer(192.168.1.200)' has been assigned to 'db2'2012/08/23 17:15:06 FATAL State of host 'db3' changed from ONLINE to REPLICATION_FAIL2012/08/23 17:15:06 INFO Removing all roles from host 'db3':2012/08/23 17:15:06 INFO Removed role 'reader(192.168.1.201)' from host 'db3'2012/08/23 17:15:06 INFO Check 'rep_threads' on 'db3' is ok!2012/08/23 17:15:06 INFO Orphaned role 'reader(192.168.1.201)' has been assigned to 'db2'2012/08/23 17:15:09 FATAL State of host 'db3' changed from REPLICATION_FAIL to ONLINE2012/08/23 17:15:09 INFO Moving role 'reader(192.168.1.202)' from host 'db2' to host 'db3'?? ?Monitor 檢測到 DB2和DB3 與DB1 之間的復制已經停止,10次檢查后,確定DB1 已經 “死掉”,將它的writer ip 轉移至 DB2,db3 復制線程停止后,將其擁有的 reader ip摘除,當 db3 重新與 DB2建立主從關系后,又獲得 reader 角色;
?? ?等DB1恢復后, ?mmm_control show
db1(192.168.1.186) master/ONLINE. Roles: db2(192.168.1.187) master/ONLINE. Roles: reader(192.168.1.201), writer(192.168.1.200)db3(192.168.1.184) slave/ONLINE. Roles: reader(192.168.1.202)?? 手動將DB1獲得writer角色:
mmm_control move_role writer db1db1(192.168.1.186) master/ONLINE. Roles: writer(192.168.1.200)db2(192.168.1.187) master/ONLINE. Roles: reader(192.168.1.201)db3(192.168.1.184) slave/ONLINE. Roles: reader(192.168.1.202)?? 在測試的時候,間隔要超過60s,原因是:MMM防抖動檢測:
?? 當主機從Online 狀態轉換為HARD_OFFLINE/REPLICATION_FAIL/REPLICATION_DELAY,又從這些狀態轉換為online(在小于60s的情況下)
?? ?MMM 會阻止這種情況的發生,我們可以通過配置文件配置它,如果一個主機在flap_duration時間內宕掉了flap_count次,就認為主機處理flap狀態,這個主機就不會自動被設置為ONLINE狀 態,它將一直處于AWAITING_RECOVERY狀態除非手動設置online(mmm_control set online host)。如果auto_set_online>0,處于flapping的主機在flap_duration時間后將制動被設置為ONLINE 狀態。
?? 英文參考地址:http://mysql-mmm.org/mysql-mmm.html
?? 中文參考地址:http://linuxguest.blog.51cto.com/195664/578311
?? ?
?
?
?
?
?? ??
轉載于:https://blog.51cto.com/weipengfei/971419
總結
以上是生活随笔為你收集整理的体验MySQL MMM的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: System Center 2012与v
- 下一篇: linux cmake编译源码,linu