刘耀文

刘耀文

java开发者
github

seata deployment

docker-compose db nacos mode#

Prepare database tables#

Database tables: https://github.com/apache/incubator-seata/tree/develop/script/server/db

Prepare compose.yaml file#

version: "3.1"
services:
  seata-server:
    image: seataio/seata-server:1.5.2
    ports:
      - "7091:7091"
      - "8091:8091"
    environment:
      - STORE_MODE=db
      - SEATA_IP=192.168.208.128
      - SEATA_PORT=8091
    volumes:
      - "/usr/share/zoneinfo/Asia/Shanghai:/etc/localtime"
      - "/usr/share/zoneinfo/Asia/Shanghai:/etc/timezone"
      - "./resources:/seata-server/resources"
    networks:
      - hm-net
          
networks:
  hm-net:
    external: true

Prepare application.yaml file#

https://github.com/apache/incubator-seata/blob/develop/server/src/main/resources/application.example.yml

Example of application.yaml
Note that after copying /seata-server/resources, the application inside needs to be replaced.

server:
  port: 7091

spring:
  application:
    name: seata-server
    
console:
  user:
    username: liuyaowen
    password: 123123

logging:
  config: classpath:logback-spring.xml
  file:
    path: ${log.home:${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

seata:
  config:
    type: nacos
    nacos:
      server-addr: 192.168.208.128:8848
      namespace: 9194952e-02a9-4737-89c2-1f3dee3317f0
      group: SEATA_GROUP
      username:
      password:
      context-path:
  registry:
    type: nacos
    preferred-networks: 30.240.*
    nacos:
      application: seata-server
      server-addr: 192.168.208.128:8848
      group: SEATA_GROUP
      namespace: 9194952e-02a9-4737-89c2-1f3dee3317f0
      cluster: default
      username:
      password:
      context-path:
  security:
    secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
    tokenValidityInMilliseconds: 1800000
    ignore:
      urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login

  metrics:
    enabled: false
    registry-type: compact
    exporter-list: prometheus
    exporter-prometheus-port: 9898
  transport:
    rpc-tc-request-timeout: 15000
    enable-tc-server-batch-send-response: false
    shutdown:
      wait: 3
    thread-factory:
      boss-thread-prefix: NettyBoss
      worker-thread-prefix: NettyServerNIOWorker
      boss-thread-size: 1

Afterwards, the configuration for seata needs to be set up in nacos.
Example of nacos configuration

store.mode=db

store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=jdbc:mysql://xxxx:xxxx/{database table name for seata}?useUnicode=true&characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
store.db.user=root
store.db.password=mysql_lyw
store.db.minConn=1
store.db.maxConn=20
store.db.maxWait=5000
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.lockTable=lock_table
store.db.distributedLockTable=distributed_lock
store.db.queryLimit=100

server.undo.logSaveDays=7
server.undo.logDeletePeriod=86400000
server.maxCommitRetryTimeout=-1
server.maxRollbackRetryTimeout=-1
server.recovery.committingRetryPeriod=1000
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
server.recovery.timeoutRetryPeriod=1000

console.user.username=liuyaowen
console.user.password=123123

Start the service#


docker-compose -f docker-compose.yaml up

File structure#

├── docker-compose.yaml
├── resources
│   ├── application.yaml
│   ├── banner.txt
│   ├── io
│   ├── logback
│   ├── logback-spring.xml
│   ├── lua
│   ├── META-INF
│   ├── README.md
│   ├── README-zh.md

Simple usage#

Import ID#

Of course, discovery, springcloud, and springcloudAlibaba need to be prepared in advance.
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>

Configuration#

seata:
    registry:
        type: nacos
        nacos:
            application: seata-server
            server-addr: 192.168.208.128:8848
            group: SEATA_GROUP
            namespace: 9194952e-02a9-4737-89c2-1f3dee3317f0
            username:
            password:
    tx-service-group: hmall
    service: 
        vgroup-mapping:
            hmall: "default"

AT mode#

-- Note that the context field was added in 0.7.0+
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,
  PRIMARY KEY (`id`),
  UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

This article is synchronized and updated to xLog by Mix Space
The original link is https://me.liuyaowen.club/posts/default/20240816and4


Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.