当前位置:网站首页>Mysql集群 ShardingSphere
Mysql集群 ShardingSphere
2022-08-09 22:08:00 【努力学习,努力爱你!】
集群原理

MySQL-MMM 是 Master-Master Replication Manager for MySQL(mysql 主主复制管理器)的简称,是 Google 的开源项目(Perl 脚本)。MMM 基于 MySQLReplication 做的扩展架构,主要用来监控 mysql 主主复制并做失败转移。其原理是将真实数据库节点的IP(RIP)映射为虚拟 IP(VIP)集。mysql-mmm 的监管端会提供多个虚拟 IP(VIP),包括一个可写 VIP,多个可读 VIP,通过监管的管理,这些 IP 会绑定在可用 mysql 之上,当某一台 mysql 宕机时,监管会将 VIP迁移至其他 mysql。在整个监管过程中,需要在 mysql 中添加相关授权用户,以便让 mysql 可以支持监理机的维护。授权的用户包括一个mmm_monitor 用户和一个 mmm_agent 用户,如果想使用 mmm 的备份工具则还要添加一个 mmm_tools 用户。

MHA(Master High Availability)目前在 MySQL 高可用方面是一个相对成熟的解决方案, 由日本 DeNA公司 youshimaton(现就职于 Facebook 公司)开发,是一套优秀的作为MySQL高可用性环境下故障切换和主从提升的高可用软件。在MySQL故障切换过程中,MHA 能做到在 0~30 秒之内自动完成数据库的故障切换操作(以 2019 年的眼光来说太慢了),并且在进行故障切换的过程中,MHA 能在最大程度上保证数据的一致性,以达到真正意义上的高可用。
InnoDB Cluster 支持自动 Failover、强一致性、读写分离、读库高可用、读请求负载均衡,横向扩展的特性,是比较完备的一套方案。但是部署起来复杂,想要解决 router单点问题好需要新增组件,如没有其他更好的方案可考虑该方案。 InnoDB Cluster 主要由 MySQL Shell、MySQL Router 和 MySQL 服务器集群组成,三者协同工作,共同为MySQL 提供完整的高可用性解决方案。MySQL Shell 对管理人员提供管理接口,可以很方便的对集群进行配置和管理,MySQL Router 可以根据部署的集群状况自动的初始化,是客户端连接实例。如果有节点 down 机,集群会自动更新配置。集群包含单点写入和多点写入两种模式。在单主模式下,如果主节点 down 掉,从节点自动替换上来,MySQL Router 会自动探测,并将客户端连接到新节点。

