您当前的位置: 首页 >  ar

cuiyaonan2000

暂无认证

  • 0浏览

    0关注

    248博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Launch Seata Searvice

cuiyaonan2000 发布时间:2021-07-14 16:09:02 ,浏览量:0

序言

根据Seata的流程图我们可以看到,他有个事务协调器(即TC),该协调器类似于我们的消息队列.是需要单独部署的cuiyaonan2000@163.com

针对版本为:1.4.0

如下图所示:

环境角色

Seata分TC、TM和RM三个角色.

在Seata的环境中TC想当时Service服务器,TM和RM相对于TC是Client

  • TC(Server端)为单独服务端部署  ----------此即为我们要部署的事务协调服务器.
  • TM和RM(Client端)由业务系统集成
Service的启动模式

Server端存储模式(store.mode)现有file、db、redis三种(后续将引入raft,mongodb)

如无意外Redis就是我们的主流模式.cuiyaonan2000@163.com

File模式(即TC的信息存储在文件系统上)
  • file模式为单机模式,全局事务会话信息内存中读写并持久化本地文件root.data,性能较高;
  • file模式无需改动,直接启动即可

 

DB&Redis模式

db模式为高可用模式,全局事务会话信息通过db共享,相应性能差些;

redis模式Seata-Server 1.3及以上版本支持,性能较高,存在事务信息丢失风险,请提前配置合适当前场景的redis持久化配置.

下载最新的安装包(非源码启动)

https://github.com/seata/seata/releases

建表(仅db)

全局事务会话信息由3块内容构成,全局事务-->分支事务-->全局锁,对应表global_table、branch_table、lock_table

修改store.mode

启动包: seata-->conf-->file.conf,修改store.mode="db或者redis" 源码: 根目录-->seata-server-->resources-->file.conf,修改store.mode="db或者redis"

修改数据库连接|redis属性配置

启动包: seata-->conf-->file.conf,修改store.db或store.redis相关属性。 源码: 根目录-->seata-server-->resources-->file.conf,修改store.db或store.redis相关属性。

启动
  • 源码启动: 执行Server.java的main方法
  • 命令启动: seata-server.sh -h 127.0.0.1 -p 8091 -m redis -n 1 -e test
启动参数说明 参数全写作用备注-h--host指定在注册中心注册的 IP不指定时获取当前的 IP,外部访问部署在云环境和容器中的 server 建议指定-p--port指定 server 启动的端口默认为 8091-m--storeMode事务日志存储方式支持file,db,redis,默认为 file 注:redis需seata-server 1.3版本及以上-n--serverNode用于指定seata-server节点ID如 1,2,3..., 默认为 1-e--seataEnv指定 seata-server 运行环境如 devtest 等, 服务启动时会使用 registry-dev.conf 这样的配置

搭建用例1
  1. 使用redis作为Tc的数据库
  2. Eureka作为注册中心
  3. file作为配置中心

file.conf修改

因为使用的file作为配置中心,所以相关的配置信息会从这个文件读取

如下修改2个地方:

  1. 启动模式修改成redis
  2. 配置redis的ip地址和端口
## transaction log store, only used in seata-server
store {
  ## store mode: file、db、redis
  mode = "redis"
  ## 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.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"
    user = "mysql"
    password = "mysql"
    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 = "192.168.137.100"
      port = "7001"
    }
    ## 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
  }
}

registry.conf

这里是配置seata的注册中心和配置中心的地方.很简单.

这里修改的地方:

  1.  注册中心的类型改成eureka,以及对应的eureka的地址
  2. 配置中心不用该直接读取本地的file.conf文件
registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "eureka"

  nacos {
    application = "seata-server"
    serverAddr = "127.0.0.1:8848"
    group = "SEATA_GROUP"
    namespace = ""
    cluster = "default"
    username = ""
    password = ""
  }
  eureka {
    serviceUrl = "http://192.168.137.100: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 = "file"

  nacos {
    serverAddr = "127.0.0.1:8848"
    namespace = ""
    group = "SEATA_GROUP"
    username = ""
    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"
  }
}

关注
打赏
1638267374
查看更多评论
立即登录/注册

微信扫码登录

0.0380s