mysql+amoeba+mysqlmmm高可用群集

來源:互聯網
上載者:User

標籤:admin   替換   log-bin   1.7   多個   factory   監控   mysql配置   epo   

一、MySQL-MMM(Master-Master replication manager fo MySQL)MMM概述
  • 雙主故障切換和日常管理的程式
  • 由多個mysql主伺服器和多個mysql從伺服器組成
  • MMM使用Perl語言開發,主要用來監控和管理MySQL Master-Master(雙主)複製
  • 其內部附加的工具指令碼也可以實現多個slave的read負載平衡。

註:

  • 同一時刻只允許一個主進行寫入,額外主提供部分讀的服務

  • 不適用於要求資料一致性很高的場合(可替換產品為:Heartbeat+DRBD+MySQL高可用方案)
MMM組成
  • mmm_mond:監控進程,負責所有的監控、決定和處理所有節點
  • mmm_agentd:運行在每個MySQL資料庫的代理進程,完成監控本地狀態並於監控端通訊
  • mmm_control:一個指令碼,提供mmm_mond進程的命令
二、案例

實驗環境:
六台Centos6,兩台主mysql(master01、master02),兩台從mysql(slave01、slave02),一台監控(mmm_mond),一台讀寫調度器(amoeba)

先部署主主(master01與master02)複製

Master01

