一、mmm架构
1.0 思路
- 主从复制:先安装数据库–>主服务器授权,刷新授权–>从节点同步配置(需先获得主的文件名及偏移量)
- 注:两个主需要互相做主从,为了故障转换之后数据能继续同步
1.1 架构
作用 | IP地址 | 安装服务 |
主负载均衡器 | 192.168.13.10 | mmm/mysql5.7 |
备负载均衡器 | 192.168.13.20 | mmm/mysql5.7 |
节点服务器1 | 192.168.13.30 | mmm/mysql5.7 |
节点服务器2 | 192.168.13.40 | mmm/mysql5.7 |
monitor监控节点 | 192.168.13.50 | mmm |
1.2 主负载均衡
systemctl stop firewalld setenforce 0 vim /etc/my.cnf server-id = 1 log-error=/usr/local/mysql/data/mysql_error.log general_log=ON general_log_file=/usr/local/mysql/data/mysql_general.log slow_query_log=ON slow_query_log_file=mysql_slow_query.log long_query_time=5 binlog-ignore-db=mysql,information_schema log_bin=mysql_bin log_slave_updates=true sync_binlog=1 innodb_flush_log_at_trx_commit=1 auto_increment_increment=2 auto_increment_offset=1 scp /etc/my.cnf root@192.168.13.20:/etc/ scp /etc/my.cnf root@192.168.13.30:/etc/ scp /etc/my.cnf root@192.168.13.40:/etc/ systemctl restart mysqld mysql -uroot -pabc123 grant replication slave on *.* to 'replication'@'192.168.13.%' identified by '123456'; show master status; #此处获得二进制日志文件名及偏移量,其他服务器配置主从复制时候需要 grant super, replication client, process on *.* to 'mmm_agent'@'192.168.13.%' identified by '123456'; grant replication client on *.* to 'mmm_monitor'@'192.168.13.%' identified by '123456'; flush privileges; #为monitor服务器授权 change master to master_host='192.168.13.20',master_user='replication',master_password='123456',master_log_file='mysql_bin.000001',master_log_pos=460; #此时的二进制文件名与偏移量是从master2获得的,原因:当故障转移后,能够和新主保持主从复制(可以先不执行这一步,等操作完master2再回来授权) show slave status\G #查看主从同步是够配置成功 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo yum -y install epel-release yum -y install mysql-mmm* cd /etc/mysql-mmm/ vim mmm_common.conf 4行:cluster_interface ens33 8行:replication_password 123456 10行:agent_password 123456 14行:ip 192.168.13.10 20行:ip 192.168.13.20 26行:ip 192.168.13.30 24-28行复制:24,,28 co 28 31行:ip 192.168.13.40 35行:hosts db1, db2 37行:ips 192.168.13.188 41行:hosts db3, db4 43行:ips 192.168.13.198, 192.168.13.199 scp mmm_common.conf root@192.168.13.20:/etc/mysql-mmm/ scp mmm_common.conf root@192.168.13.30:/etc/mysql-mmm/ scp mmm_common.conf root@192.168.13.40:/etc/mysql-mmm/ scp mmm_common.conf root@192.168.13.50:/etc/mysql-mmm/ systemctl start mysql-mmm-agent.service systemctl enable mysql-mmm-agent.service
1.3 备负载均衡器
systemctl stop firewalld setenforce 0 vim /etc/my.cnf server-id = 2 systemctl restart mysqld.service mysql -u root -pabc123 grant replication slave on *.* to 'replication'@'192.168.13.%' identified by '123456'; show master status; #此处获得二进制日志文件名及偏移量,为了给master1使用 change master to master_host='192.168.13.20',master_user='replication',master_password='123456',master_log_file='mysql_bin.000001',master_log_pos=460; #此时的二进制文件名与偏移量是从master1获得的,原因:为了保持数据一致性,随时可以进行故障转移 grant super, replication client, process on *.* to 'mmm_agent'@'192.168.13.%' identified by '123456'; grant replication client on *.* to 'mmm_monitor'@'192.168.13.%' identified by '123456'; flush privileges; #为monitor服务器授权 show slave status\G #查看主从同步是够配置成功 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo yum -y install epel-release yum -y install mysql-mmm* vim /etc/mysql-mmm/mmm_agent.conf 6行:this db2 systemctl start mysql-mmm-agent.service systemctl enable mysql-mmm-agent.service
1.4 从服务器
systemctl stop firewalld setenforce 0 vim /etc/my.cnf server-id = 3 systemctl restart mysqld.service mysql -u root -pabc123 change master to master_host='192.168.13.10',master_user='replication',master_password='123456',master_log_file='mysql_bin.000001',master_log_pos=460; #与master1保持主从复制 grant super, replication client, process on *.* to 'mmm_agent'@'192.168.13.%' identified by '123456'; grant replication client on *.* to 'mmm_monitor'@'192.168.13.%' identified by '123456'; flush privileges; #为monitor服务器授权 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo yum -y install epel-release yum -y install mysql-mmm* vim /etc/mysql-mmm/mmm_agent.conf 6行:this db3 systemctl start mysql-mmm-agent.service systemctl enable mysql-mmm-agent.service #另外一台从服务器重复此操作,server-id = 4,6行:this db4。修改这两项即可
1.5 monitor服务器
systemctl stop firewalld 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 -y install mysql-mmm* vim /etc/mysql-mmm/mmm_mon.conf 8行:ping_ips 192.168.13.10,192.168.13.20,192.168.13.30,192.168.13.40 9行:auto_set_online 10 20行:monitor_user mmm_monitor 21行:onitor_password 123456 systemctl restart mysql-mmm-monitor.service mmm_control show #检查各节点的情况,正确显示如下 db1(192.168.13.10) master/ONLINE. Roles: writer(192.168.13.188) db2(192.168.13.20) master/ONLINE. Roles: db3(192.168.13.30) slave/ONLINE. Roles: reader(192.168.13.198) db4(192.168.13.40) slave/ONLINE. Roles: reader(192.168.13.199) #mmm高可用搭建完毕