天天看點

mysql MMM詳解

master-master monitor(MMM)

一、MMM簡介

MMM即Master-Master Replication Manager for MySQL(mysql主主複制管理器)關于mysql主主複制配置的監控、故障轉移和管理的一套可伸縮的腳本套件(在任何時候隻有一個節點可以被寫入),這個套件也能對居于标準的主從配置的任意數量的從伺服器進行讀負載均衡,是以你可以用它來在一組居于複制的伺服器啟動虛拟ip,除此之外,它還有實作資料備份、節點之間重新同步功能的腳本。
   官網安裝步驟:http://mysql-mmm.org/mmm2:guide
   下載下傳位址:http://mysql-mmm.org/downloads      

二、MMM基本構架及實作原理

mysql MMM詳解

主要的思想還是主從複制,然後再多設定一個master來備用。MMM(Master-Master replication managerfor Mysql,Mysql主主複制管理器)是一套靈活的腳本程式,基于perl實作,用來對mysql replication進行監控和故障遷移,并能管理mysql Master-Master複制的配置(同一時間隻有一個節點是可寫的)。

  mmm_mond:監控程序,負責所有的監控工作,決定和處理所有節點角色活動。此腳本需要在監管機上運作。

  mmm_agentd:運作在每個mysql伺服器上的代理程序,完成監控的探針工作和執行簡單的遠端服務設定。此腳本需要在被監管機上運作。

  mmm_control:一個簡單的腳本,提供管理mmm_mond程序的指令。

  mysql-mmm的監管端會提供多個虛拟IP(VIP),包括一個可寫VIP,多個可讀VIP,通過監管的管理,這些IP會綁定在可用mysql之上,當某一台mysql當機時,監管會将VIP遷移至其他mysql。

  在整個監管過程中,需要在mysql中添加相關授權使用者,以便讓mysql可以支援監理機的維護。授權的使用者包括一個mmm_monitor使用者和一個mmm_agent使用者,如果想使用mmm的備份工具則還要添加一個mmm_tools使用者。

三、MMM的優缺點

優點:高可用性,擴充性好,出現故障自動切換,對于主主同步,在同一時間隻提供一台資料庫寫操作,保證的資料的一緻性。

缺點:Monitor節點是單點,可以結合Keepalived實作高可用。

MMM安裝

一、安裝準備工作 

伺服器:

伺服器 IP 作用 備注
DB1 192.168.1.238 master
DB2 192.168.1.239 備用master
DB3 192.168.1.13 slave
monitor 192.168.1.238 slave 測試用是以放在master上
ips:192.168.1.5(寫)、192.168.1.10(讀)

系統:centos6.5

二、安裝Mysql

三、配置複制 

配置DB1與DB2進行主主複制。 

配置DB1(master)與DB3(slave)進行主從複制。 

 四、配置使用者 

每個資料庫上都需要三個使用者:

function description privileges
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
replication user used for replication REPLICATION SLAVE

GRANT REPLICATION CLIENT ON . TO ‘mmm_monitor’@’192.168.1.%’ IDENTIFIED BY ‘monitor_password’; 

GRANT SUPER, REPLICATION CLIENT, PROCESS ON . TO ‘mmm_agent’@’192.168.1.%’ IDENTIFIED BY ‘agent_password’; 

GRANT REPLICATION SLAVE ON . TO 

‘replication’@’192.168.1.%’ IDENTIFIED BY ‘replication_password’;

五、安裝MMM 

用yum安裝時需要epel源,安裝配置方法: 

 1、DB1、DB2、DB3安裝mysql-MMM-agent 

yum install -y mysql-mmm-agent 

2、monitor安裝mysql-mmm-monitor 

yum -y install mysql-mmm-monitor

六、配置MMM 

1、配置DB1、DB2、DB3、monitor中的 /etc/mysql-mmm/mmm_common.conf

active_master_role          writer


<host default>
    cluster_interface       eth0

    pid_path                /var/run/mmmd_agent.pid
    bin_path                /usr/lib/mysql-mmm/

    replication_user        replication
    replication_password    replication_password

    agent_user              mmm_agent
    agent_password          agent_password
</host>

<host db1>
    ip                      192.168.1.238
    mode                    master
    peer                    db2
</host>

<host db2>
    ip                      192.168.1.239
    mode                    master
    peer                    db1
</host>

<host db3>
    ip                      192.168.1.13
    mode                    slave
</host>

#<host db4>
#    ip                      192.168.1.14
#    mode                    slave
#</host>


<role writer>
    hosts                   db1, db2
    ips                     192.168.1.5
    mode                    exclusive
</role>

<role reader>
    hosts                   db3
    ips                     192.168.1.10
    mode                    balanced
</role>      

2、分别配置DB1、DB2、DB3中的 /etc/mysql-mmm/mmm_agent.conf

DB1:

include mmm_common.conf
this db1      

DB2:

include mmm_common.conf
this db2      

DB3:

include mmm_common.conf
this db3      

3、配置monitor主機中的 /etc/mysql-mmm/mmm_mon.conf檔案:

include mmm_common.conf

<monitor>
    ip                      127.0.0.1
    pid_path                /var/run/mmmd_mon.pid
    bin_path                /usr/lib/mysql-mmm/
    status_path             /var/lib/misc/mmmd_mon.status
    ping_ips               192.168.1.238,192.168.1.239,192.168.1.13
</monitor>

<host default>
    monitor_user            mmm_monitor
    monitor_password        monitor_password
</host>

debug 0      

七、啟動MMM 

在DB1/DB2/DB3上執行: 

/etc/init.d/mysql-mmm-agent start

在monitor上執行 

/etc/init.d/mysql-mmm-monitor start

檢視狀态(monitor): 

mmm_control show 

mysql MMM詳解

檢視檢測狀态: 

mmm_control checks 

mysql MMM詳解

八、測試MMM 

停止238上的mysql并檢視是否會切換至239上。

相關文章: 

使用MySQL-MMM時遇到的一些問題​​http://sofar.blog.51cto.com/353572/1603111​​ 

MMM監控端啟動流程 ​​http://blog.itpub.net/26250550/viewspace-1094480/​​