MySQLã§ãã¬ããªã±ã¼ã·ã§ã³ãã¼ã¹ã®HAãªæ§æã«ã¤ãã¦èããã¡ã¢ã§ãã
3å°(ã¨ããã2å°ï¼1å°)ãããããªãã¨æã£ã¦ãã¦ãååã¯ãã®çç±ããå¾åã§ã¯{ãã¹ã¿,ã¹ã¬ã¼ã}ã{åèµ·ä¸è½ã«ãªã£ã,ã¡ãã£ã¨ãã¦ã³ãã¦ãã復帰ãã}å ´åã®ãªã«ããªãã©ã³ã«ã¤ãã¦æ¸ãã¾ãã
ä»ã®ã¨ããã¯ããããã¹ãããªã¨æã£ã¦ããã®ã§ããããããããã»ããããã¨æãï¼ãããããããããï¼ããªã©ãªã©ã®ãæè¦ã¯ã³ã¡ã³ããTBãªã©ã§ããã ããã¨ããããã§ãã
ã´ã¼ã«
- ãã¹ã¿ãè½ã¡ã¦ããã¼ããå¯ã¦ããããããã«ããã
- ãªã«ããªã®ä½æ¥ã¯ã§ããã ãåç´ã«ããã¤ãçæéã§å®äºããããã«ããã
- ããã©ãããã®ã¯ãã
åºæ¬æ§æãæ¹é
- 2å°ï¼1å°
- ãµã¼ãã¹ã§ä½¿ãã®ã¯2å° (db1, db2)
- ãã1å°ã¯ç®¡çç¨ (db3)
- ã¹ã¬ã¼ããå¤æ°ä¸¦ã¹ãæ§æã«ã¯ããªã
- å°æ°å¢ããã¨ç®¡çã³ã¹ããä¸ãã
- ãã¹ã¿ãã¦ã³æã®ãã§ã¤ã«ãªã¼ãã¨ãã®ãã§ã¤ã«ããã¯ã®ä½æ¥ãç
©éã«ãªã
- DBãµã¼ãã¯ã並ã¹ãã ãã§æ¸ãWebãµã¼ãã¨éã
- ã¢ã¯ã»ã¹ãæããªããªããããªã¨ãã¯:
- MySQLãã¢ããªã®ãã¥ã¼ãã³ã°ã§ä¹ãè¶ãã
- ã©ã¼ãã¦ãçªç ´ã§ããªãã¨ãã¯ãã¹ã±ã¼ã«ã¢ãããèãã
- ããã§ãã©ã¼ãã¦ãçªç ´ã§ããªãã¨ãã¯ãæ°´å¹³ãã¼ãã£ã·ã§ãã³ã°ãèãã
- ããã§ãããã§ãã©ã¼ãã¦ãçªç ´ã§ããªãã¨ãã¯ãåç´ãã¼ãã£ã·ã§ãã³ã°ãèãã
ã¬ããªã±ã¼ã·ã§ã³ã®ä¸çã®è©±
- db1ã¨db2ã¯åæ¹åã¬ããªã±ã¼ã·ã§ã³ãã¦ãã
-
- ãã¹ã¿ã®æå®ã§ã¯ããµã¼ãåºæã®IPã¢ãã¬ã¹(=db1ãdb2ã®IPã¢ãã¬ã¹)ã使ããæµ®åIPã¢ãã¬ã¹(å¾è¿°)ã®db0ãªã©ã¯æå®ããªãã
- åæ¹åã¬ããªã±ã¼ã·ã§ã³ãã¦ããçç±
- ä¾ãã°ããã©ã¤ããªãããªã¼ãºããã®ã§ãªã»ãããã¦å¾©å¸°ããå ´åããªã©ããã©ã¤ããªã ã£ããµã¼ããçãæéã®å¾ã«å¾©å¸°ããå ´åã®å¾©æ§ä½æ¥ã楽ã«ããããã詳ããã¯å¾è¿°ã
- çµé¨ä¸ããçæéã®åæ¢ãã¯å²ã¨ãããããã¨ãªã®ã§ã復帰æé ãç°¡åã«ãããã
ç¨èªã®æ´ç: ãã©ã¤ããªã¨ã»ã«ã³ããªã¨ããã¯ã¢ãã
- ãã©ã¤ããªã¨ã¯ãæ´æ°ç³»ã¯ã¨ãªãåãä»ããå¯ä¸ã®ãµã¼ãã®ãã¨
- ãã©ã¤ããªã®å®ä½ã¨ãããæ£ä½ã¨ãããã¯æµ®åIPã¢ãã¬ã¹
- ã»ã«ã³ããªã¨ã¯ãåç §ç³»ã®ã¯ã¨ãªãåãä»ãããµã¼ãã®ãã¨
- ããã¯ã¢ããã¨ã¯ãå®ãµã¼ãã¹ã«ã¯ä½¿ããªãã¹ã¬ã¼ãã®ãã¨
- ã¯ã©ã¤ã¢ã³ãã¯ããã©ã¤ããªã®VIPã«åãã¦æ´æ°ç³»ã¯ã¨ãªãçºè¡ãã
- ãã©ã¤ããªã®VIPã¯ã²ã¨ã¤ã®ãµã¼ãã«ããä»ä¸ãããªãã®ã§ãæ´æ°ç³»ã¯ã¨ãªãåãä»ãå¦çããã®ã¯ããã ä¸ã¤ã®ãµã¼ãã¨ãããã¨ã«ãªã
- ã¯ã©ã¤ã¢ã³ãã¯lvsãä»ãã¦ã»ã«ã³ããªã«åç
§ç³»ã¯ã¨ãªãçºè¡ãã
- ã»ã«ã³ããªãåæ¢ãã¦ãåç §ç³»ã¯ã¨ãªãå¦çã§ããããã«ããã¼ããã©ã³ãµãä»ãã¦ã»ã«ã³ããªã¨ãã©ã¤ããªã§ã¢ã¯ãã£ã/ããã¯ã¢ããæ§æã«ããããéã¿ä»ãã®ãã¼ããã©ã³ã¹ã«ããã
- ã»ã«ã³ããªã¯ set global read_only = 1 ãã¦ãæ´æ°ç³»ã¯ã¨ãªãæ¥ã¦ãã¾ã£ã¦ãåãå ¥ããªãããã«ããï¼äºæ é²æ¢ï¼
- ããã¯ã¢ããã®ç¨é:
- æ¥æ¬¡ã®ã¹ãããã·ã§ããã®æ¡åã« (7ä¸ä»£ãããä¿åãã)
- for db in ALL_DB; do mysqldump --opt --no-autocommit --hex-blob -master-data=2 --database $db | gzip -c > YYYYMMDD/$db.gz; done
- éè¨ãªã©ã«
- å®ãµã¼ãã¹ã«ã¯æå ¥ãã¦ããªãã®ã§ãéãã¯ã¨ãªãçºè¡ãã¦ãOKã
- æ¥æ¬¡ã®ã¹ãããã·ã§ããã®æ¡åã« (7ä¸ä»£ãããä¿åãã)
é害æã®å¯¾å¿æé
ãã©ã¤ããªãåèµ·ä¸è½
- ãã©ã¤ããªã«ãã¼ã¿ã®æ¶å¤±ãä¼´ãæ éãçºçããå ´å
- ä½æ¥æ¦è¦
- ãã©ã¤ããªããã¦ã³ããæç¹ã§ã(èªåçã«)ã»ã«ã³ããªããã©ã¤ããªã«ææ ¼ãã
- æ§ãã©ã¤ããªã¯æ é解æ¶å¾ãããã¯ã¢ããããã®ã¾ããã¨ã³ãã¼ã使ã£ã¦å¾©æ§ããã
- ãã©ã¤ããªããã¦ã³
- â ãµã¼ãã¹åæ¢â (æ´æ°ç³»ã®ã¿åæ¢)
- <ã»ã«ã³ããªããã©ã¤ããªã«ææ ¼>
- âæ´æ°ãåç §å ±ã«æ°ãã©ã¤ããªã«è¡ã
- â æ°ãã©ã¤ããªå¾©æ§â
- â ãµã¼ãã¹ä»®å¾©æ§â
- æ§ã»ã«ã³ããªã¨ããã¯ã¢ããã§ãSHOW SLAVE STATUSã®Exec_Master_Log_Posãæ¯è¼ãã
- â¼(A):æ§ã»ã«ã³ããªExec_Pos = ããã¯ã¢ããExec_Pos:
- æ§ã»ã«ã³ããªã¨ããã¯ã¢ããã®ãã¼ã¿ã®åæç¹ãã¨ããã®ã§æ¬¡ã®ã¹ããã(C)ã¸ç§»ãâ
- â¼æ§ã»ã«ã³ããªExec_Pos > ããã¯ã¢ããExec_Pos:
- æ§ã»ã«ã³ããªã¨ããã¯ã¢ããã§ãSHOW SLAVE STATUSã®Read_Master_Log_Posãæ¯è¼ãã
- â¼æ§ã»ã«ã³ããªRead_Pos = ããã¯ã¢ããRead_Pos:
- Exec_Posãåãã«ãªãã¾ã§å¾ ã£ã¦ãã¹ããã(A)ã¸ç§»ãâ
- â¼æ§ã»ã«ã³ããªRead_Pos > ããã¯ã¢ããRead_Pos:
- æ§ã»ã«ã³ããªã¨ããã¯ã¢ããã®relayãã°ãmysqlbinlogã§è¦ã¦æ¯è¼ããå·®åã®ã¯ã¨ãªãããã¯ã¢ããã«å¯¾ãã¦æåã§çºè¡ããã
- å¾ãExec_Posãåãã«ãªãã¾ã§å¾ ã£ã¦ãã¹ããã(A)ã¸ç§»ãâ
- â¼æ§ã»ã«ã³ããªRead_Pos < ããã¯ã¢ããRead_Pos:
- (B):ããã¾ãèµ·ãããªãã¯ããèµ·ããã¨ã¡ãã£ã¨ã¾ããã·ãã¥ã¨ã¼ã·ã§ã³ããã
- æ§ã»ã«ã³ããªã¨ããã¯ã¢ããã®relayãã°ãmysqlbinlogã§è¦ã¦æ¯è¼ããå·®åã®ã¯ã¨ãªãæ§ã»ã«ã³ããªã«å¯¾ãã¦æåã§çºè¡ããã
- æ§ã»ã«ã³ããªã¯æ¢ã«æ°ãã©ã¤ããªã¨ãã¦æ´æ°ç³»ã¯ã¨ãªãåãä»ãã¦ããã®ã§ãå·®åã®ç¢ºèªã¨ãã®é©ç¨ã¯ãæ°ãã©ã¤ããªã«ãªã£ãå¾ã§åãä»ããã¯ã¨ãªãå å³ãã¦æ éã«æ¤è¨ããå¿ è¦ãããã
- å¾ãExec_Posãåãã«ãªãã¾ã§å¾ ã£ã¦ãã¹ããã(A)ã¸ç§»ãâ
- â¼æ§ã»ã«ã³ããªRead_Pos = ããã¯ã¢ããRead_Pos:
- æ§ã»ã«ã³ããªã¨ããã¯ã¢ããã§ãSHOW SLAVE STATUSã®Read_Master_Log_Posãæ¯è¼ãã
- â¼æ§ã»ã«ã³ããªExec_Pos < ããã¯ã¢ããExec_Pos:
- èµ·ããã¨ã¡ãã£ã¨ã¾ããã·ãã¥ã¨ã¼ã·ã§ã³
- æ§ã»ã«ã³ããªã¨ããã¯ã¢ããã§ãSHOW SLAVE STATUSã®Read_Master_Log_Posãæ¯è¼ãã
- â¼æ§ã»ã«ã³ããªRead_Pos = ããã¯ã¢ããRead_Pos:
- èµ·ããå¾ãªãã
- ãã©ã¤ããªã«ææ ¼ããéã«Readã¨Execãåãã«ãªãã¾ã§å¾ ã£ã¦ããã®ã§ãExecãæ§ã»ã«ã³ã㪠< ããã¯ã¢ããã§ãReadãæ§ã»ã«ã³ã㪠= ããã¯ã¢ããã«ãªãã®ã¯ããå¾ãªããå¾ ã¦ã°ããã¯ã¢ããã®Exec_Posãé²ãã¯ããªã®ã§ã
- èµ·ããå¾ãªãã
- â¼æ§ã»ã«ã³ããªRead_Pos > ããã¯ã¢ããRead_Pos:
- Exec_Pos < Read_Pos ãªã®ã§ããå¾ãªã
- â¼æ§ã»ã«ã³ããªRead_Pos < ããã¯ã¢ããRead_Pos:
- èµ·ããã¨ã¡ãã£ã¨ã¾ããã·ãã¥ã¨ã¼ã·ã§ã³
- ã¹ããã(B)ã¸ç§»ãâ
- â¼æ§ã»ã«ã³ããªRead_Pos = ããã¯ã¢ããRead_Pos:
- â¼(A):æ§ã»ã«ã³ããªExec_Pos = ããã¯ã¢ããExec_Pos:
- ããã¯ã¢ããã®å¾©æ§
- (C):ããã¯ã¢ããã®mysqldãåæ¢ãã¦ã<丸ãã¨ããã¯ã¢ãããæ¡å>ãã
- master.infoãç·¨éãã¦ãæ°ãã©ã¤ããªã®ã¹ã¬ã¼ãã«ãªãããã«ãã
- Master_Host ãæ°ãã©ã¤ããªã®åæå(db0ã§ã¯ãªãdb2ãªã©)ã«å¤æ´
- æ°ãã©ã¤ããªã¯ææ ¼æã«ãã¤ããªãã°ããã¼ãã¼ããã¦ããã®ã§ã以ä¸ã®éãã«å¤æ´ãã
- Master_Log_Fileã¯æ°ãããã°ãã¡ã¤ã«å
- Read_Master_Log_Posã¯4
- ããã¯ã¢ããã®mysqldãèµ·åãã
- â ããã¯ã¢ãã復æ§â
- æ°ã»ã«ã³ããªã®å¾©æ§
- æ°ã»ã«ã³ããªã®ãµã¼ãã®ã»ããã¢ãããã§ããã
- ã¹ã¬ã¼ãã®ãã¼ããã©ã³ã¹ã°ã«ã¼ãã«å ¥ããªãããã«ãã
- (C)ã§æ¡åãã丸ãã¨ããã¯ã¢ãããå±éãã
- master.infoãç·¨éãã¦ãæ°ãã©ã¤ããªã®ã¹ã¬ã¼ãã«ãªãããã«ãã
- Master_Host ãæ°ãã©ã¤ããªã®åæå(db0ã§ã¯ãªãdb2ãªã©)ã«å¤æ´
- æ°ãã©ã¤ããªã¯ææ ¼æã«ãã¤ããªãã°ããã¼ãã¼ããã¦ããã®ã§ã以ä¸ã®éãã«å¤æ´ãã
- Master_Log_Fileã¯æ°ãããã°ãã¡ã¤ã«å
- Read_Master_Log_Posã¯4
- æ°ã»ã«ã³ããªã®mysqldãèµ·åãã
- æ°ãã©ã¤ããªã¨åæããã¾ã§å¾ ã¤
- æ°ã»ã«ã³ããªã§SHOW MASTER STATUSããæ°ãã©ã¤ããªã§ããã®Posã«CHANGE MASTER TOãã
- CHANGE MASTER TO MASTER_LOG_FILE = 'mysql-bin.000XXX', MASTER_LOG_POS = XXX;
- æ°ãã©ã¤ããªã§ START SLAVE
- ã¬ããªã±ã¼ã·ã§ã³ã追ãã¤ããã®ã確èªãã¦ã¹ã¬ã¼ãã®ãã¼ããã©ã³ã¹ã°ã«ã¼ãã«å ¥ãã
- â æ°ã»ã«ã³ããªå¾©æ§â
- â ãµã¼ãã¹å®å ¨å¾©æ§â
ãã©ã¤ããªãçæéåæ¢
- æ¯è¼ççæéã®åæ¢
- OS rebootãã
- ãã³ã°ã¢ããããã®ã§ãªã»ãããã
- ä½æ¥æ¦è¦
- ãã©ã¤ããªããã¦ã³ããæç¹ã§ã(èªåçã«)ã»ã«ã³ããªããã©ã¤ããªã«ææ ¼ãã
- æ§ãã©ã¤ããªã¯å¾©å¸°å¾ãã¬ããªã±ã¼ã·ã§ã³ãåéãã追ãã¤ãããã»ã«ã³ããªã¨ãã¦åç §ç³»ã¯ã¨ãªãå¦çããããã«ãã
- ãã©ã¤ããªããã¦ã³
- â ãµã¼ãã¹åæ¢â (æ´æ°ç³»ã®ã¿åæ¢)
- <ã»ã«ã³ããªããã©ã¤ããªã«ææ ¼>
- âæ´æ°ãåç §å ±ã«æ°ãã©ã¤ããªã«è¡ã
- â æ°ãã©ã¤ããªå¾©æ§â
- â ãµã¼ãã¹ä»®å¾©æ§â
- æ§ã»ã«ã³ããªã¨ããã¯ã¢ããã§ãSHOW SLAVE STATUSã®Exec_Master_Log_Posãæ¯è¼ãã
- (以ä¸âã®æé ã¨åã)
- æ§ãã©ã¤ããªã®mysqldã¯èµ·åããªã
- æ°ãã©ã¤ããªã®SHOW SLAVE STATUSã®Exec_Master_Log_Posã¨æ§ãã©ã¤ããªã®ææ°ã®ãã¤ããªãã°ã®æå¾ã®end_log_posãæ¯è¼
- mysqlbinlog $(ls -1t mysql-bin.[0-9]*|head -n 1) | grep end_log_pos | tail -n 1
- â¼(A):æ°ãã©ã¤ããªExec_Pos = æ§ãã©ã¤ããªend_log_pos:
- ã¹ããã(B)ã¸ç§»ãâ
- â¼æ°ãã©ã¤ããªExec_Pos > æ§ãã©ã¤ããªend_log_pos:
- sync_binlog = 0 ã«ãªã£ã¦ããã¨ãèµ·ããããã
- ä¸æã®é»æºæã¨ããªã»ãããããã£ãå ´åããã£ã¹ã¯ã«syncããã¦ããªãbinlogã¯å¤±ããã¦ãã¾ãã®ã§ã
- ãã®å ´åãæ§ãã©ã¤ããªã®ãã¼ã¿ã¯ä½¿ããªãã®ã§ãããã©ã¤ããªãåèµ·ä¸è½ãã®æé ã«å¾ãããã¼ã¿ãæ¨ã¦ã¦å¾©æ§ããã
- sync_binlog = 0 ã«ãªã£ã¦ããã¨ãèµ·ããããã
- â¼æ°ãã©ã¤ããªExec_Pos < æ§ãã©ã¤ããªend_log_pos:
- æ°ãã©ã¤ããªã®SHOW SLAVE STATUSã®Read_Master_Log_Posã¨æ§ãã©ã¤ããªã®1ã¤åã®ãã¤ããªãã°ã®æå¾ã®end_log_posãæ¯è¼
- â¼æ°ãã©ã¤ããªRead_Pos = æ§ãã©ã¤ããªend_log_pos:
- Exec_Posãåãã«ãªãã¾ã§å¾ ã£ã¦ãã¹ããã(A)ã¸ç§»ãâ
- â¼æ°ãã©ã¤ããªRead_Pos > æ§ãã©ã¤ããªend_log_pos:
- ããããªãã
- â¼æ°ãã©ã¤ããªRead_Pos < æ§ãã©ã¤ããªend_log_pos:
- èµ·ããã¨ã¡ãã£ã¨ã¾ããã·ãã¥ã¨ã¼ã·ã§ã³ã
- æ°ãã©ã¤ããªãªã¬ã¼ãã°ã¨æ§ãã©ã¤ããªã®ãã¤ããªãã°ãmysqlbinlogã§è¦ã¦æ¯è¼ããå·®åã®ã¯ã¨ãªãæ°ãã©ã¤ããªã«å¯¾ãã¦æåã§çºè¡ããã
- æ°ãã©ã¤ããªã¯æ¢ã«æ´æ°ç³»ã¯ã¨ãªãåãä»ãã¦ããã®ã§ãå·®åã®ç¢ºèªã¨ãã®é©ç¨ã¯ãæ°ãã©ã¤ããªã«ãªã£ãå¾ã§åãä»ããã¯ã¨ãªãå å³ãã¦æ éã«æ¤è¨ããå¿ è¦ãããã
- å¾ãExec_Posãåãã«ãªãã¾ã§å¾ ã£ã¦ãã¹ããã(A)ã¸ç§»ãâ
- â¼æ°ãã©ã¤ããªRead_Pos = æ§ãã©ã¤ããªend_log_pos:
- æ°ãã©ã¤ããªã®SHOW SLAVE STATUSã®Read_Master_Log_Posã¨æ§ãã©ã¤ããªã®1ã¤åã®ãã¤ããªãã°ã®æå¾ã®end_log_posãæ¯è¼
- (B):æ§ãã©ã¤ããªãæ°ãã©ã¤ããªã®ã¹ã¬ã¼ãã«ãã
- æ§ãã©ã¤ããªã®mysqldã¯åæ¢ãã¦ããã¯ã
- ã¹ã¬ã¼ãã®ãã¼ããã©ã³ã¹ã°ã«ã¼ãã«å ¥ããªãããã«ãã
- æ§ãã©ã¤ããªã®mysqldéå§
- my.cnfã«read_onlyã¨æ¸ãã¦ãã
- mysqldãèµ·åãã
- æ°ãã©ã¤ããªã§ START SLAVE ãã
- æ°ãã©ã¤ããªâæ§ãã©ã¤ããªã®ã¬ããªã±ã¼ã·ã§ã³ãéå§ããã
- æ§ãã©ã¤ããªã§ START SLAVE ãã (èªåçã«éå§ãã¦ããã)
- ã¬ããªã±ã¼ã·ã§ã³ã追ãã¤ããã®ã確èªãã¦ã¹ã¬ã¼ãã®ãã¼ããã©ã³ã¹ã°ã«ã¼ãã«å ¥ãã
- â æ°ã»ã«ã³ããªå¾©æ§â
- â ãµã¼ãã¹å®å ¨å¾©æ§â
ã»ã«ã³ããªãåèµ·ä¸è½
ã»ã«ã³ããªããã¦ã³ããã¨ãåç §ç³»ã®ã¯ã¨ãªã¯ãã©ã¤ããªã«æµããããã«ãã¦ããã®ã§ãã»ã«ã³ããªããã¦ã³ãã¦ããµã¼ãã¹ã«ã¯å½±é¿ãªãã
- ä½æ¥æ¦è¦
- ããã¯ã¢ããã§<ã¾ããã¨ããã¯ã¢ãããæ¡åãã>
- ããã¯ã¢ããã¯ãµã¼ãã¹ã«ä½¿ã£ã¦ãªãã®ã§æ¢ãã¦ãå½±é¿ãªã
- ãããã»ã«ã³ããªã«å±éãã¦ãmysqldãèµ·å
- ããã¯ã¢ããã§<ã¾ããã¨ããã¯ã¢ãããæ¡åãã>
ã»ã«ã³ããªãçæéåæ¢
- ä½æ¥æ¦è¦
- mysqldãç«ä¸ããã ãã§OK
å ±éæé
<ã»ã«ã³ããªããã©ã¤ããªã«ææ ¼>
- ãã©ã¤ããªã®æµ®åIPã¢ãã¬ã¹ãä»ä¸ãã
- Read_Master_Log_Pos ã Exec_Master_Log_Pos ã¨åãã«ãªãã¾ã§å¾ ã¤
- SHOW SLAVE STATUS ã®çµæãã¡ã¢ã
- STOP SLAVE
- FLUSH LOGS
- binlogããã¼ãã¼ããããã
- SET GLOBAL READ_ONLY = 0
<ã¾ããã¨ããã¯ã¢ãããæ¡åãã>
cd /db tar --exclude 'mysql-bin.*' -cvpf mysql.tar mysql