SEATA安装使用

发布时间:2023年12月25日

官网:https://seata.io/

介绍:http://www.dreamwu.com/post-1741.html


版本

组件版本
SpringBoot2.3.12.RELEASE
SpringCloudHoxton.SR12
SpringCloudAlibaba2.2.10-RC1
Nacos2.2.0
Sentinel1.8.6
Seata1.6.1

安装 Seata 服务端

下载

下载地址:https://github.com/apache/incubator-seata/releases/tag/v1.6.1

配置 Seata 配置文件

解压完成后,修改:\seata\conf\application.yml文件

seata:
  config:
    # 配置中心类型,选择使用nacos
    type: nacos
    nacos:
      # nacos服务地址
      server-addr: 127.0.0.1:8848
      # nacos组
      group: SEATA_GROUP
      # nacos命名空间
      namespace: seata
      # 有权限读写命名空间的账号密码,无鉴权不需要
      username: dev
      password: 123456
      # seata在nacos上读取的配置文件
      data-id: seataServer.properties
  registry:
    # 注册中心类型,选择使用nacos
    type: nacos
    nacos:
      # nacos服务地址
      server-addr: 127.0.0.1:8848
      # 制定 seata 服务名称,就像SpringBoot的 spring.application.name 一样
      application: seata-tc-server
      # nacos组
      group: SEATA_GROUP
      # nacos命名空间
      namespace: seata
      username: dev
      password: 123456
      # 自定义seata服务集群名称
      cluster: AAA

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: seata
    password: seata


seata:
  config:
    # 配置中心类型,选择使用nacos
    type: nacos
    nacos:
      # nacos服务地址
      server-addr: 127.0.0.1:8848
      # nacos组
      group: SEATA_GROUP
      # nacos命名空间
      namespace: seata
      # 有权限读写命名空间的账号密码,无鉴权不需要
      username: dev
      password: 123456
      # seata在nacos上读取的配置文件
      data-id: seataServer.properties
  registry:
    # 注册中心类型,选择使用nacos
    type: nacos
    nacos:
      # nacos服务地址
      server-addr: 127.0.0.1:8848
      # 制定 seata 服务名称,就像SpringBoot的 spring.application.name 一样
      application: seata-tc-server
      # nacos组
      group: SEATA_GROUP
      # nacos命名空间
      namespace: seata
      username: dev
      password: 123456
      # 自定义seata服务集群名称
      cluster: AAA
#  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

配置 Seata 持久化方式

这里我们使用 DB 数据库的方式

1,新建名称为 seata 数据库

2,向数据库中导入seata解压包路径文件?\seata\script\server\db\mysql.sql

mysql.sql 内容如下:

-- -------------------------------- The script used when storeMode is 'db' --------------------------------
-- the table to store GlobalSession data
CREATE TABLE IF NOT EXISTS `global_table`
(
    `xid`                       VARCHAR(128) NOT NULL,
    `transaction_id`            BIGINT,
    `status`                    TINYINT      NOT NULL,
    `application_id`            VARCHAR(32),
    `transaction_service_group` VARCHAR(32),
    `transaction_name`          VARCHAR(128),
    `timeout`                   INT,
    `begin_time`                BIGINT,
    `application_data`          VARCHAR(2000),
    `gmt_create`                DATETIME,
    `gmt_modified`              DATETIME,
    PRIMARY KEY (`xid`),
    KEY `idx_status_gmt_modified` (`status` , `gmt_modified`),
    KEY `idx_transaction_id` (`transaction_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

-- the table to store BranchSession data
CREATE TABLE IF NOT EXISTS `branch_table`
(
    `branch_id`         BIGINT       NOT NULL,
    `xid`               VARCHAR(128) NOT NULL,
    `transaction_id`    BIGINT,
    `resource_group_id` VARCHAR(32),
    `resource_id`       VARCHAR(256),
    `branch_type`       VARCHAR(8),
    `status`            TINYINT,
    `client_id`         VARCHAR(64),
    `application_data`  VARCHAR(2000),
    `gmt_create`        DATETIME(6),
    `gmt_modified`      DATETIME(6),
    PRIMARY KEY (`branch_id`),
    KEY `idx_xid` (`xid`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

-- the table to store lock data
CREATE TABLE IF NOT EXISTS `lock_table`
(
    `row_key`        VARCHAR(128) NOT NULL,
    `xid`            VARCHAR(128),
    `transaction_id` BIGINT,
    `branch_id`      BIGINT       NOT NULL,
    `resource_id`    VARCHAR(256),
    `table_name`     VARCHAR(32),
    `pk`             VARCHAR(36),
    `status`         TINYINT      NOT NULL DEFAULT '0' COMMENT '0:locked ,1:rollbacking',
    `gmt_create`     DATETIME,
    `gmt_modified`   DATETIME,
    PRIMARY KEY (`row_key`),
    KEY `idx_status` (`status`),
    KEY `idx_branch_id` (`branch_id`),
    KEY `idx_xid` (`xid`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

CREATE TABLE IF NOT EXISTS `distributed_lock`
(
    `lock_key`       CHAR(20) NOT NULL,
    `lock_value`     VARCHAR(20) NOT NULL,
    `expire`         BIGINT,
    primary key (`lock_key`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0);

文章来源:https://blog.csdn.net/a1053765496/article/details/135192011
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。