seata 的注册中心和配置中心

注册中心:

服务端注册中心(位于seata-server的registry.conf配置文件中的registry.type参数),为了实现seata-server集群高可用不会使用file类型,例如下边代码表示:使用zookeeper作为seata服务们的注册管理中心,当前seata服务将会交由这个zk管理

registry {
  # 可选用的类型file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  # 使用zookeeper作为seata服务的注册管理中心,则只看zk对应的配置
  type = "zk"

  nacos {
    application = "seata-server"
    serverAddr = "localhost"
    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 {
    # 疑问注册类型指定file,感觉这里name=file.conf毫无意义,难不成还能将服务交给一个文件管理啊!
    name = "file.conf"
  }
}

客户端注册中心(位于各个分布式项目中的registry.conf配置文件中的registry.type参数)其实指的是在哪里返现seata-server,因为为了支持HA高可用seata-server可能是集群的,比如交由zookeeper管理,那么客户端只需向zk去发现seata-server即可,例如配置:

registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  # 表示要找的seata-server位于zk中管理,去哪里找就好了
  type = "zk"

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

 

如果仅适用单一的seata-server,无需HA高可用的支持,可以使用file作为注册中心类型

 

配置中心:客户端配置和服务端配置,就是管理服务端和客户端关于seata的相关的参数设置,如果无需统一管理配置使用file即可,不会影响高可用,但最好也使用一个第三方配置中心 ,  举例:


config {
  # file、nacos 、apollo、zk、consul、etcd3、springCloudConfig
  # 读取配置参数的方式使用读取文件中的属性配置方式
  type = "file"

  nacos {
    serverAddr = "localhost"
    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"
  }
  zk {
    serverAddr = "127.0.0.1:2181"
    sessionTimeout = 6000
    connectTimeout = 2000
    username = ""
    password = ""
  }
  etcd3 {
    serverAddr = "http://localhost:2379"
  }
  file {
    # 配置属性位于同及目录下的file.conf文件中
    name = "file.conf"
  }
}

 

注意不推荐registry.type=file:因为当registry.type=file时,说明这里用的不是真正的注册中心,不具体集群内服务的健康检查机制当tc(seata-server)不可用时无法自动剔除列表,推荐使用nacos 、eureka、redis、zk、consul、etcd3、sofa。

registry.type=file或config.type=file 设计的初衷是让用户再不依赖第三方注册中心或配置中心的前提下,通过直连的方式,快速验证seata服务。

注意HA高可用说明如果使用了seata-server集群为了保证数据 的一直行,服务端的配置参数store.mode就不能使用file类型了,不然会报错。需要使用db类型,将集群中所有的seata-server的数据存储位置指向同一个DB或DB集群。如果DB使用mysql时使用过高版本可能会出现一些问题,之前使用mysql8.0作为db存储遇到些问题,降到5.x就好了

跟多配置参数参考 

 

展示一下我项目中的服务端和客户端的配置,仅供参考:

服务端registry.conf:

registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "zk"

  zk {
    cluster = "default"
    serverAddr = "192.168.5.1:2181"
    sessionTimeout = 6000
    connectTimeout = 2000
    username = ""
    password = ""
  }
}

config {
  # file、nacos 、apollo、zk、consul、etcd3
  type = "file"
  file {
    name = "file.conf"
  }
}

因为上边我使用的配置方式选的file【有点low但是不影响高可用的使用】,许指定一个文件,我写的是同级目录下的file.conf,所以需要服务端配置文件file.conf:

store {
  ## store mode: file、db
  ## 如果使用过高版本可能会出现一些问题,之前使用mysql8.0作为db存储遇到些问题,降到5.x就好了
  mode = "db"

  db {
    ## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp) etc.
    datasource = "druid"
    ## mysql/oracle/postgresql/h2/oceanbase etc.
    dbType = "mysql"
    driverClassName = "com.mysql.jdbc.Driver"
    url = "jdbc:mysql://192.168.5.101:3306/seata"
    user = "mysql"
    password = "mysql"
    minConn = 5
    maxConn = 30
    globalTable = "global_table"
    branchTable = "branch_table"
    lockTable = "lock_table"
    queryLimit = 100
    maxWait = 5000
  }
}

客户端registry.conf:

registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "zk"

  zk {
    serverAddr = "192.168.5.102:2181"
    sessionTimeout = 6000
    connectTimeout = 2000
    username = ""
    password = ""
  }
}

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

  file {
    name = "file.conf"
  }
}

同理配置方式选用的file方式file.conf:

transport {
  # tcp udt unix-domain-socket
  type = "TCP"
  #NIO NATIVE
  server = "NIO"
  #enable heartbeat
  heartbeat = true
  # the client batch send request enable
  enableClientBatchSendRequest = true
  #thread factory for netty
  threadFactory {
    bossThreadPrefix = "NettyBoss"
    workerThreadPrefix = "NettyServerNIOWorker"
    serverExecutorThread-prefix = "NettyServerBizHandler"
    shareBossWorker = false
    clientSelectorThreadPrefix = "NettyClientSelector"
    clientSelectorThreadSize = 1
    clientWorkerThreadPrefix = "NettyClientWorkerThread"
    # netty boss thread size,will not be used for UDT
    bossThreadSize = 1
    #auto default pin or 8
    workerThreadSize = "default"
  }
  shutdown {
    # when destroy server, wait seconds
    wait = 3
  }
  serialization = "seata"
  compressor = "none"
}
service {
  #transaction service group mapping
  vgroupMapping.my_test_tx_group = "default"
  #only support when registry.type=file, please don't set multiple addresses
  #只用registry.type=file时才是用default.grouplist,属性直连某个seata-server,且只能配置一个
  #default.grouplist = "192.168.5.105:8091"
  #degrade, current not support
  enableDegrade = false
  #disable seata
  disableGlobalTransaction = false
}

client {
  rm {
    asyncCommitBufferLimit = 10000
    lock {
      retryInterval = 10
      retryTimes = 30
      retryPolicyBranchRollbackOnConflict = true
    }
    reportRetryCount = 5
    tableMetaCheckEnable = false
    reportSuccessEnable = false
  }
  tm {
    commitRetryCount = 5
    rollbackRetryCount = 5
  }
  undo {
    dataValidation = true
    logSerialization = "jackson"
    logTable = "undo_log"
  }
  log {
    exceptionRate = 100
  }
}

参考项目地址(zk维护TC集群+zk作为dubbo的bean注册中心+dubbo+TC高可用+业务数据库mysql+TC管理数据DB模式使用的mysql):

链接:https://pan.baidu.com/s/1pa0Oh5aiAx8iQ5pYf_WGcA 
提取码:id8g

你可能感兴趣的:(seata 的注册中心和配置中心)