首页 > 编程语言 > Springcloud seata nacos环境搭建过程图解
2020
09-24

Springcloud seata nacos环境搭建过程图解

最近学习了一下seata,由于nacos现在也挺火,于是学习了seata注册到nacos,然后集成springcloud

1.nacos配置(自行上官网下载)

将nacos/conf/nacos-mysql.sql导入自己的数据库

2.配置修改nacos/conf/application.properties

spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=123456

3.启动nacos

windows直接双击startup.cmd

linux不要直接sh startup.sh 加入参数 -m standalone或者改startup.sh -m参数,linux脚本默认集群启动,不改参数也不加启动参数会报错

启动成功

4.下载seata,建议直接下载源码编译

mvn -Prelease-all -DskipTests clean install -U

5.使用db模式导入配置

上面是源码目录,mysql.sql为seata库必须的表,执行sql即可

将上面的config.txt文件复制到seata目录,nacos中的nacos-config.shnacos-config.py复制到seata的conf目录

git 命令框执行 sh nacos-config.sh hostip 即可,位置为什么这样自己看下脚本就知道了

配置都进来了,注意上面的红框,如果你网上搜的脚本导入的,seata是1.0及之前的版本上面是对的,如果1.1及最新的源码改成vgroupMapping了,报错参考另一篇博客

5.修改seata配置

修改file.conf

service {
  #transaction service group mapping
  vgroupMapping.my_tx_group="default" #此处根据自己的情况修改
  default.grouplist="127.0.0.1:8091"
  disableGlobalTransaction=false
}
## transaction log store, only used in seata-server
store {
 ## store mode: file、db
 mode = "db"

 ## 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) etc.
  datasource = "druid"
  ## mysql/oracle/h2/oceanbase etc.
  dbType = "mysql"
  driverClassName = "com.mysql.jdbc.Driver" #不要用mysql8的驱动,否则报错
  url = "jdbc:mysql://127.0.0.1:3306/seata"
  user = "root"
  password = "123456"
  minConn = 1
  maxConn = 10
  globalTable = "global_table"
  branchTable = "branch_table"
  lockTable = "lock_table"
  queryLimit = 100
 }
}

registry.conf

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

 nacos {
  serverAddr = "localhost:8848"
  namespace = ""
  cluster = "default"
 }


}

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

 nacos {
  serverAddr = "localhost"
  namespace = ""
  group = "SEATA_GROUP"
 }
}

然后将上面两个配置文件复制到你的springcloud模块中

6.启动seata

如果之前在其他ip启动过,将file_store/data下的文件清掉,不然会报错

7.springcloud代码

https://gitee.com/code_fun/example.git 把demo.zip下载跑就可以了,前提是建好数据库哦

demo.sql有表结构,undo_log表每个库都要有

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持自学编程网。

编程技巧