1.準備工作
vim /etc/sysconfig/network-scripts/ifcfg-eth0    DEVICE=eth0    TYPE=Ethernet    ONBOOT=yes    NM_CONTROLLED=no    BOOTPROTO=static    IPADDR=192.168.1.10    NETMASK=255.255.255.0
vim /etc/sysconfig/network-scripts/ifcfg-eth1    DEVICE=eth1    TYPE=Ethernet    ONBOOT=yes    NM_CONTROLLED=no    BOOTPROTO=dhcp
vim /etc/hosts    192.168.1.10    db1    192.168.1.20    db2    192.168.1.30    db3    192.168.1.40    db4
vim /etc/sysconfig/network    HOSTNAME=db1
reboot
2.YUM源配置並安裝MMM
rm -rf /etc/yum.repos.d/*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
yum -y install epel-release
yum -y install mysql-mmm* mysql mysql-server mysql-devel
3.MySQL配置
/etc/init.d/mysqld start && chkconfig --level 35 mysqld on
mysqladmin -uroot password "123"
cp /usr/share/doc/mysql-server-5.1.73/my-medium.cnf /etc/my.cnf
vim /etc/my.cnf    [mysqld]    50 log-slave-updates
/etc/init.d/mysqld restart
4.授權並主主同步
mysql -u root -pmysql> grant replication slave on *.* to ‘slave‘@‘192.168.1.%‘ identified by ‘123‘;mysql> show master status;+------------------+----------+--------------+------------------+| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.000001 |      647 |              |                  |+------------------+----------+--------------+------------------+1 row in set (0.00 sec)mysql> change master to master_host=‘192.168.1.20‘,master_user=‘slave‘,master_password=‘123‘,master_log_file=‘mysql-bin.000001‘,master_log_pos=481;//所跟IP、log、pos等資訊都為第二台主的資訊mysql> start slave;mysql> show slave status\G;//查看同步狀態,I/0和SQL線程狀態為yes則正確

Master02

1.準備工作
vim /etc/sysconfig/network-scripts/ifcfg-eth0    DEVICE=eth0    TYPE=Ethernet    ONBOOT=yes    NM_CONTROLLED=no    BOOTPROTO=static    IPADDR=192.168.1.20    NETMASK=255.255.255.0
vim /etc/sysconfig/network-scripts/ifcfg-eth1    DEVICE=eth1    TYPE=Ethernet    ONBOOT=yes    NM_CONTROLLED=no    BOOTPROTO=dhcp
vim /etc/hosts    192.168.1.10    db1    192.168.1.20    db2    192.168.1.30    db3    192.168.1.40    db4
vim /etc/sysconfig/networkHOSTNAME=db2
reboot
2.YUM源配置並安裝MMM
rm -rf /etc/yum.repos.d/*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
yum -y install epel-release
yum -y install mysql-mmm* mysql mysql-server mysql-devel
3.MySQL配置
/etc/init.d/mysqld start && chkconfig --level 35 mysqld on
mysqladmin -uroot password "123"
cp /usr/share/doc/mysql-server-5.1.73/my-medium.cnf /etc/my.cnf
vim /etc/my.cnf    [mysqld]    50 log-slave-updates    58 server-id = 2
/etc/init.d/mysqld restart
4.授權並主主同步
mysql -u root -pmysql> grant replication slave on *.* to ‘slave‘@‘192.168.1.%‘ identified by ‘123‘;mysql> show master status;+------------------+----------+--------------+------------------+| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.000001 |      481 |              |                  |+------------------+----------+--------------+------------------+1 row in set (0.00 sec)mysql> change master to master_host=‘192.168.1.10‘,master_user=‘slave‘,master_password=‘123‘,master_log_file=‘mysql-bin.000001‘,master_log_pos=647;//所跟IP、log、pos等資訊都為第一台主的資訊mysql> start slave;mysql> show slave status\G;
再部署兩對主從複製(m1與s1,m2與s2)

Slave01

1.準備工作
vim /etc/sysconfig/network-scripts/ifcfg-eth0    DEVICE=eth0    TYPE=Ethernet    ONBOOT=yes    NM_CONTROLLED=no    BOOTPROTO=static    IPADDR=192.168.1.30    NETMASK=255.255.255.0
vim /etc/sysconfig/network-scripts/ifcfg-eth1    DEVICE=eth1    TYPE=Ethernet    ONBOOT=yes    NM_CONTROLLED=no    BOOTPROTO=dhcp
vim /etc/hosts    192.168.1.10    db1    192.168.1.20    db2    192.168.1.30    db3    192.168.1.40    db4
vim /etc/sysconfig/network    HOSTNAME=db3
reboot
2.YUM源配置並安裝MMM
rm -rf /etc/yum.repos.d/*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
yum -y install epel-release
yum -y install mysql-mmm* mysql mysql-server mysql-devel
3.MySQL配置
/etc/init.d/mysqld start && chkconfig --level 35 mysqld on
mysqladmin -uroot password "123"
cp /usr/share/doc/mysql-server-5.1.73/my-medium.cnf /etc/my.cnf
vim /etc/my.cnf    [mysqld]    50 relay-log=relay-log-bin    51 relay-log-index=slave-relay-bin.index    59 server-id = 3
/etc/init.d/mysqld restart
4.授權並主從同步(m1,s1)
mysql -u root -pmysql> change master to master_host=‘192.168.1.10‘,master_user=‘slave‘,master_password=‘123‘,master_log_file=‘mysql-bin.000001‘,master_log_pos=647;//所跟IP、log、pos等資訊都為第一台主的資訊mysql> start slave;mysql> show slave status\G;

Slave02

1.準備工作
vim /etc/sysconfig/network-scripts/ifcfg-eth0    DEVICE=eth0    TYPE=Ethernet    ONBOOT=yes    NM_CONTROLLED=no    BOOTPROTO=static    IPADDR=192.168.1.40    NETMASK=255.255.255.0
vim /etc/sysconfig/network-scripts/ifcfg-eth1    DEVICE=eth1    TYPE=Ethernet    ONBOOT=yes    NM_CONTROLLED=no    BOOTPROTO=dhcp
vim /etc/hosts    192.168.1.10    db1    192.168.1.20    db2    192.168.1.30    db3    192.168.1.40    db4
2.YUM源配置並安裝MMM
rm -rf /etc/yum.repos.d/*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
yum -y install epel-release
yum -y install mysql-mmm* mysql mysql-server mysql-devel
3.MySQL配置
/etc/init.d/mysqld start && chkconfig --level 35 mysqld on
mysqladmin -uroot password "123"
cp /usr/share/doc/mysql-server-5.1.73/my-medium.cnf /etc/my.cnf
vim /etc/my.cnf    [mysqld]    50 relay-log=relay-log-bin    51 relay-log-index=slave-relay-bin.index    59 server-id = 4
/etc/init.d/mysqld restart
4.授權並主從同步(m2,s2)
mysql -u root -pmysql> change master to master_host=‘192.168.1.20‘,master_user=‘slave‘,master_password=‘123‘,master_log_file=‘mysql-bin.000001‘,master_log_pos=647;//所跟IP、log、pos等資訊都為第二台主的資訊mysql> start slave;mysql> show slave status\G;
配置高可用MySQL-MMM

Master01

1.建立授權使用者
mysql> grant super,replication client,process on *.* to ‘mmm_agent‘@‘192.168.1.%‘ identified by ‘123‘;//主伺服器授權,從伺服器自動同步mysql> grant replication client on *.* to ‘mmm_monitor‘@‘192.168.1.%‘ identified by ‘123‘;           //主伺服器授權,從伺服器自動同步mysql> grant all on *.* to ‘test‘@‘192.168.1.%‘ identified by ‘123‘;                    //建立測試使用者
2.配置MMM_COMMON
vim /etc/mysql-mmm/mmm_common.conf    active_master_role      writer    <host default>            cluster_interface       eth0                    //叢集IP承載的介面            pid_path                /var/run/mysql-mmm/mmm_agentd.pid       //PID檔案位置(存放MMM的進程號)            bin_path                /usr/libexec/mysql-mmm/         //運行命令位置            replication_user        slave                   //需使用主從同步時授權使用者            replication_password    123            agent_user              mmm_agent                   //代理串連            agent_password          123    </host>    <host db1>            ip      192.168.1.10            mode    master            peer    db2                     //當db1主機不能使用,自動切換到db2    </host>    <host db2>            ip      192.168.1.20            mode    master                  //當前伺服器作為主伺服器(寫)            peer    db1                     //當db2主機不能使用,自動切換到db1    </host>    <host db3>            ip      192.168.1.30            mode    slave    </host>    <host db4>            ip      192.168.1.40            mode    slave                   //當前主機作為從伺服器(讀)    </host>    <role writer>            hosts   db1, db2            ips     192.168.1.250               //寫伺服器VIP            mode    exclusive                   //只有一個host可以writer    </role>    <role reader>            hosts   db3, db4            ips     192.168.1.251, 192.168.1.252        //讀伺服器VIP            mode    balanced                    //多個host可以reader    </role>
3.配置MMM_AGENT
vim /etc/mysql-mmm/mmm_agent.confinclude mmm_common.confthis db1
4.拷貝檔案給其餘主機
scp /etc/mysql-mmm/mmm_common.conf [email protected]:/etc/mysql-mmm/scp /etc/mysql-mmm/mmm_common.conf [email protected]:/etc/mysql-mmm/scp /etc/mysql-mmm/mmm_common.conf [email protected]:/etc/mysql-mmm/
/etc/init.d/mysql-mmm-agent restart && chkconfig --level 35 mysql-mmm-agent on

Master02

配置MMM_AGENT
vim /etc/mysql-mmm/mmm_agent.confthis db2
/etc/init.d/mysql-mmm-agent restart && chkconfig --level 35 mysql-mmm-agent on

Slave01

配置MMM_AGENT
vim /etc/mysql-mmm/mmm_agent.confthis db3
/etc/init.d/mysql-mmm-agent restart && chkconfig --level 35 mysql-mmm-agent on

Slave02

配置MMM_AGENT
vim /etc/mysql-mmm/mmm_agent.confthis db4
/etc/init.d/mysql-mmm-agent restart && chkconfig --level 35 mysql-mmm-agent on
監控配置(mmm_mon)1.準備工作
vim /etc/sysconfig/network-scripts/ifcfg-eth0    DEVICE=eth0    TYPE=Ethernet    ONBOOT=yes    NM_CONTROLLED=no    BOOTPROTO=static    IPADDR=192.168.1.50    NETMASK=255.255.255.0
vim /etc/sysconfig/network-scripts/ifcfg-eth1    DEVICE=eth1    TYPE=Ethernet    ONBOOT=yes    NM_CONTROLLED=no    BOOTPROTO=dhcp
vim /etc/hosts    192.168.1.10    db1    192.168.1.20    db2    192.168.1.30    db3    192.168.1.40    db4
reboot
2.YUM源配置並安裝MMM
rm -rf /etc/yum.repos.d/*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
yum -y install epel-release
yum -y install mysql-mmm* mysql
3.配置MMM_COMMON
scp 192.168.1.10:/etc/mysql-mmm/mmm_common.conf /etc/mysql-mmm/
4.配置MMM_MON
vim /etc/mysql-mmm/mmm_mon.conf    include mmm_common.conf    <monitor>            ip                  127.0.0.1            ping_ips            192.168.1.10,192.168.1.20,192.168.1.30,192.168.1.40    </monitor>    <host default>            monitor_user        mmm_monitor            monitor_password    123    </host>    debug 0
5.啟動服務並驗證
/etc/init.d/mysql-mmm-monitor restart && chkconfig --level 35 mysql-mmm-monitor on  //監控端啟動
mmm_control show                                    //查看節點狀態
mysql -u test -p -h 192.168.1.250

報錯解決方案:

[[email protected] ~]# mysql -u test -p -h 192.168.1.250Enter password:ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘192.168.1.254‘ (113)

主伺服器:

grant super,replication client,process on *.* to ‘mmm_agent‘@‘db1‘ identified by ‘123‘;grant super,replication client,process on *.* to ‘mmm_agent‘@‘db2‘ identified by ‘123‘;grant super,replication client,process on *.* to ‘mmm_agent‘@‘db3‘ identified by ‘123‘;grant super,replication client,process on *.* to ‘mmm_agent‘@‘db4‘ identified by ‘123‘;

日誌查看:

tail -f /var/log/mysql-mmm/mmm_agentd.log                       //MySQL端的Agent日誌
tail -f /var/log/mysql-mmm/mmm_mond.log                     //監控機端的Monitor日誌
部署讀寫調度器Amoeba1.環境準備
vim /etc/sysconfig/network-scripts/ifcfg-eth0    DEVICE=eth0    TYPE=Ethernet    ONBOOT=yes    NM_CONTROLLED=no    BOOTPROTO=static    IPADDR=192.168.1.254    NETMASK=255.255.255.0
2.安裝jdk與amoeba
yum -y erase java-*
chmod +x jdk-6u14-linux-x64.bin
./jdk-6u14-linux-x64.bin
mv jdk1.6.0_14/ /usr/local/jdk1.6
vim /etc/profileexport JAVA_HOME=/usr/local/jdk1.6export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/libexport PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/bin/:$PATH:$HOME/binexport AMOEBA_HOME=/usr/local/amoebaexport PATH=$PATH:$AMOEBA_HOME/bin
source /etc/profile && java -version
mkdir /usr/local/amoeba
tar zxvf amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba/
chmod -R 755 /usr/local/amoeba/
3.在主Mysql資料庫建立授權使用者
mysql -u root -p    mysql> grant all on *.* to [email protected]‘192.168.1.%‘ identified by ‘123‘;
4.編輯amoeba設定檔
vim /usr/local/amoeba/conf/amoeba.xml 30                <property name="user">hehe</property>            //設定串連Amoeba使用者 31 32                <property name="password">123</property>         //設定串連Amoeba使用者115                 <property name="defaultPool">slaves</property>116117                 <property name="writePool">master</property>        注意刪除<!--  -->的注釋118                 <property name="readPool">slaves</property>         //定義讀伺服器集區
vim /usr/local/amoeba/conf/dbServers.xml 25                         <!-- mysql user --> 26                         <property name="user">haha</property>               //設定串連Mysql的使用者 27 28                         <property name="password">123</property>                //設定串連mysql的密碼注意刪除<!--  -->的注釋 43         <dbServer name="master"  parent="abstractServer"> 44                 <factoryConfig> 45                         <!-- mysql ip --> 46                         <property name="ipAddress">192.168.1.254</property>         //定義寫伺服器IP 47                 </factoryConfig> 48         </dbServer> 49         <dbServer name="slave1"  parent="abstractServer"> 50                 <factoryConfig> 51                         <!-- mysql ip --> 52                         <property name="ipAddress">192.168.1.30</property>          //定義讀伺服器IP 53                 </factoryConfig> 54         </dbServer> 55         <dbServer name="slave2"  parent="abstractServer"> 56                 <factoryConfig> 57                         <!-- mysql ip --> 58                         <property name="ipAddress">192.168.1.40</property>          //定義讀伺服器IP 59                 </factoryConfig> 60 61         </dbServer> 62         <dbServer name="slaves" virtual="true"> 68                         <property name="poolNames">slave1,slave2</property>     //定義輸入slaves讀伺服器集區的主機 69                 </poolConfig>
amoeba start &
netstat -utpln | grep 8066
5.串連測試
client:mysql -u hehe -p -h 192.168.1.254 -P 8066

mysql+amoeba+mysqlmmm高可用群集

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.