Seata部署问题 - registry.conf配置文件不起作用

本文详细记录了使用docker-compose部署Seata 1.4.2版本时遇到的问题及解决办法。在尝试用nacos作为注册中心和配置中心时,配置不生效,发现是由于Seata版本升级导致的配置差异。通过将版本回退到1.4.2并调整配置文件,包括docker-compose.yml、registry.conf、file.conf,最终成功使Seata注册到nacos并使用db存储分布式事务数据。此外,还分享了如何通过挂载application.yml文件来进一步配置Seata。

问题重现

我使用的是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官网文档,更新了也没写个文档,害我折腾,害!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

来了就走下去

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值