架構拓撲
| 角色 | IP | 主機名 | Server ID |
| Monitor | 192.168.84.174 | monitor | - |
| Master 1 | 192.168.85.167 | db1 | 1 |
| Master 2 | 192.168.85.169 | db2 | 2 |
| Slave 1 | 192.168.85.171 | db3 | 3 |
| Slave 2 | 192.168.85.168 | db4 | 4 |
虛擬 IP (VIP) 分配
| VIP | 角色 | 說明 |
| 192.168.85.200 | Writer | 唯一寫入入口,故障自動漂移 |
| 192.168.85.201 | Reader | 讀負載均衡 |
| 192.168.85.202 | Reader | 讀負載均衡 |
| 192.168.85.203 | Reader | 讀負載均衡 |
部署步驟總覽
- MySQL Replication:雙主雙從,GTID/傳統複制均可
- 建立同步用戶:replication / mmm_agent / mmm_monitor
- 資料同步:
FLUSH TABLES WITH READ LOCK → mysqldump → CHANGE MASTER TO → START SLAVE
- 安裝 MMM:
yum install mysql-mmm-monitor/agent + perl-Time-HiRes
- 配置三大文件:
mmm_common.conf, mmm_agent.conf, mmm_mon.conf
- 啟動服務:Agent → Monitor,
mmm_control show 驗證
關鍵配置片段
mmm_common.conf 核心段
active_master_role writer
cluster_interface eth0
pid_path /var/run/mysql-mmm/mmm_agentd.pid
bin_path /usr/libexec/mysql-mmm/
replication_user replication
replication_password replication
agent_user mmm_agent
agent_password agent
ip 192.168.85.167 mode master peer db2
ip 192.168.85.169 mode master peer db1
ip 192.168.85.171 mode slave
ip 192.168.85.168 mode slave
hosts db1,db2 ips 192.168.85.200 mode exclusive
hosts db2,db3,db4 ips 192.168.85.201,192.168.85.202,192.168.85.203 mode balanced
mmm_agent.conf(各 DB 節點修改 this)
include mmm_common.conf
this db1 # db2/db3/db4 對應修改
mmm_mon.conf(監控端)
include mmm_common.conf
ip 192.168.84.174
pid_path /var/run/mysql-mmm/mmm_mond.pid
bin_path /usr/libexec/mysql-mmm
status_path /var/lib/mysql-mmm/mmm_mond.status
ping_ips 192.168.85.167,192.168.85.169,192.168.85.171,192.168.85.168
auto_set_online 60
monitor_user mmm_monitor
monitor_password monitor
debug 0
踩坑記錄與解決
| 問題 | 現象 | 解決 |
| Monitor 啟動失敗 | Can't connect to monitor daemon | 缺 perl-Time-HiRes,yum install |
| Agent 不可達 | Warning: agent on host db1 is not reachable | 防火牆阻擋 9989 埠,關閉或放行 |
驗證命令
mmm_control show
# 輸出範例:
db1(192.168.85.167) master/ONLINE. Roles: writer(192.168.85.200)
db2(192.168.85.169) master/ONLINE. Roles: reader(192.168.85.202)
db3(192.168.85.171) slave/ONLINE. Roles: reader(192.168.85.203)
db4(192.168.85.168) slave/ONLINE. Roles: reader(192.168.85.201)
參考資源
現代替代方案提示
MMM 已停止維護,生產環境建議考慮:
- MHA(Master High Availability):成熟、廣泛使用
- Orchestrator:拓撲管理、自動故障轉移
- MySQL InnoDB Cluster:官方原生 Group Replication + Router
- ProxySQL + Keepalived:讀寫分離 + VIP 漂移
- 上一篇文章: MySQL 保留字踩坑記:group 欄位名導致語法錯誤
- 下一篇文章: PHP 開發者必知的 MySQL 常用操作指南
Copyright ©
程式碼之家 All Rights Reserved