MySQL中mmm實現高可用群集

來源:互聯網
上載者:User

標籤:get   mysq   character   51cto   iad   ext   許可權   程式   log   

  • 介紹

    MMM(Master-Master replication manager for MySQL)是一套支援雙主故障切換和雙主日常管理的指令碼程式。MMM使用Perl語言開發,主要用來監控和管理MySQL Master-Master(雙主)複製,可以說是mysql主主複製管理器。雖然叫做雙主複製,但是業務上同一時刻只允許對一個主進行寫入,另一台備選主上提供部分讀服務,以加速在主主切換時刻備選主的預熱,可以說MMM這套指令碼程式一方面實現了故障切換的功能,另一方面其內部附加的工具指令碼也可以實現多個slave的負載平衡。

  • 優點

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

    • 缺點

    Monitor節點是單點,可以結合Keepalived實現高可用。

  • 實驗要求

    兩台主伺服器master

    master1:192.168.177.128

    master2:192.168.177.135

    兩台從伺服器slave

    slave1:192.168.177.132

    slave2:192.168.177.133

    監控伺服器monitor

    monitor:192.168.177.134

  • 配置ALI雲源,然後安裝epel-release源(四台主從)
    # wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo# yum -y install epel-release# yum clean all && yum makecache
    搭建本地YUM源(四台主從)
    # yum -y install mariadb-server mariadb# systemctl stop firewalld.service # setenforce 0# systemctl start mariadb.service
    修改m1主設定檔
    # vim /etc/my.cnf //刪掉原來的[mysqld]9行,添加如下內容:[mysqld]    log_error=/var/lib/mysql/mysql.errlog=/var/lib/mysql/mysql_log.loglog_slow_queries=/var/lib/mysql_slow_queris.logbinlog-ignore-db=mysql,information_schemacharacter_set_server=utf8log_bin=mysql_binserver_id=1log_slave_updates=truesync_binlog=1auto_increment_increment=2auto_increment_offset=1==注意==server_id要不同# systemctl restart mariadb.service




    配置主主複製-兩台主伺服器相互複製
    # mysql># show master status; //記錄記錄檔名稱和位置值,在兩台主上查看在m1上為m2授予從的許可權,在m2上也要為m1授予從的許可權# grant replication slave on *.* to ‘replication‘@‘192.168.177.%‘ identified by ‘123456‘; //m1上# grant replication slave on *.* to ‘replication‘@‘192.168.177.%‘ identified by ‘123456‘;//m2上#change master to master_host=‘192.168.177.135‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000001‘,master_log_pos=245;//m1上# change master to master_host=‘192.168.177.128‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000001‘,master_log_pos=245;//m2上# start slave;# show slave status\G;

    在兩台從上做-注意記錄檔和位置參數的改變(都指向m1)
    # change master to master_host=‘192.168.177.128‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000001‘,master_log_pos=245;# start slave; //開啟同步# show slave status\G;

    安裝MMM(四台主從)
    # yum -y install mysql-mmm*安裝結束後,對mmm進行配置# cd /etc/mysql-mmm/#vim mmm_common.conf //所有主機上都要配置,直接複製多份<host default>    cluster_interface       ens33    ……    replication_user        replication    replication_password    123456    agent_user              mmm_agent    agent_password          123456 <host db1>    ip      192.168.177.128    mode    master    peer    db2</host><host db2>    ip      192.168.177.135    mode    master    peer    db1</host><host db3>    ip      192.168.177.132    mode    slave</host><host db4>    ip      192.168.177.133    mode    slave</host><role writer>    hosts   db1, db2    ips     192.168.177.200    #主伺服器虛擬IP    mode    exclusive</role><role reader>    hosts   db3, db4    ips     192.168.177.20,192.168.177.30   #從伺服器虛擬IP    mode    balanced</role>在主1上面複製:# scp mmm_common.conf [email protected]:/etc/mysql-mmm/# scp mmm_common.conf [email protected]:/etc/mysql-mmm/# scp mmm_common.conf [email protected]:/etc/mysql-mmm/



    在monitor伺服器上配置
    # systemctl stop firewalld.service# setenforce 0# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo# yum -y install epel-release# yum clean all && yum makecache# yum -y install mysql-mmm*# cd /etc/mysql-mmm# vim mmm_mon.conf<host default>    ping_ips            192.168.177.132,192.168.177.128,192.168.177.133,192.168.177.135 //四台地址    monitor_user        mmm_monitor    monitor_password    123456    auto_set_online     10</host>在m1上:# scp mmm_common.conf [email protected]:/etc/mysql-mmm/
    在所有資料庫上為mmm_agent授權-四台主從
    # mysql># grant super, replication client, process on *.* to ‘mmm_agent‘@‘192.168.177.%‘ identified by ‘123456‘;
    在所有資料庫上為mmm_moniter授權-四台主從
    # grant replication client on *.* to ‘mmm_monitor‘@‘192.168.177.%‘ identified by ‘123456‘;# flush privileges;
    修改所有資料庫的mmm_agent.conf-四台主從
    # vim /etc/mysql-mmm/mmm_agent.confthis db1 //根據規划進行逐一調整this db2this db3this db4
    在所有資料庫伺服器上啟動mysql-mmm-agent-四台主從
    # systemctl start mysql-mmm-agent.service# systemctl enable mysql-mmm-agent.service   #開機自啟動
    在monitor伺服器上配置
    # systemctl start mysql-mmm-monitor.service # mmm_control show# mmm_control checks all# mmm_control move_role writer db2    //指定db2綁定虛擬IP



    故障測試
    停止m1 確認 虛擬位址 200 是否移動到 m2 上。注意:主不會搶佔# systemctl stop mariadb.service //m1上# mmm_control show   db1(192.168.177.128) master/HARD_OFFLINE. Roles:  db2(192.168.177.135) master/ONLINE. Roles: writer(192.168.177.200)


    MySQL中mmm實現高可用群集

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.