主从同步
参考博客 https://blog.csdn.net/weixin_45247019/article/details/125497374
MyCat或者ShardingSphere 分库分表
官网链接 http://shardingsphere.apache.org/index_zh.html
下载
#镜像方式
docker pull apache/sharding-proxy
docker run -d -v /mydata/sharding-proxy/conf:/opt/sharding-proxy/conf -v
/mydata/sharding-proxy/lib:/opt/sharding-proxy/lib --env PORT=3308 -p13308:3308
apache/sharding-proxy:latest
#压缩包下载
https://shardingsphere.apache.org/document/current/cn/downloads/
配置server.yaml
server.yaml 文件
authentication:
users:
root:
password: root
sharding:
password: sharding
authorizedSchemas: sharding_db
配置数据分片+读写分离
config-mallshard.yaml
schemaName: sharding_db
dataSources:
ds0:
url: jdbc:mysql://192.168.56.10:3307/ds0
username: root
password: root
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 65
ds0_slave0:
url: jdbc:mysql://192.168.56.10:3317/ds0
username: root
password: root
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 65
ds1:
url: jdbc:mysql://192.168.56.10:3307/ds1
username: root
password: root
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 65
ds1_slave0:
url: jdbc:mysql://192.168.56.10:3317/ds1
username: root
password: root
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 65
shardingRule:
tables:
t_order:
actualDataNodes: ds${0..1}.t_order${0..1}
databaseStrategy:
inline:
shardingColumn: user_id
algorithmExpression: ds${user_id % 2}
tableStrategy:
inline:
shardingColumn: order_id
algorithmExpression: t_order${order_id % 2}
keyGenerator:
type: SNOWFLAKE
column: order_id
t_order_item:
actualDataNodes: ds${0..1}.t_order_item${0..1}
databaseStrategy:
inline:
shardingColumn: user_id
algorithmExpression: ds${user_id % 2}
tableStrategy:
inline:
shardingColumn: order_id
algorithmExpression: t_order_item${order_id % 2}
keyGenerator:
type: SNOWFLAKE
column: order_item_id
bindingTables: - t_order,t_order_item
broadcastTables: - t_config
defaultDataSourceName: ds0
defaultTableStrategy:
none:
masterSlaveRules:
ms_ds0:
masterDataSourceName: ds0
slaveDataSourceNames: - ds0_slave0
loadBalanceAlgorithmType: ROUND_ROBIN
ms_ds1:
masterDataSourceName: ds1
slaveDataSourceNames: - ds1_slave0
loadBalanceAlgorithmType: ROUND_ROBIN
创建表测试
#创建测试表
CREATE TABLE `t_order` (
`order_id` bigint(20) NOT NULL, `user_id` int(11) NOT NULL, `status` varchar(50) COLLATE utf8_bin DEFAULT NULL, PRIMARY KEY (`order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE TABLE `t_order_item` (
`order_item_id` bigint(20) NOT NULL, `order_id` bigint(20) NOT NULL, `user_id` int(11) NOT NULL, `content` varchar(255) COLLATE utf8_bin DEFAULT NULL, `status` varchar(50) COLLATE utf8_bin DEFAULT NULL, PRIMARY KEY (`order_item_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
作者声明
如有问题,欢迎指正!
边栏推荐
- R语言ggplot2可视化:使用ggplot2可视化散点图、使用labs参数自定义Y轴的轴标签文本(customize Y axis labels)
- 【微信小程序开发(八)】音频背景音乐播放问题汇总
- C. Omkar and Baseball
- mysql 、pg 查询日期处理
- C 在函数声明前加typedef
- 第 1 章 一大波数正在靠近——排序
- Install win7 virtual machine in Vmware and related simple knowledge
- JS中表单操作、addEventListener事件监听器
- 请讲一讲JS中的 for...in 与 for...of (上)
- What kind of mentality do you need to have when using the stock quantitative trading interface
猜你喜欢

xctf攻防世界 Web高手进阶区 shrine

EasyExcel使用

Tencent continues to wield the "big knife" to reduce costs and increase efficiency, and free catering benefits for outsourced employees have been cut

JS中表单操作、addEventListener事件监听器

【技术分享】SLA(服务等级协议)原理与配置

shell array

leetcode brush questions diary Calculate the number of elements on the right that is less than the current element

leetcode:286.墙和门

shell数组

Js fifteen interview questions (with answers)
随机推荐
重装系统后新建文本文档打不开怎么办
xctf攻防世界 Web高手进阶区 shrine
chart.js面积图曲线图统计插件
都在说云原生,那云原生到底是什么?
Presto Event Listener开发
xctf攻防世界 Web高手进阶区 ics-05
信息系统项目管理师---第十一章项目风险管理历年考题
leetcode:332. 重新安排行程
Jinshanyun earthquake, the epicenter is in bytes?
毕昇编译器优化:Lazy Code Motion
Common commands and technical function modules of Metasploit
HUAWEI CLOUD escorts the whole process of "Wandering Ark" for the first time, creating a popular brand
Qt 消息机制和事件
three.js镂空圆球拖拽变形js特效
【技术分享】SLA(服务等级协议)原理与配置
【面试高频题】可逐步优化的链表高频题
注意力引导网络用于视网膜图像分割
电脑系统重装后怎么用打印机扫描出文件?
JuiceFS 在多云存储架构中的应用 | 深势科技分享
shell array