使用MySQL-MMM實現MySQL叢集部署

來源:互聯網
上載者:User

使用MySQL-MMM實現MySQL叢集部署

背景:之前實現的mysql同步複製功能(見筆者之前文章 )只是雙機熱備功能,還不能做到Mysql連結的自動切換。

本配置實現真正的mysql叢集,使得在某台機子的mysql應用停止時,能讓應用程式自動切換到另外一台機子的mysql串連,實現應用的高穩定性,並且使得擴充Mysql服務成為可能。

本配置使用mysql-mmm(master-master Replication Manager for MySQL)組件實現叢集功能。

本次示範的配置使用三台機器,架構如下:

Master1 和Master2兩台機器實現雙機熱備,其中一台機器的mysql服務停止或機器宕機,應用程式都會將資料庫連接自動切換到另外一台機子。另外用一台機子即時備份master1的資料。

--------------------------------------分割線 --------------------------------------

MySQL-MMM實現MySQL高可用

MySQL-MMM切換示範

mysql proxy、MySQL-MMM實現讀寫分離高可用性

將MySQL-MMM Master從REPLICATION_FAIL狀態恢複

CentOS下利用MySQL-MMM實現MySQL高可用

--------------------------------------分割線 --------------------------------------

1、安裝mysql-mmm服務

在三台機器都安裝

wget http://dl.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

rpm -ivh epel-release-6-8.noarch.rpm

yum -y install mysql-mmm*

完成後查看  rpm -qa|grep mysql-mmm

有以下組件表示安裝成功

Rhel5或centos5,32位:http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm

Rhel6或centos6,32位:http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm

Rhel6或centos6,64位:http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

1、添加mysql的使用者

在三台機器都添加mysql使用者,分別用於複製、

進入mysql服務mysql -u root -p

use mysql;

grant REPLICATION slave,REPLICATION CLIENT on *.* to 'repl'@'%' identified by 'password';  //建立複製使用者

grant PROCESS,SUPER,REPLICATION CLIENT on *.* to 'mmm_agent'@'%' identified by 'password'; //建立agent使用者

grant REPLICATION CLIENT on *.* to 'mmm_monitor'@'%' identified by 'password';  //建立使用者

FLUSH PRIVILEGES;

2、配置同步複製

配置複製的策略如架構圖所示。

配置方法在我上一篇文章有介紹過,這裡不再重複,見筆者之前文章

3、修改hosts

分別修改三台機器的hosts檔案

vi /etc/hosts

添加

200.200.168.24 M1

200.200.168.25 M2

200.200.168.23 slave1

4、配置mysql-mmm

修改 /etc/mysql-mmm/mmm_common.conf  各台機子的配置都一樣

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    password
    agent_user              mmm_agent
    agent_password          <span style="font-size: 13.3333339691162px;">password</span>
</host>

<host M1>
    ip      200.200.168.24
    mode    master
    peer    M2
</host>

<host M2>
    ip      200.200.168.25
    mode    master
    peer    M1
</host>

<host slave1>
    ip      200.200.168.23
    mode    slave
</host>

<role writer>
    hosts  M1,M2
    ips    200.200.168.26
    mode    exclusive
</role>

<role reader>
    hosts  M1,M2,slave1
    ips    200.200.168.27
    mode    balanced
</role>

注意:200.200.168.26和200.200.168.27是兩個虛擬IP地址,供應用程式調用,只需用兩個沒人佔用的IP就可以,分別用來提供寫和讀服務,為以後實現資料庫的讀寫分離(但實現讀寫分離需要修改應用程式,mysql並不能自動識別並切換)。

修改/etc/mysql-mmm/mmm_agent.conf

三台機器分別設定為this M1、this M2、this slave1

修改/etc/mysql-mmm/mmm_mon.conf

只是monitor(200.200.168.24)機子需要配置

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            200.200.168.24,200.200.168.25,200.200.168.23
    auto_set_online    10

    # The kill_host_bin does not exist by default, though the monitor will
    # throw a warning about it missing.  See the section 5.10 "Kill Host
    # Functionality" in the PDF documentation.
    #
    # kill_host_bin    /usr/libexec/mysql-mmm/monitor/kill_host
    #
</monitor>
<host default>
    monitor_user        mmm_monitor
    monitor_password    password
</host>
debug 0

配置完成後運行

三台機子都需運行:

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

Monitor機子運行

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

更多詳情見請繼續閱讀下一頁的精彩內容:

  • 1
  • 2
  • 下一頁

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.