体验MySQL MMM
?? ?今天試驗(yàn)了一把MySQL MMM.(MySQL Master-Master Replication Manager)一個(gè)主主復(fù)制的管理工具,它提供了主機(jī)監(jiān)控,MySQL服務(wù)監(jiān)控,復(fù)制線程等多個(gè)方位的監(jiān)控,使用VIP自動(dòng)漂移,可以對(duì)應(yīng)用程序?qū)崿F(xiàn)透明。
?? ?下面是試驗(yàn)步驟:
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:在建立復(fù)制環(huán)境時(shí)需要注意的幾點(diǎn):
1、server_id 要設(shè)置不同2、Auto_increment_offset=1 Auto_increment_increment=2 (master1 上設(shè)置)Auto_increment_offset=2 Auto_increment_increment=2 (master2上設(shè)置)?? ? ? 可以防止在某master假死并恢復(fù)的瞬間,兩個(gè)“master” 都出現(xiàn)數(shù)據(jù)的更新,導(dǎo)致復(fù)制失敗
?? ?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?? ?下載的二進(jìn)制包,直接make ?install (在所有機(jī)器上)
???? MMM主要的功能通過下面三個(gè)腳本來實(shí)現(xiàn):
mmm_mond
監(jiān)控進(jìn)程,負(fù)責(zé)所有的監(jiān)控工作,決定和處理所有節(jié)點(diǎn)角色活動(dòng)
???? mmm_agentd
運(yùn)行在每個(gè)mysql服務(wù)器上的代理進(jìn)程,完成監(jiān)控的探針工作和執(zhí)行簡(jiǎn)單的遠(yuǎn)端服務(wù)設(shè)置
??? mmm_control
?一個(gè)簡(jiǎn)單的腳本,提供管理mmm_mond進(jìn)程的命令
?? ?配置文件部分:
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 查看狀態(tài): 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)?? ?測(cè)試一、db2 宕機(jī),恢復(fù)情況:
?? ?日志分析:
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已經(jīng)從 online狀態(tài)到?HARD_OFFLINE ?主機(jī)存在,但是數(shù)據(jù)庫已“死”,DB1的線程也已經(jīng)停止,從 DB2上移除 reader角色到 DB3.
?? ?當(dāng)把DB2啟動(dòng)起來之后,它的狀態(tài)會(huì)變?yōu)?#xff1a;changed from HARD_OFFLINE to AWAITING_RECOVERY,
Check 'rep_threads' on 'db1' is ok!mmm_control set_online db2 手動(dòng)變?yōu)閛nline狀態(tài),它會(huì)重新獲得reader角色:Admin changed state of 'db2' from AWAITING_RECOVERY to ONLINEINFO Moving role 'reader(192.168.1.202)' from host 'db3' to host 'db2'?? ?測(cè)試二:
?? ?DB1宕機(jī), DB2應(yīng)該變?yōu)閣riter,db3 slave 把主定向?yàn)閐b2.
?? ?日志分析:
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 檢測(cè)到 DB2和DB3 與DB1 之間的復(fù)制已經(jīng)停止,10次檢查后,確定DB1 已經(jīng) “死掉”,將它的writer ip 轉(zhuǎn)移至 DB2,db3 復(fù)制線程停止后,將其擁有的 reader ip摘除,當(dāng) db3 重新與 DB2建立主從關(guān)系后,又獲得 reader 角色;
?? ?等DB1恢復(fù)后, ?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)?? 手動(dòng)將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)?? 在測(cè)試的時(shí)候,間隔要超過60s,原因是:MMM防抖動(dòng)檢測(cè):
?? 當(dāng)主機(jī)從Online 狀態(tài)轉(zhuǎn)換為HARD_OFFLINE/REPLICATION_FAIL/REPLICATION_DELAY,又從這些狀態(tài)轉(zhuǎn)換為online(在小于60s的情況下)
?? ?MMM 會(huì)阻止這種情況的發(fā)生,我們可以通過配置文件配置它,如果一個(gè)主機(jī)在flap_duration時(shí)間內(nèi)宕掉了flap_count次,就認(rèn)為主機(jī)處理flap狀態(tài),這個(gè)主機(jī)就不會(huì)自動(dòng)被設(shè)置為ONLINE狀 態(tài),它將一直處于AWAITING_RECOVERY狀態(tài)除非手動(dòng)設(shè)置online(mmm_control set online host)。如果auto_set_online>0,處于flapping的主機(jī)在flap_duration時(shí)間后將制動(dòng)被設(shè)置為ONLINE 狀態(tài)。
?? 英文參考地址:http://mysql-mmm.org/mysql-mmm.html
?? 中文參考地址:http://linuxguest.blog.51cto.com/195664/578311
?? ?
?
?
?
?
?? ??
轉(zhuǎn)載于:https://blog.51cto.com/weipengfei/971419
總結(jié)
以上是生活随笔為你收集整理的体验MySQL MMM的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: System Center 2012与v
- 下一篇: SQL server 2008 数据库企