欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

seata 1.4安装与配置

程序员文章站 2022-06-21 17:07:00
...

seata是阿里巴巴的分布式全家桶解决方案

  1. 下载:https://github.com/seata/seata/releases

解压,注意看下里面有个README-zh.md,相关的一些脚本可以在这个文件的链接找到,因为不同的seata版本,脚本可能有差异,需要注意下。我这里把1.4.0的这个文件内容补充在下面:

脚本说明

client

存放用于客户端的配置和SQL

  • at: AT模式下的 undo_log 建表语句
  • conf: 客户端的配置文件
  • saga: SAGA 模式下所需表的建表语句
  • spring: SpringBoot 应用支持的配置文件

server

存放server侧所需SQL和部署脚本

  • db: server 侧的保存模式为 db 时所需表的建表语句
  • docker-compose: server 侧通过 docker-compose 部署的脚本
  • helm: server 侧通过 Helm 部署的脚本
  • kubernetes: server 侧通过 Kubernetes 部署的脚本

config-center

用于存放各种配置中心的初始化脚本,执行时都会读取 config.txt配置文件,并写入配置中心

  • nacos: 用于向 Nacos 中添加配置
  • zk: 用于向 Zookeeper 中添加配置,脚本依赖 Zookeeper 的相关脚本,需要手动下载;ZooKeeper相关的配置可以写在 zk-params.txt 中,也可以在执行的时候输入
  • apollo: 向 Apollo 中添加配置,Apollo 的地址端口等可以写在 apollo-params.txt,也可以在执行的时候输入
  • etcd3: 用于向 Etcd3 中添加配置
  • consul: 用于向 consul 中添加配置

我按这个文档,找了下相关的脚本地址:https://github.com/seata/seata/tree/develop/script/client

这里我把undo_log的脚本贴在下面:

-- for AT mode you must to init this sql for you business database. the seata server not need it.
CREATE TABLE IF NOT EXISTS `undo_log`
(
    `branch_id`     BIGINT(20)   NOT NULL COMMENT 'branch transaction id',
    `xid`           VARCHAR(100) NOT NULL COMMENT 'global transaction id',
    `context`       VARCHAR(128) NOT NULL COMMENT 'undo_log context,such as serialization',
    `rollback_info` LONGBLOB     NOT NULL COMMENT 'rollback info',
    `log_status`    INT(11)      NOT NULL COMMENT '0:normal status,1:defense status',
    `log_created`   DATETIME(6)  NOT NULL COMMENT 'create datetime',
    `log_modified`  DATETIME(6)  NOT NULL COMMENT 'modify datetime',
    UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
) ENGINE = InnoDB
  AUTO_INCREMENT = 1
  DEFAULT CHARSET = utf8 COMMENT ='AT transaction mode undo table';
  1. 修改registry.conf的注册中心和配置中心为nacos
registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "nacos"
  loadBalance = "RandomLoadBalance"
  loadBalanceVirtualNodes = 10

  nacos {
    application = "seata-server"
    serverAddr = "127.0.0.1:8848"
    group = "SEATA_GROUP"
    namespace = ""
    cluster = "default"
    username = ""
    password = ""
  }
  eureka {
    serviceUrl = "http://localhost:8761/eureka"
    application = "default"
    weight = "1"
  }
  redis {
    serverAddr = "localhost:6379"
    db = 0
    password = ""
    cluster = "default"
    timeout = 0
  }
  zk {
    cluster = "default"
    serverAddr = "127.0.0.1:2181"
    sessionTimeout = 6000
    connectTimeout = 2000
    username = ""
    password = ""
  }
  consul {
    cluster = "default"
    serverAddr = "127.0.0.1:8500"
  }
  etcd3 {
    cluster = "default"
    serverAddr = "http://localhost:2379"
  }
  sofa {
    serverAddr = "127.0.0.1:9603"
    application = "default"
    region = "DEFAULT_ZONE"
    datacenter = "DefaultDataCenter"
    cluster = "default"
    group = "SEATA_GROUP"
    addressWaitTime = "3000"
  }
  file {
    name = "file.conf"
  }
}

config {
  # file、nacos 、apollo、zk、consul、etcd3
  type = "nacos"

  nacos {
    serverAddr = "127.0.0.1:8848"
    namespace = ""
    group = "SEATA_GROUP"
    username = ""
    password = ""
  }
  consul {
    serverAddr = "127.0.0.1:8500"
  }
  apollo {
    appId = "seata-server"
    apolloMeta = "http://192.168.1.204:8801"
    namespace = "application"
    apolloAccesskeySecret = ""
  }
  zk {
    serverAddr = "127.0.0.1:2181"
    sessionTimeout = 6000
    connectTimeout = 2000
    username = ""
    password = ""
  }
  etcd3 {
    serverAddr = "http://localhost:2379"
  }
  file {
    name = "file.conf"
  }
}
  1. 配置好之后,启动seata
# nohup sh seata-server.sh -p 8091 -h 127.0.0.1 -m file > seata.log &
-p 指定启动seata server的端口号。
-h 指定seata server所绑定的主机。
-m 事务日志、事务执行信息存储的方式,目前支持file(文件方式)、db(数据库方式,建表语句请查看config/db_store.sql、config/db_undo_log.sql)

启动之后可以在nacos的控制台上看到注册的服务:

seata 1.4安装与配置

相关标签: 其他 java