配置方案


    主机         地址              角色       虚拟IP    

     db2       172.16.24.7        master      172.16.24.77

     db3       172.16.24.8        master      172.16.24.88

     db4       172.16.24.9        slave       172.16.24.99

     db1       172.16.24.6         MMM

(注:四台主机都要装上mysql)

一、配置mysql主主复制

1)编辑配置文件(主机172.16.24.7)

[root@localhost ~]# vim /etc/my.cnf

mysql_MMM服务器的搭建_第1张图片

wKioL1NjYXmDL58aAACKAqRPaDc316.jpg

2)编辑配置文件(172.16.24.8)

[root@localhost ~]# vim /etc/my.cnf

mysql_MMM服务器的搭建_第2张图片

wKioL1NjYezRWOCYAACAMy8fMpY491.jpg

3)编辑配置文件(172.16.24.9)

server-id       = 3

log-bin=mysql-bin

log-slave-updates

4)编辑配置文件(172.16.24.6)

server-id       = 4

log-bin=mysql-bin

log-slave-updates

5)、创建具有复制权限的mysql用户(172.16.24.7、172.16.24.8)

server1 (172.16.24.7)

mysql> grant replication slave on *.* to 'myuser'@'172.16.24.8' identified by 'mypass';

mysql> grant replication slave on *.* to 'myuser'@'172.16.24.9' identified by 'mypass';

mysql> flush privileges;

server2(172.16.24.8)

mysql> grant replication slave on *.* to 'myuser'@'172.16.24.7' identified by 'mypass';

mysql> grant replication slave on *.* to 'myuser'@'172.16.24.9' identified by 'mypass';

mysql> flush privileges;




二、主主复制数据(172.16.24.7、172.16.24.8)

1)同步数据(db3同步db2的数据)

server1:(172.16.24.7)

mysql> show master status;

+------------------+----------+--------------+------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+------------------+----------+--------------+------------------+

| mysql-bin.000003 |      346 |              |                  |

+------------------+----------+--------------+------------------+

1 row in set (0.00 sec)

server2:(172.16.24.8)

mysql> change master to MASTER_HOST='172.16.24.7',MASTER_USER='myuser',MASTER_PASSWORD='mypass',MASTER_LOG_FILE='mysql-bin.000003',MASTER_LOG_POS=346;


mysql> start slave;

Query OK, 0 rows affected (0.01 sec)


mysql> show slave status\G

*************************** 1. row ***************************

              Slave_IO_State: Waiting for master to send event

                 Master_Host: 172.16.24.7

                 Master_User: myuser

                 Master_Port: 3306

               Connect_Retry: 60

             Master_Log_File: mysql-bin.000003

         Read_Master_Log_Pos: 346

              Relay_Log_File: localhost-relay-bin.000002

               Relay_Log_Pos: 253

       Relay_Master_Log_File: mysql-bin.000003

            Slave_IO_Running: Yes

           Slave_SQL_Running: Yes

2)同步数据(db2同步db3的数据)

server2:(172.16.24.8)

mysql> show master status;

+------------------+----------+--------------+------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+------------------+----------+--------------+------------------+

| mysql-bin.000003 |      505 |              |                  |

+------------------+----------+--------------+------------------+

1 row in set (0.00 sec)

server1:(172.16.24.7)

mysql> change master to MASTER_HOST='172.16.24.8',MASTER_USER='myuser',MASTER_PASSWORD='mypass',MASTER_LOG_FILE='mysql-bin.000003',MASTER_LOG_POS=505;

Query OK, 0 rows affected (0.08 sec)


mysql> start slave;

Query OK, 0 rows affected (0.00 sec)


mysql> show slave status\G

*************************** 1. row ***************************

              Slave_IO_State: Waiting for master to send event

                 Master_Host: 172.16.24.8

                 Master_User: myuser

                 Master_Port: 3306

               Connect_Retry: 60

             Master_Log_File: mysql-bin.000003

         Read_Master_Log_Pos: 505

              Relay_Log_File: localhost-relay-bin.000002

               Relay_Log_Pos: 253

       Relay_Master_Log_File: mysql-bin.000003

            Slave_IO_Running: Yes

           Slave_SQL_Running: Yes

             Replicate_Do_DB:

         Replicate_Ignore_DB:

三、安装mysql-mmm及配

1)安装mysql-mmm(四个主要都要安装)

[root@localhost ~]# yum install mysql-mmm*

wKioL1NkVlWh1JAYAACG7WVk9xU730.jpg

2)修改配置文件(172.16.24.6)

[root@localhost ~]# vim /etc/mysql-mmm/mmm_common.conf  

   cluster_interface       eth0

   pid_path                /var/run/mysql-mmm/mmm_agentd.pid

   bin_path                /usr/libexec/mysql-mmm/

   replication_user        slave

   replication_password    slave

   agent_user              mmm_agent

   agent_password          mmm_agent


   ip      172.16.24.7

   mode    master

   peer    db3


   ip      172.16.24.8

   mode    master

   peer    db2


   ip      172.16.24.9

   mode    slave

   hosts   db2, db3

   ips     172.16.24.77

   mode    exclusive


   hosts   db2,db3,db4

   ips     172.16.24.77,172.16.24.88,172.16.24.99

   mode    balanced


3)发送到其它3台主机

[root@localhost mysql-mmm]# scp mmm_common.conf 172.16.24.7:/etc/mysql-mmm/  

[root@localhost mysql-mmm]# scp mmm_common.conf 172.16.24.8:/etc/mysql-mmm/

[root@localhost mysql-mmm]# scp mmm_common.conf 172.16.24.9:/etc/mysql-mmm/

4)添加agentd使用的mysql用户,db2,db3,db4都要添加

mysql>grant super,replication client,process on *.* to 'mmm_agent'@'172.16.24.6' identified by 'mmm_agent';

mysql>grant super,replication client,process on *.* to 'mmm_agent'@'172.16.24.7' identified by 'mmm_agent';

mysql>grant super,replication client,process on *.* to 'mmm_agent'@'172.16.24.8' identified by 'mmm_agent';

mysql>grant super,replication client,process on *.* to 'mmm_agent'@'172.16.24.9' identified by 'mmm_agent';

5)修改的/etc/mysql-mmm/mmm_agent.conf 配置文件(四台主机都要改,要跟你的主机名对上)

db2:(172.16.24.7)

[root@localhost ~]# cat /etc/mysql-mmm/mmm_agent.conf

include mmm_common.conf


# The 'this' variable refers to this server.  Proper operation requires

# that 'this' server (db1 by default), as well as all other servers, have the

# proper IP addresses set in mmm_common.conf.

this db2

db3:(172.16.24.8)

include mmm_common.conf


# The 'this' variable refers to this server.  Proper operation requires

# that 'this' server (db1 by default), as well as all other servers, have the

# proper IP addresses set in mmm_common.conf.

this db3

其它略…………………

6)启动mysql-mmm-agent(172.16.24.7,172.16.24.8,172.16.24.9)

[root@localhost ~]# /etc/init.d/mysql-mmm-agent start

Starting MMM Agent Daemon:                                 [  OK  ]

7)启动mysql-mmm-monitor(172.16.24.6)

[root@localhost ~]# /etc/init.d/mysql-mmm-monitor start

Starting MMM Monitor Daemon:                               [  OK  ]

到此配置结束