/etc/hosts 互解。repl、監控用戶 mmm_monitor、代理用戶 mmm_agent。mysql-mmm-monitor + mysql-mmm-agent;DB 節點僅裝 mysql-mmm-agent。active_master_role writer <host default> cluster_interface eth0 pid_path /var/run/mysql-mmm/mmm_agentd.pid bin_path /usr/libexec/mysql-mmm/ replication_user repl replication_password repl agent_user mmm_agent agent_password mmm_agent </host> <host master> ip 192.168.137.10 mode master peer backup </host> <host backup> ip 192.168.137.20 mode master peer master </host> <host slave> ip 192.168.137.30 mode slave </host> <role writer> hosts master,backup ips 192.168.137.100 mode exclusive </role> <role reader> hosts backup,slave ips 192.168.137.120,192.168.137.130,192.168.137.140 mode balanced </role>
include mmm_common.conf
<monitor>
ip 127.0.0.1
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.137.10,192.168.137.20,192.168.137.30
auto_set_online 0
<host default>
monitor_user mmm_monitor
monitor_password mmm_monitor
</host>
debug 0
</monitor>
# DB 節點 chkconfig mysql-mmm-agent on && service mysql-mmm-agent start # Monitor 節點 chkconfig mysql-mmm-monitor on && service mysql-mmm-monitor start # 驗證 mmm_control checks all mmm_control show
mmm_control move_role writer backup(Slave 自動重指向新 Master)。mmm_control set_offline backup / set_online backup。writer role 中只保留 hosts master,故障時不漂移 VIP,但失去寫可用性。read_only、綁定/解綁 VIP、發起 Slave 切主。HARD_OFFLINE → AWAITING_RECOVERY → ONLINE,auto_set_online 控制自動上線延遲(預設 60s)。my.cnf 設 read_only=1,由 Monitor 動態關閉 Writer 的 read_only。MMM 提供「雙主熱備 + 讀負載均衡 + VIP 自動漂移」,核心在 Monitor 決策、Agent 執行、復制拓撲自動調整。生產環境需注意主從延遲觸發誤切換、Monitor 單點風險(可雙監控心跳)。