feat: shardingsphere主从复制,去除dynamic-datasource多数据源
This commit is contained in:
@@ -1 +1,3 @@
|
|||||||
# 诺力开发平台
|
# 诺力开发平台
|
||||||
|
## 主从复制(Master-Slave Replication)
|
||||||
|
<img src="./doc/img.png">
|
||||||
|
|||||||
BIN
nladmin-system/doc/img.png
Normal file
BIN
nladmin-system/doc/img.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 455 KiB |
@@ -32,6 +32,12 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- 主从复制 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.shardingsphere</groupId>
|
||||||
|
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
|
||||||
|
<version>5.1.1</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.dameng</groupId>
|
<groupId>com.dameng</groupId>
|
||||||
<artifactId>DmJdbcDriver18</artifactId>
|
<artifactId>DmJdbcDriver18</artifactId>
|
||||||
@@ -76,11 +82,11 @@
|
|||||||
<version>11.2.0.4</version>
|
<version>11.2.0.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- dynamic-datasource -->
|
<!-- dynamic-datasource -->
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>com.baomidou</groupId>
|
<!-- <groupId>com.baomidou</groupId>-->
|
||||||
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
|
<!-- <artifactId>dynamic-datasource-spring-boot-starter</artifactId>-->
|
||||||
<version>4.1.3</version>
|
<!-- <version>4.1.3</version>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
<!-- https://onew.me/logback/2018/09/17/logback_win.html-->
|
<!-- https://onew.me/logback/2018/09/17/logback_win.html-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.fusesource.jansi</groupId>
|
<groupId>org.fusesource.jansi</groupId>
|
||||||
|
|||||||
@@ -9,6 +9,12 @@ nl:
|
|||||||
username: root
|
username: root
|
||||||
password: 12356
|
password: 12356
|
||||||
database: nl-platform
|
database: nl-platform
|
||||||
|
slave:
|
||||||
|
ip: 127.0.0.1
|
||||||
|
port: 3306
|
||||||
|
username: root
|
||||||
|
password: 12356
|
||||||
|
database: nl_platform
|
||||||
redis:
|
redis:
|
||||||
ip: 127.0.0.1
|
ip: 127.0.0.1
|
||||||
port: 6379
|
port: 6379
|
||||||
|
|||||||
@@ -12,62 +12,102 @@ spring:
|
|||||||
exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
|
exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
|
||||||
messages:
|
messages:
|
||||||
basename: language/login/login,language/error/error,language/buss/buss,language/task/task
|
basename: language/login/login,language/error/error,language/buss/buss,language/task/task
|
||||||
datasource:
|
shardingsphere:
|
||||||
druid:
|
datasource:
|
||||||
initial-size: 5 #初始化时建立物理连接的个数
|
names: master,slave
|
||||||
min-idle: 15 #最小连接池数量
|
master:
|
||||||
maxActive: 30 #最大连接池数量
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
maxWait: 3000 #获取连接时最大等待时间,单位毫秒
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
#申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。
|
# 初始连接数
|
||||||
test-while-idle: true
|
initial-size: 20
|
||||||
time-between-eviction-runs-millis: 300000 #既作为检测的间隔时间又作为test-while-idle执行的依据
|
# 最小连接数
|
||||||
min-evictable-idle-time-millis: 900000 #销毁线程时检测当前连接的最后活动时间和当前时间差大于该值时,关闭当前连接
|
min-idle: 30
|
||||||
#用来检测连接是否有效的sql
|
# 最大连接数
|
||||||
#mysql中为 select 'x'
|
max-active: 300
|
||||||
#oracle中为 select 1 from dual
|
# 是否自动回收超时连接
|
||||||
validation-query: SELECT 'x'
|
socket-timeout: 10
|
||||||
test-on-borrow: true #申请连接时会执行validationQuery检测连接是否有效,开启会降低性能,默认为true
|
query-time-out: 7
|
||||||
test-on-return: false #归还连接时会执行validationQuery检测连接是否有效,开启会降低性能,默认为true
|
transaction-query-timeout: 30
|
||||||
exception-sorter: true #当数据库抛出不可恢复的异常时,抛弃该连接
|
# 获取连接超时时间
|
||||||
pool-prepared-statements: true #是否缓存preparedStatement,mysql5.5+建议开启
|
max-wait: 4000
|
||||||
max-pool-prepared-statement-per-connection-size: 20 #当值大于20时poolPreparedStatements会自动修改为true
|
# 连接有效性检测时间
|
||||||
#通过connectProperties属性来打开mergeSql功能;慢SQL记录
|
time-between-eviction-runs-millis: 60000
|
||||||
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
|
# 连接在池中最小生存的时间
|
||||||
# use-global-data-source-stat: true #合并多个DruidDataSource的监控数据
|
min-evictable-idle-time-millis: 300000
|
||||||
#filters通过别名的方式配置扩展插件,常用的插件有:
|
# 连接在池中最大生存的时间
|
||||||
#监控统计用的filter:stat 日志用的filter:log4j 防御sql注入的filter:wall
|
max-evictable-idle-time-millis: 900000
|
||||||
filter:
|
# 指明连接是否被空闲连接回收器(如果有)进行检验.如果检测失败,则连接将被从池中去除
|
||||||
stat:
|
test-while-idle: true
|
||||||
|
# 指明是否在从池中取出连接前进行检验,如果检验失败, 则从池中去除连接并尝试取出另一个
|
||||||
|
test-on-borrow: true
|
||||||
|
# 是否在归还到池中前进行检验
|
||||||
|
test-on-return: false
|
||||||
|
# 检测连接是否有效
|
||||||
|
validation-query: select 1
|
||||||
|
# 配置监控统计
|
||||||
|
webStatFilter:
|
||||||
enabled: true
|
enabled: true
|
||||||
# 记录慢SQL
|
stat-view-servlet:
|
||||||
log-slow-sql: true
|
enabled: true
|
||||||
slow-sql-millis: 1000
|
url-pattern: /druid/*
|
||||||
merge-sql: true
|
reset-enable: false
|
||||||
wall:
|
|
||||||
config:
|
|
||||||
multi-statement-allow: true
|
|
||||||
#设置访问druid监控页面的拦截路径及账号和密码,默认没有
|
|
||||||
stat-view-servlet:
|
|
||||||
enabled: true
|
|
||||||
url-pattern: /druid/*
|
|
||||||
login-username: admin
|
|
||||||
login-password: admin
|
|
||||||
dynamic:
|
|
||||||
primary: mysql
|
|
||||||
datasource:
|
|
||||||
mysql:
|
|
||||||
driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
|
||||||
url: jdbc:log4jdbc:mysql://${DB_HOST:${nl.config.mysql.ip}}:${DB_PORT:${nl.config.mysql.port}}/${DB_NAME:${nl.config.mysql.database}}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
|
|
||||||
username: ${DB_USER:${nl.config.mysql.username}}
|
|
||||||
password: ${DB_PWD:${nl.config.mysql.password}}
|
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
|
||||||
druid:
|
|
||||||
filters:
|
filters:
|
||||||
DruidFilter,stat
|
DruidFilter,stat
|
||||||
initial-size: 5 #初始化时建立物理连接的个数
|
url: jdbc:mysql://${DB_HOST:${nl.config.mysql.ip}}:${DB_PORT:${nl.config.mysql.port}}/${DB_NAME:${nl.config.mysql.database}}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
|
||||||
min-idle: 15 #最小连接池数量
|
username: ${DB_USER:${nl.config.mysql.username}}
|
||||||
maxActive: 30 #最大连接池数量
|
password: ${DB_PWD:${nl.config.mysql.password}}
|
||||||
maxWait: 3000 #获取连接时最大等待时间,单位毫秒
|
slave:
|
||||||
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
# 初始连接数
|
||||||
|
initial-size: 20
|
||||||
|
# 最小连接数
|
||||||
|
min-idle: 30
|
||||||
|
# 最大连接数
|
||||||
|
max-active: 300
|
||||||
|
# 是否自动回收超时连接
|
||||||
|
socket-timeout: 10
|
||||||
|
query-time-out: 7
|
||||||
|
transaction-query-timeout: 30
|
||||||
|
# 获取连接超时时间
|
||||||
|
max-wait: 4000
|
||||||
|
# 连接有效性检测时间
|
||||||
|
time-between-eviction-runs-millis: 60000
|
||||||
|
# 连接在池中最小生存的时间
|
||||||
|
min-evictable-idle-time-millis: 300000
|
||||||
|
# 连接在池中最大生存的时间
|
||||||
|
max-evictable-idle-time-millis: 900000
|
||||||
|
# 指明连接是否被空闲连接回收器(如果有)进行检验.如果检测失败,则连接将被从池中去除
|
||||||
|
test-while-idle: true
|
||||||
|
# 指明是否在从池中取出连接前进行检验,如果检验失败, 则从池中去除连接并尝试取出另一个
|
||||||
|
test-on-borrow: true
|
||||||
|
# 是否在归还到池中前进行检验
|
||||||
|
test-on-return: false
|
||||||
|
# 检测连接是否有效
|
||||||
|
validation-query: select 1
|
||||||
|
# 配置监控统计
|
||||||
|
webStatFilter:
|
||||||
|
enabled: true
|
||||||
|
stat-view-servlet:
|
||||||
|
enabled: true
|
||||||
|
url-pattern: /druid/*
|
||||||
|
reset-enable: false
|
||||||
|
filters:
|
||||||
|
DruidFilter,stat
|
||||||
|
url: jdbc:mysql://${DB_HOST:${nl.config.slave.ip}}:${DB_PORT:${nl.config.slave.port}}/${DB_NAME:${nl.config.slave.database}}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
|
||||||
|
username: ${DB_USER:${nl.config.slave.username}}
|
||||||
|
password: ${DB_PWD:${nl.config.slave.password}}
|
||||||
|
rules:
|
||||||
|
readwrite-splitting:
|
||||||
|
data-sources:
|
||||||
|
db:
|
||||||
|
type: Static
|
||||||
|
props:
|
||||||
|
#接口有事务,读写分离不生效,默认全部使用主库
|
||||||
|
write-data-source-name: master
|
||||||
|
read-data-source-names: slave
|
||||||
|
#负载均衡算法名称
|
||||||
|
load-balancer-name: round-robin
|
||||||
flyway:
|
flyway:
|
||||||
#开启
|
#开启
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|||||||
Reference in New Issue
Block a user