必要配置
# 必要配置
# 数据源配置
# 1.主数据源
支持Oracle和Mysql两种数据库,稍加调整,可支持所有常用关系型数据库。
spring:
datasource:
#MySql数据源
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/base2048?useSSL=false&serverTimezone=GMT%2B8&autoReconnect=true&allowPublicKeyRetrieval=true&useOldAliasMetadataBehavior=true
username: root
password: mysql
#Oracle数据源
# driverClassName: oracle.jdbc.driver.OracleDriver
# url: jdbc:oracle:thin:@127.0.0.1:1521:orcl
# P6Spy 数据库访问操作的动态监测框架
# driver-class-name: com.p6spy.engine.spy.P6SpyDriver
# url: jdbc:p6spy:oracle:thin:@127.0.0.1:1521:orcl
# username: base2048
# password: base2048
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
启动base2048服务时,系统会自动在主数据源创建数据表、视图,初始化各类数据。
# 2.Quartz框架定时任务数据源
可与主数据源一体,也可以单独设置。为了逻辑更清晰,建议单独设置定时任务数据源。
base2048:
job:
enable: true
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/base2048job?useSSL=false&serverTimezone=GMT%2B8&autoReconnect=true&allowPublicKeyRetrieval=true&useOldAliasMetadataBehavior=true
username: root
password: mysql
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
启动base2048服务时,系统会自动在定时任务数据源创建11张数据表。如下图所示:
# 3.Flowable工作流数据源
可与主数据源一体,也可以单独设置。为了逻辑更清晰,建议单独设置工作流数据源。
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/base2048flow?useSSL=false&serverTimezone=UTC&autoReconnect=true&allowPublicKeyRetrieval=true&useOldAliasMetadataBehavior=true&nullCatalogMeansCurrent=true
username: root
password: mysql
1
2
3
4
5
6
2
3
4
5
6
启动workflow3072服务时,系统会自动在主数据源创建38张数据表、初始化各类数据。
注意
为实现分布式事务,需手工在Quartz数据源和Flowable工作流数据源分别创建Seata的undo_log表。
Mysql表
CREATE TABLE `undo_log` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`branch_id` bigint(20) NOT NULL,
`xid` varchar(100) NOT NULL,
`context` varchar(128) NOT NULL,
`rollback_info` longblob NOT NULL,
`log_status` int(11) NOT NULL,
`log_created` datetime NOT NULL,
`log_modified` datetime NOT NULL,
`ext` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
Oracle表和序列
--liquibase formatted sql
-- oracle for AT mode you must to init this sql for you business database. the seata server not need it.
CREATE TABLE undo_log
(
id NUMBER(19) NOT NULL,
branch_id NUMBER(19) NOT NULL,
xid VARCHAR2(128) NOT NULL,
context VARCHAR2(128) NOT NULL,
rollback_info BLOB NOT NULL,
log_status NUMBER(10) NOT NULL,
log_created TIMESTAMP(0) NOT NULL,
log_modified TIMESTAMP(0) NOT NULL,
PRIMARY KEY (id),
CONSTRAINT ux_undo_log UNIQUE (xid, branch_id)
);
COMMENT ON TABLE undo_log IS 'AT transaction mode undo table';
-- Generate ID using sequence and trigger
CREATE SEQUENCE UNDO_LOG_SEQ START WITH 1 INCREMENT BY 1;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Nacos相关配置
# 1.Nacos conf/application.properties
### 启用安全认证
nacos.core.auth.enabled=true
nacos.core.auth.server.identity.key=nacos
nacos.core.auth.server.identity.value=nacos123456
nacos.core.auth.plugin.nacos.token.secret.key=VGhpc0lzTXlDdXN0b21TZWNyZXRLZXkwMTIzNDU2Nzg=
1
2
3
4
5
2
3
4
5
生产环境建议启用Nacos认证
# 2.微服务
spring:
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848 #nacos的IP和端口
namespace: 9047c5e7-ee93-498f-9c79-10f53a92310f #命名空间
username: nacos #nacos安全认证账号
password: nacos123456 #nacos安全认证密码
ip: 127.0.0.1 #向nacos注册的自身服务IP
port: 2048 #向nacos注册的自身服务端口
config:
username: ${spring.cloud.nacos.discovery.username} #nacos配置中心认证账号
password: ${spring.cloud.nacos.discovery.password} #nacos配置中心认证密码
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
# Seata相关配置
# 1.Seata conf/file.conf
store {
mode = "file"
publicKey = ""
file {
## store location dir
dir = "sessionStore"
# branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
maxBranchSessionSize = 16384
# globe session size , if exceeded throws exceptions
maxGlobalSessionSize = 512
# file buffer size , if exceeded allocate new buffer
fileWriteBufferCacheSize = 16384
# when recover batch read size
sessionReloadReadSize = 100
# async, sync
flushDiskMode = async
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 2.Seata conf/registry.conf
# 服务注册
registry {
type = "nacos"
nacos {
application = "seata-server"
serverAddr = "127.0.0.1:8848" #nacos的IP和PORT
group = "SEATA_GROUP" #微服务分组名称
namespace = "a667f2c4-d1f7-466b-80e7-2fa043135670" #命名空间
cluster = "default"
username = "nacos" #nacos配置中心认证账号
password = "nacos123456" #nacos配置中心认证密码
}
}
# 配置中心
config {
type = "nacos"
nacos {
serverAddr = "127.0.0.1:8848" #nacos的IP和PORT
namespace = "a667f2c4-d1f7-466b-80e7-2fa043135670" #命名空间
group = "SEATA_GROUP" #微服务分组名称
username = "nacos" #nacos配置中心认证账号
password = "nacos123456" #nacos配置中心认证账号
dataId = "seataServer.properties"
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 3.微服务
seata:
application-id: ${spring.application.name}
tx-service-group: my_test_tx_group
enable-auto-data-source-proxy: true
client:
undo:
log-serialization: kryo
registry:
type: nacos
nacos:
server-addr: 127.0.0.1:8848
namespace: a667f2c4-d1f7-466b-80e7-2fa043135670
group: SEATA_GROUP
username: ${spring.cloud.nacos.discovery.username}
password: ${spring.cloud.nacos.discovery.password}
config:
type: nacos
nacos:
server-addr: 127.0.0.1:8848
namespace: a667f2c4-d1f7-466b-80e7-2fa043135670
group: SEATA_GROUP
username: ${spring.cloud.nacos.discovery.username}
password: ${spring.cloud.nacos.discovery.password}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Redis相关配置
# 1.redis.windows-service.conf
port 6389
requirepass redis2021
1
2
2
# 2.微服务
spring:
redis:
# Redis服务器地址
host: 127.0.0.1
# Redis数据库索引(默认为0)
database: 0
# Redis服务器连接端口
port: 6389
# Redis服务器连接密码(默认为空)
password: redis2021
# 连接超时时间
timeout: 1000ms
lettuce:
pool:
# 连接池最大连接数
max-active: 8
# 连接池最大空闲连接数
max-idle: 8
# 连接池最小空闲连接数
min-idle: 0
# 连接池最大阻塞等待时间,负值表示没有限制
max-wait: -1ms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Liquibase相关配置
spring:
liquibase:
enabled: true
change-log: classpath:liquibase/master.xml
1
2
3
4
2
3
4
master.xml
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<includeAll path="liquibase/changelogs/" relativeToChangelogFile="false"/>
</databaseChangeLog>
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 开启监控
management:
endpoints:
web:
exposure:
include: "*"
base-path: /actuator
endpoint:
health:
show-details: ALWAYS
server:
port: 12048
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 日志
logging:
config: classpath:log4j2-dev.xml
level:
root: info
com.qiyuan: debug
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
mapper-locations: classpath*:**/mapper/mybatis/xml/*.xml
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
编辑 (opens new window)
上次更新: 2024/04/18