Commit edff9f7d authored by tangtuo's avatar tangtuo

引入sharding-jdbc,加入读写分离配置

parent b8ca93b7
server: server:
port: 8002 port: 8002
spring: spring:
application:
name: joying-admin
main: main:
allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册 allow-bean-definition-overriding: true
datasource: shardingsphere:
url: jdbc:mysql://172.16.101.136:3306/fzm_joying?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 datasource:
username: root names:
password: Joying@123456 write,read
platform: mysql # 主数据源
type: com.alibaba.druid.pool.DruidDataSource write:
driver-class-name: com.mysql.cj.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource
druid: driver-class-name: com.mysql.cj.jdbc.Driver
initial-size: 5 url: jdbc:mysql://172.16.101.135:3306/joying_dev?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8
min-idle: 5 username: root
max-active: 20 password: Joying@123456
max-wait: 60000 # 从数据源
time-between-eviction-runs-millis: 60000 read:
min-evictable-idle-time-millis: 300000 type: com.alibaba.druid.pool.DruidDataSource
validation-query: SELECT 1 FROM DUAL driver-class-name: com.mysql.cj.jdbc.Driver
test-while-idle: true url: jdbc:mysql://172.16.101.136:3306/joying_dev?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8
test-on-borrow: false username: root
test-on-return: false password: Joying@123456
pool-prepared-statements: false masterslave:
max-pool-prepared-statement-per-connection-size: 20 # 读写分离配置
filters: stat ,wall load-balance-algorithm-type: round_robin
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 # 最终的数据源名称
useGlobalDataSourceStat: true name: dataSource
# 主库数据源名称
master-data-source-name: write
# 从库数据源名称列表,多个逗号分隔
slave-data-source-names: read
props:
# 开启SQL显示,默认false
sql:
show: true
redis: redis:
host: 172.16.101.135 host: 172.16.101.135
port: 6379 port: 6379
......
server: server:
port: 8002 port: 8002
spring: spring:
application:
name: joying-admin
main: main:
allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册 allow-bean-definition-overriding: true
datasource: shardingsphere:
url: jdbc:mysql://172.16.101.136:3306/fzm_joying?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 datasource:
username: root names:
password: Joying@123456 write,read
platform: mysql # 主数据源
type: com.alibaba.druid.pool.DruidDataSource write:
driver-class-name: com.mysql.cj.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource
druid: driver-class-name: com.mysql.cj.jdbc.Driver
initial-size: 5 url: jdbc:mysql://172.16.101.135:3306/joying_dev?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8
min-idle: 5 username: root
max-active: 20 password: Joying@123456
max-wait: 60000 # 从数据源
time-between-eviction-runs-millis: 60000 read:
min-evictable-idle-time-millis: 300000 type: com.alibaba.druid.pool.DruidDataSource
validation-query: SELECT 1 FROM DUAL driver-class-name: com.mysql.cj.jdbc.Driver
test-while-idle: true url: jdbc:mysql://172.16.101.136:3306/joying_dev?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8
test-on-borrow: false username: root
test-on-return: false password: Joying@123456
pool-prepared-statements: false masterslave:
max-pool-prepared-statement-per-connection-size: 20 # 读写分离配置
filters: stat ,wall load-balance-algorithm-type: round_robin
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 # 最终的数据源名称
useGlobalDataSourceStat: true name: dataSource
# 主库数据源名称
master-data-source-name: write
# 从库数据源名称列表,多个逗号分隔
slave-data-source-names: read
props:
# 开启SQL显示,默认false
sql:
show: true
redis: redis:
host: 172.16.101.135 host: 172.16.101.135
port: 6379 port: 6379
......
server: server:
port: 8002 port: 8002
spring: spring:
application:
name: joying-admin
main: main:
allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册 allow-bean-definition-overriding: true
datasource: shardingsphere:
url: jdbc:mysql://172.16.101.136:3306/fzm_joying_test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 datasource:
username: root names:
password: Joying@123456 write,read
platform: mysql # 主数据源
type: com.alibaba.druid.pool.DruidDataSource write:
driver-class-name: com.mysql.cj.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource
druid: driver-class-name: com.mysql.cj.jdbc.Driver
initial-size: 5 url: jdbc:mysql://172.16.101.135:3306/joying_test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8
min-idle: 5 username: root
max-active: 20 password: Joying@123456
max-wait: 60000 # 从数据源
time-between-eviction-runs-millis: 60000 read:
min-evictable-idle-time-millis: 300000 type: com.alibaba.druid.pool.DruidDataSource
validation-query: SELECT 1 FROM DUAL driver-class-name: com.mysql.cj.jdbc.Driver
test-while-idle: true url: jdbc:mysql://172.16.101.136:3306/joying_test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8
test-on-borrow: false username: root
test-on-return: false password: Joying@123456
pool-prepared-statements: false masterslave:
max-pool-prepared-statement-per-connection-size: 20 # 读写分离配置
filters: stat ,wall load-balance-algorithm-type: round_robin
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 # 最终的数据源名称
useGlobalDataSourceStat: true name: dataSource
# 主库数据源名称
master-data-source-name: write
# 从库数据源名称列表,多个逗号分隔
slave-data-source-names: read
props:
# 开启SQL显示,默认false
sql:
show: true
redis: redis:
host: 172.16.101.136 host: 172.16.101.136
port: 6379 port: 6379
......
...@@ -88,6 +88,11 @@ ...@@ -88,6 +88,11 @@
<groupId>com.google.zxing</groupId> <groupId>com.google.zxing</groupId>
<artifactId>core</artifactId> <artifactId>core</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
</dependency>
</dependencies> </dependencies>
<properties> <properties>
......
...@@ -2,30 +2,38 @@ server: ...@@ -2,30 +2,38 @@ server:
port: 8001 port: 8001
spring: spring:
main: main:
allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册 allow-bean-definition-overriding: true
datasource: shardingsphere:
url: jdbc:mysql://172.16.101.136:3306/fzm_joying?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 datasource:
username: root names:
password: Joying@123456 write,read
platform: mysql # 主数据源
type: com.alibaba.druid.pool.DruidDataSource write:
driver-class-name: com.mysql.cj.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource
druid: driver-class-name: com.mysql.cj.jdbc.Driver
initial-size: 5 url: jdbc:mysql://172.16.101.135:3306/joying_dev?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8
min-idle: 5 username: root
max-active: 20 password: Joying@123456
max-wait: 60000 # 从数据源
time-between-eviction-runs-millis: 60000 read:
min-evictable-idle-time-millis: 300000 type: com.alibaba.druid.pool.DruidDataSource
validation-query: SELECT 1 FROM DUAL driver-class-name: com.mysql.cj.jdbc.Driver
test-while-idle: true url: jdbc:mysql://172.16.101.136:3306/joying_dev?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8
test-on-borrow: false username: root
test-on-return: false password: Joying@123456
pool-prepared-statements: false masterslave:
max-pool-prepared-statement-per-connection-size: 20 # 读写分离配置
filters: stat ,wall load-balance-algorithm-type: round_robin
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 # 最终的数据源名称
useGlobalDataSourceStat: true name: dataSource
# 主库数据源名称
master-data-source-name: write
# 从库数据源名称列表,多个逗号分隔
slave-data-source-names: read
props:
# 开启SQL显示,默认false
sql:
show: true
redis: redis:
host: 172.16.101.135 host: 172.16.101.135
port: 6379 port: 6379
......
...@@ -2,30 +2,38 @@ server: ...@@ -2,30 +2,38 @@ server:
port: 8001 port: 8001
spring: spring:
main: main:
allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册 allow-bean-definition-overriding: true
datasource: shardingsphere:
url: jdbc:mysql://172.16.101.136:3306/fzm_joying?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 datasource:
username: root names:
password: Joying@123456 write,read
platform: mysql # 主数据源
type: com.alibaba.druid.pool.DruidDataSource write:
driver-class-name: com.mysql.cj.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource
druid: driver-class-name: com.mysql.cj.jdbc.Driver
initial-size: 5 url: jdbc:mysql://172.16.101.135:3306/joying_dev?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8
min-idle: 5 username: root
max-active: 20 password: Joying@123456
max-wait: 60000 # 从数据源
time-between-eviction-runs-millis: 60000 read:
min-evictable-idle-time-millis: 300000 type: com.alibaba.druid.pool.DruidDataSource
validation-query: SELECT 1 FROM DUAL driver-class-name: com.mysql.cj.jdbc.Driver
test-while-idle: true url: jdbc:mysql://172.16.101.136:3306/joying_dev?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8
test-on-borrow: false username: root
test-on-return: false password: Joying@123456
pool-prepared-statements: false masterslave:
max-pool-prepared-statement-per-connection-size: 20 # 读写分离配置
filters: stat ,wall load-balance-algorithm-type: round_robin
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 # 最终的数据源名称
useGlobalDataSourceStat: true name: dataSource
# 主库数据源名称
master-data-source-name: write
# 从库数据源名称列表,多个逗号分隔
slave-data-source-names: read
props:
# 开启SQL显示,默认false
sql:
show: true
redis: redis:
host: localhost host: localhost
port: 6379 port: 6379
......
...@@ -2,30 +2,38 @@ server: ...@@ -2,30 +2,38 @@ server:
port: 8001 port: 8001
spring: spring:
main: main:
allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册 allow-bean-definition-overriding: true
datasource: shardingsphere:
url: jdbc:mysql://172.16.101.136:3306/fzm_joying_test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 datasource:
username: root names:
password: Joying@123456 write,read
platform: mysql # 主数据源
type: com.alibaba.druid.pool.DruidDataSource write:
driver-class-name: com.mysql.cj.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource
druid: driver-class-name: com.mysql.cj.jdbc.Driver
initial-size: 5 url: jdbc:mysql://172.16.101.135:3306/joying_test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8
min-idle: 5 username: root
max-active: 20 password: Joying@123456
max-wait: 60000 # 从数据源
time-between-eviction-runs-millis: 60000 read:
min-evictable-idle-time-millis: 300000 type: com.alibaba.druid.pool.DruidDataSource
validation-query: SELECT 1 FROM DUAL driver-class-name: com.mysql.cj.jdbc.Driver
test-while-idle: true url: jdbc:mysql://172.16.101.136:3306/joying_test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8
test-on-borrow: false username: root
test-on-return: false password: Joying@123456
pool-prepared-statements: false masterslave:
max-pool-prepared-statement-per-connection-size: 20 # 读写分离配置
filters: stat ,wall load-balance-algorithm-type: round_robin
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 # 最终的数据源名称
useGlobalDataSourceStat: true name: dataSource
# 主库数据源名称
master-data-source-name: write
# 从库数据源名称列表,多个逗号分隔
slave-data-source-names: read
props:
# 开启SQL显示,默认false
sql:
show: true
redis: redis:
host: 172.16.101.136 host: 172.16.101.136
port: 6379 port: 6379
......
...@@ -99,6 +99,18 @@ ...@@ -99,6 +99,18 @@
<artifactId>core</artifactId> <artifactId>core</artifactId>
<version>3.3.0</version> <version>3.3.0</version>
</dependency> </dependency>
<!-- sharding -->
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
<version>4.0.0-RC1</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment