seata1.4.2环境搭建

seata1.4.2环境搭建

官网地址
  • seata官网:http://seata.io/zh-cn/docs/overview/what-is-seata.html
  • seata Git : https://github.com/seata/seata/releases
  • seata v1.4.2:https://github.com/seata/seata/releases/tag/v1.4.2
下载文件

下载服务端服务和源码两个文件。seata-server-1.4.2.zip,seata-1.4.2.zip
在这里插入图片描述

下载后解压得到两个文件夹:
  • seata-1.4.2 源码文件夹
  • seata-server-1.4.2server 服务文件夹
    在这里插入图片描述
配置seata服务

配置文件目录D:\Desktop\seata-server-1.4.2\conf

修改registry.conf文件

注册方式有 file 、nacos 、eureka、redis、zk、consul、etcd3、sofa。

我们这次选择注册方式为nacos

  • 修改注册类型为nacos
  • 修改nacos的服务地址、命名空间、用户名和密码
registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "nacos"

  nacos {
    application = "seata-server"
    serverAddr = "12.3.34.3:8848"
    group = "SEATA_GROUP"
    namespace = "5ea6ba5e-5ba6-4fae-a7c7-9ce97b3a7541"
    cluster = "default"
    username = "nacos"
    password = "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"
    aclToken = ""
  }
  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 = "12.3.34.3:8848"
    namespace = "5ea6ba5e-5ba6-4fae-a7c7-9ce97b3a7541"
    group = "SEATA_GROUP"
    username = "nacos"
    password = "password"
    dataId = "seataServer.properties"
  }
  consul {
    serverAddr = "127.0.0.1:8500"
    aclToken = ""
  }
  apollo {
    appId = "seata-server"
    ## apolloConfigService will cover apolloMeta
    apolloMeta = "http://192.168.1.204:8801"
    apolloConfigService = "http://192.168.1.204:8080"
    namespace = "application"
    apolloAccesskeySecret = ""
    cluster = "seata"
  }
  zk {
    serverAddr = "127.0.0.1:2181"
    sessionTimeout = 6000
    connectTimeout = 2000
    username = ""
    password = ""
    nodePath = "/seata/seata.properties"
  }
  etcd3 {
    serverAddr = "http://localhost:2379"
  }
  file {
    name = "file.conf"
  }
}

修改file.conf文件

seata事物日志的存储方式:file、db、redis。file只适合单节点模式

这次我们先选择DB数据库模式

  • 修改mode为DB模式
  • 修改DB模块的配置:
    • mysql驱动,我的测试环境是8.0
    • mysql地址、用户名、密码
    • 注意:服务文件目录中含有mysql 5.X和8.X的两个数据库连接驱动。目录位置:D:\Desktop\seata-server-1.4.2\lib\jdbc。最好是把里面不使用的驱动移除或备份。我保留mysql-connector-java-8.0.19.jar。
## transaction log store, only used in seata-server
store {
  ## store mode: file、db、redis
  mode = "db"
  ## rsa decryption public key
  publicKey = ""
  ## file store property
  file {
    ## store location dir
    dir = "sessionStore"
    # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
    maxBranchSessionSize = 16384
    # globe session size , if exceeded throws exceptions
    maxGlobalSessionSize = 512
    # file buffer size , if exceeded allocate new buffer
    fileWriteBufferCacheSize = 16384
    # when recover batch read size
    sessionReloadReadSize = 100
    # async, sync
    flushDiskMode = async
  }

  ## 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://127.0.0.1:3306/seata?rewriteBatchedStatements=true&serverTimezone=GMT%2B8"
    user = "root"
    password = "admin"
    minConn = 5
    maxConn = 100
    globalTable = "global_table"
    branchTable = "branch_table"
    lockTable = "lock_table"
    queryLimit = 100
    maxWait = 5000
  }

  ## redis store property
  redis {
    ## redis mode: single、sentinel
    mode = "single"
    ## single mode property
    single {
      host = "127.0.0.1"
      port = "6379"
    }
    ## sentinel mode property
    sentinel {
      masterName = ""
      ## such as "10.28.235.65:26379,10.28.235.65:26380,10.28.235.65:26381"
      sentinelHosts = ""
    }
    password = ""
    database = "0"
    minConn = 1
    maxConn = 10
    maxTotal = 100
    queryLimit = 100
  }
}

在这里插入图片描述

创建mysql seata数据库

在这里插入图片描述

执行seataSQL脚本

获取脚本位置:

  • 最好选择下载的源码文件里面的SQL脚本,保持版本一致性。

  • seata源码文件夹。D:\Desktop\seata-1.4.2\script\server\db\mysql.sql

  • https://github.com/seata/seata/blob/develop/script/server/db/mysql.sql
    在这里插入图片描述

执行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_gmt_modified_status` (`gmt_modified`, `status`),
    KEY `idx_transaction_id` (`transaction_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8;

-- 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 = utf8;

-- 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),
    `gmt_create`     DATETIME,
    `gmt_modified`   DATETIME,
    PRIMARY KEY (`row_key`),
    KEY `idx_branch_id` (`branch_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8;

在这里插入图片描述

nacos导入配置文件
  • 首先配置导入脚本,D:\Desktop\seata-1.4.2\script\config-center\config.txt
  • 修改数据库配置
service.vgroupMapping.my_test_tx_group=default
store.mode=db
store.db.dbType=mysql
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true&rewriteBatchedStatements=true&serverTimezone=GMT%2B8
  • 进入nacos文件夹D:\Desktop\seata-1.4.2\script\config-center\nacos。执行命令
sh nacos-config.sh -h 12.3.34.3 -p 8848 -g SEATA_GROUP -t 5ea6ba5e-5ba6-4fae-a7c7-9ce97b3a7541 -u nacos -w password

在这里插入图片描述

在这里插入图片描述

  • 进入nacos控制台查看,配置文件自动添加
    在这里插入图片描述
启动seata服务
  • 进入bin目录。D:\Desktop\seata-server-1.4.2\bin。运行脚本即可。(脚本分为windows和Linux的)
    在这里插入图片描述

在这里插入图片描述

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值