首页 技术 正文
技术 2022年11月21日
0 收藏 587 点赞 2,326 浏览 1467 个字

在之前的文章中我详细描述了如何利用ShardingSphere-JDBC进行分库分表,同时也实现了简单的精确分库算法接口,详情见下面的链接:

利用ShardingSphere-JDBC实现分库分表

但是观察一下配置文件,我现在只有两张表的情况下就已经用了60行来做配置,如果说我在一个真实的系统中,那么配置文件的规模将是非常可观的,这个时候配置中心的作用就很重要了。ShardingSphere支持主流的zookeeper和etcd等服务发现组件,作为最常用的,我用zookeeper来实现。

下面是关于zookeeper部分的配置:

# 名字随便起一个
spring.shardingsphere.orchestration.name=spring_boot_ds_sharding
# 覆盖配置中心的配置,以本地为准
spring.shardingsphere.orchestration.overwrite=true
spring.shardingsphere.orchestration.registry.type=zookeeper
# 名字随便起一个,这是我们这个集群的名称,其他的集群可以用这个也可以用自己单独的,作为资源隔离
spring.shardingsphere.orchestration.registry.namespace=shardingsphere
spring.shardingsphere.orchestration.registry.server-lists=127.0.0.1:2181

服务启动以后就会自动的将这些配置上传到配置好的配置中心去,未来只需要修改配置中心就可以。

需要注意一点,官方文档中没有讲明白gradle或者maven的配置,如果按照文档上讲得直接把相关的starter配置进去,启动会报错,这是因为jar包冲突导致的,我这里给出gradle的配置,maven的可以参考修改:

compile('org.apache.shardingsphere:sharding-jdbc-orchestration-spring-boot-starter:4.0.0-RC2')
{
exclude group: 'org.apache.curator', module: 'curator-framework'
}
compile('org.apache.shardingsphere:sharding-orchestration-reg-zookeeper-curator:4.0.0-RC2')
{
exclude group: 'org.apache.curator', module: 'curator-framework'
exclude group: 'org.apache.curator', module: 'curator-recipes'
exclude group: 'org.apache.curator', module: 'curator-client'
}
compile group: 'org.apache.curator', name: 'curator-framework', version: '2.10.0'
compile group: 'org.apache.curator', name: 'curator-recipes', version: '2.10.0'

我们可以在zkCli上看看上传上去的配置信息:

至此我们就完成了配置中心的配置工作。在以后的篇幅中,我还会提及数据脱敏等其他内容,要是有时间的话,我还希望能够深入源码内部了解一下这个组件。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,031
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,862