问题重现
我使用的是docker-compose方式部署seata server端
目录结构如下:
| - conf
- registry.conf
- file.conf
| - docker-compose.yml
docker-compose.yml配置如下:
version: "3"
services:
seata-server:
image: seataio/seata-server
hostname: seata-server
ports:
- "8091:8091"
environment:
- SEATA_IP=192.168.220.230
- SEATA_PORT=8091
- SEATA_CONFIG_NAME=file:/root/seata-config/registry
volumes:
- ./conf:/root/seata-config
registry.conf配置如下:
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos"
nacos {
application = "seata-server"
serverAddr = "xxx:8848"
group = ""
namespace = ""
cluster = "default"
username = "nacos"
password = "nacos"
}
}
config {
# file、nacos 、apollo、zk、consul、etcd3
type = "file"
file {
name = "file:/root/seata-config/file.conf"
}
}
file.conf配置如下:
# transaction log store, only used in seata-server
store {
## store mode: file、db、redis
mode = "db"
## rsa decryption public key
publicKey = ""
## database store property
db {
## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp)/HikariDataSource(hikari) etc.
datasource = "druid"
## mysql/oracle/postgresql/h2/oceanbase etc.
dbType = "mysql"
driverClassName = "com.mysql.cj.jdbc.Driver"
## if using mysql to store the data, recommend add rewriteBatchedStatements=true in jdbc connection param
url = "jdbc:mysql://xxx:3306/seata?useUnicode=true&rewriteBatchedStatements=true"
user = "xxx"
password = "xxx"
minConn = 5
maxConn = 100
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
}
结果发现无论我怎么修改registry.conf,都不起作用,不会注册服务到nacos,不会使用db存储分布式事务相关数据
问题原因
docker-compose没有指定seata-server的版本号,默认当前是lastest,是1.5.0以上版本,这个版本可能配置方式不同跟1.4.2的配置有所不同
解决方案
修改docker-compose.yml中的seata-server版本号为1.4.2
docker-compose.yml配置如下:
version: "3"
services:
seata-server:
image: seataio/seata-server:1.4.2
hostname: seata-server
ports:
- "8091:8091"
environment:
- SEATA_IP=192.168.220.230
- SEATA_PORT=8091
- SEATA_CONFIG_NAME=file:/root/seata-config/registry
volumes:
- ./conf:/root/seata-config
挂载application.yml
这种方式从启动的服务配置上去配置registry、config、store等信息,例如,我这里配置了store.mode=db,application.yml文件如下:
server:
port: 7091
spring:
application:
name: seata-server
logging:
config: classpath:logback-spring.xml
file:
path: ${user.home}/logs/seata
extend:
logstash-appender:
destination: 127.0.0.1:4560
kafka-appender:
bootstrap-servers: 127.0.0.1:9092
topic: logback_to_logstash
console:
user:
username: admin
password: admin
seata:
config:
# support: nacos, consul, apollo, zk, etcd3
type: file
registry:
# support: nacos, eureka, redis, zk, consul, etcd3, sofa
type: file
store:
# support: file 、 db 、 redis
mode: db
db:
dbType: mysql
datasource: druid
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://xxx/seata?useUnicode=true
user: xxx
password: xxx
# server:
# service-port: 8091 #If not configured, the default is '${server.port} + 1000'
security:
secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
tokenValidityInMilliseconds: 1800000
ignore:
urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login
主要修改了store.mode部分
docker-compose.yml配置:
version: "3"
services:
seata-server:
image: seataio/seata-server:1.4.2
hostname: seata-server
ports:
- "8091:8091"
environment:
- SEATA_IP=192.168.220.230
- SEATA_PORT=8091
volumes:
- ./application.yml:/seata-server/resources/application.yml
吐槽下seata官网文档,更新了也没写个文档,害我折腾,害!