欢迎来到Introzo百科
Introzo百科
ShardingSphere-Proxy 子库和表
安装ShardingSphere-Proxy
中间件封装
定位为透明的数据库代理
,提供封装数据库二进制协议的服务器版本,支持异构语言。目前 MySQL 和 PostgreSQL 版本可用。可以使用任何兼容MySQL/PostgreSQL协议的访问客户端(如MySQL Command Client、MySQL Workbench、Navicat等)来操作数据,对DBA更加友好。
5.1.1 安装:
https://www.introzo.com/document/5.1.1/cn/user-manual/shardingsphere-proxy/startup/bin/)https://www.introzo.com/dist/shardingsphere/
下载jar包后,上传到/usr/local文件并解压
tar -zxvf apache-shardingsphere-5.1.1-shardingsphere-proxy-bin.tar.gz
新建ext-lib
目录
cd /usr/local/apache-shardingsphere-5.1.1-shardingsphere-proxy-binmkdir ext-lib
然后将MySQL驱动mysql-connector-java-8.0.22.jar
放入ext-lib
目录
修改配置文件
cd /usr/local/apache-shardingsphere-5.1.1-shardingsphere-proxy-bin/confvim server.yaml
左侧如下配置表示任何服务器都可以root用户登录,并拥有所有权限
规则:- !AUTHORITY用户:- root@%:rootprovider:type: ALL_PRIVILEGES_PERMITTED
# 打印sql
道具:sql-show:true
开始:
/usr/local/apache-shardingsphere-5.1.1-shardingsphere-proxy-bin/bin/www.introzo.com 3306 也可以指定端口号和配置文件目录:`bin/start.bat ${proxy_port} ${ proxy_conf_directory}`,如果不指定,则为3307端口
停止:
/usr/local/apache-shardingsphere-5.1.1-shardingsphere-proxy-bin/bin/www.introzo.com
检查启动状态
ps -ef|grep 分片球|grep -v grep
开放端口:
firewall-cmd --zone=public --add-port=3306/tcp --permanent
重新启动防火墙:
firewall-cmd --reload #restart
防火墙 systemctl stop firewalld.service #Stopfirewall systemctl disablefirewalld.service #禁用防火墙启动
远程连接
mysql -h192.168.158.166 -p3306 -uroot -p
连接成功
也可用于视觉工具连接和正常使用mysql没有什么区别
配置读写分离
/conf目录下
有以下配置文件
修改配置文件config-read write -splitting.yaml
cd /usr/local/apache-shardingsphere-5.1.1-shardingsphere-proxy-bin/confvim config-readwrite-splitting.yaml
schemaName: readwrite_splitting_db数据源:db1: url:jdbc:mysql://192.168.158.134:3306/distributed_server?serverTimezone=UTC &useUnicode=true&characterEncoding=UTF-8&useSSL=false用户名: 根密码: psh120370连接超时毫秒: 30000空闲超时毫秒: 60000maxLifetime毫秒: 1800000maxPoolSize: 50minPoolSize: 1slave1: url:jdbc:mysql://192.168.158.146:3306/distributed_server?serverTimezone= UTC&useUnicode=true&characterEncoding=UTF-8&useSSL=false用户名 : root密码: psh120370连接超时毫秒: 30000空闲超时毫秒: 60000maxLifetime毫秒: 1800000maxPoolSize: 50minPoolSize: 1db0:网址:jdbc:mysql://192.168.158.165:3306/分布式_server?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF- 8&useSSL=false用户名:根密码: psh120370连接超时毫秒: 30000空闲超时毫秒: 60000maxLifetimeMilliseconds: 1800000maxPoolSize: 50minPoolSize:1规则:- !READWRITE_SPLITTING数据源:readwrite_ds:类型:静态props:写入数据源-名称: db1读取数据源名称:slave1
重新启动:
/usr/local/apache-shardingsphere-5.1.1-shardingsphere-proxy-bin/bin/www.introzo.com 3306
对 readwrite_splitting_db 的查询就会象征slave1上,写就会象征db1上,slave1 是db1的从库,readwrite_splitting_db就是一个代理库
通过springboot整合ShardingSphere-Proxy,不需要添加任何额外的依赖,在配置数据源的时候需要连接上面的逻辑库readwrite_splitting_db
spring:应用程序:名称:shardingProxy云 :nacos:发现:服务器地址: http://192.168.158.135:8848命名空间: d3a69e71-1c55-411c-940a-1f275c8c7bea 用户名: nacos密码: nacos 数据源:druid:驱动程序类名称: com.mysql.cj.jdbc.Driver网址:jdbc:mysql://192.168.158.166:3306 /readwrite_splitting_db?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF -8&useSSL=false用户名:根密码:根
水平分片
表结构和查询逻辑见:
https://www.introzo.com/persistence_PSH/article/details/131367613
修改配置config-sharding.yaml
cd /usr/local/apache-shardingsphere-5.1.1-shardingsphere-proxy-bin/confvim config-sharding.yaml
这里的schemaName需要和上面的读写分离逻辑库的名称不一致。其实spring boot中原来的配置是写入ShardingSphere-Proxy
schemaName: sharding_db数据源:db1:url :jdbc:mysql://192.168.158.134:3306/distributed_server?serverTimezone=UTC &useUnicode=true&characterEncoding=UTF-8&useSSL=false用户名: 根密码: psh120370连接超时毫秒: 30000空闲超时毫秒: 60000maxLifetime毫秒: 1800000maxPoolSize: 50minPoolSize: 1slave1: url:jdbc:mysql://192.168.158.146:3306/distributed_server?serverTimezone= UTC&useUnicode=true&characterEncoding=UTF-8&useSSL=false用户名 : root密码: psh120370连接超时毫秒: 30000空闲超时毫秒: 60000maxLifetime毫秒: 1800000maxPoolSize: 50minPoolSize: 1db0:url:jdbc:mysql://192.168.158.165:3306/distributed_server? serverTimezone=UTC&useUnicode=true&characterEncoding=UTF-8&useSSL=false用户名:根密码: psh120370连接超时毫秒: 30000idleTimeout毫秒: 60000maxLifetime毫秒: 1800000maxPoolSize: 50minPoolSize: 1规则:- !分片表:测试顺序:实际数据节点: db$->{0..1}.test_order$->{0..1}数据库策略 :标准:分片列:账户分片算法名称: inline_accounttableStrategy:标准:shardingColumn: order_noshardingAlgorithmName: hash_modkeyGenerateStrategy :列: idkeyGeneratorName :雪花test_order_item:实际数据节点:db$->{0..1}.test_order_item$->{0..1}数据库策略 :标准:分片列:账户分片算法名称:inline_account表策略:标准:shardingColumn: order_noshardingAlgorithmName : hash_modkeyGenerateStrategy:列: idkeyGeneratorName:雪花绑定表:- test_order ,test_order_item分片算法:inline_account:类型: HASH_MODprops:分片计数: 2hash_mod:类型: HASH_MOD道具:分片计数:2keyGenerators :雪花:类型 :雪花
springboot配置文件
spring:应用程序:名称:shardingProxy云 :nacos:发现:服务器地址: http://192.168.158.135:8848命名空间: d3a69e71-1c55-411c-940a-1f275c8c7bea 用户名: nacos密码: nacos 数据源:druid:驱动程序类名称: com.mysql.cj.jdbc.Driver网址:jdbc:mysql://192.168.158.166:3306 /sharding_db?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF -8&useSSL=false用户名:根密码:根
查询成功:
相关文章
- 10-03 android 表格布局属性
- 10-03 android表格布局介绍,TableLayout
- 10-03 html表格在页面上的位置,css表格布局-dis
- 10-03 php是一种编程语言吗?
- 10-03 如何下载wampserver
- 10-03 如何在php中启动exe文件
- 10-03 本田宣布2025年拆除东京总部大楼 2030年完成
- 10-03 曝三菱汽车已决定全面放弃中国生产 日系车开始出局?
- 10-03 问界M9 35万起售?内部人士:纯属无稽之谈!
- 10-03 2023年数据采集与融合技术实践作业1
- 10-03 自我介绍
- 10-03 2023年数据采集与融合技术实践作业
- 10-03 MySQL判断空值的方法是NULL和(mysql中
- 10-03 Linux网卡验证解决方案:turn it off
- 10-03 Linux下如何使用C语言实现文件复制操作(lin
- 10-03 Linux系统下的游戏:优质选择,更好体验(Lin
- 10-03 回答Linux时区问题:00 00代表哪个时区?
- 10-03 Linux下如何限制ssh登录? (Linux限制
- 10-03 jQuery实现手机下拉显示新内容动画反弹
- 10-03 jQuery实时统计输入框的字数及限制
- 最近发表