【数据库】mysql架构之MMM,高可用同时实现读写分离

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: 文章目录前言一、mmm架构1.0 思路1.1 架构

一、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高可用搭建完毕
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
1月前
|
SQL NoSQL 前端开发
基于BS架构的饰品购物平台设计与实现(程序+文档+数据库)
基于BS架构的饰品购物平台设计与实现(程序+文档+数据库)
|
2月前
|
存储 监控 安全
360 企业安全浏览器基于阿里云数据库 SelectDB 版内核 Apache Doris 的数据架构升级实践
为了提供更好的日志数据服务,360 企业安全浏览器设计了统一运维管理平台,并引入 Apache Doris 替代了 Elasticsearch,实现日志检索与报表分析架构的统一,同时依赖 Doris 优异性能,聚合分析效率呈数量级提升、存储成本下降 60%....为日志数据的可视化和价值发挥提供了坚实的基础。
360 企业安全浏览器基于阿里云数据库 SelectDB 版内核 Apache Doris 的数据架构升级实践
|
2月前
|
监控 数据可视化 关系型数据库
微服务架构+Java+Spring Cloud +UniApp +MySql智慧工地系统源码
项目管理:项目名称、施工单位名称、项目地址、项目地址、总造价、总面积、施工准可证、开工日期、计划竣工日期、项目状态等。
304 6
|
21天前
|
canal 消息中间件 关系型数据库
【分布式技术专题】「分布式技术架构」MySQL数据同步到Elasticsearch之N种方案解析,实现高效数据同步
【分布式技术专题】「分布式技术架构」MySQL数据同步到Elasticsearch之N种方案解析,实现高效数据同步
66 0
|
1月前
|
关系型数据库 MySQL 数据库
使用 Docker 搭建一个“一主一从”的 MySQL 读写分离集群(超详细步骤
使用 Docker 搭建一个“一主一从”的 MySQL 读写分离集群(超详细步骤
59 0
|
1月前
|
SQL 存储 数据管理
数据库系统架构与DBMS功能探微:现代信息时代数据管理的关键
数据库系统架构与DBMS功能探微:现代信息时代数据管理的关键
35 1
|
1月前
|
架构师 算法 关系型数据库
数据库架构师之道:MySQL安装与系统整合指南
数据库架构师之道:MySQL安装与系统整合指南
44 0
|
2月前
|
存储 监控 关系型数据库
ELK架构监控MySQL慢日志
ELK架构监控MySQL慢日志
|
2月前
|
SQL 缓存 关系型数据库
从架构师角度全局理解Mysql性能优化
从架构师角度全局理解Mysql性能优化
|
2月前
|
缓存 负载均衡 监控
从零开始搭建一个高可用的后端架构
【2月更文挑战第6天】本文将介绍如何从零开始搭建一个高可用的后端架构,包括架构设计、技术选型、部署和监控等方面。通过对各种技术的分析和实践,帮助读者深入理解高可用架构的实现和优化。