springcloud seata nacos环境搭建
Posted 学无终
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springcloud seata nacos环境搭建相关的知识,希望对你有一定的参考价值。
最近学习了一下seata,由于nacos现在也挺火,于是学习了seata注册到nacos,然后集成springcloud
1.nacos配置(自行上官网下载)
将nacos/conf/nacos-mysql.sql导入自己的数据库
2.配置修改nacos/conf/application.properties
1 spring.datasource.platform=mysql 2 db.num=1 3 db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true 4 db.user=root 5 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.sh nacos-config.py复制到seata的conf目录
git 命令框执行 sh nacos-config.sh hostip 即可,位置为什么这样自己看下脚本就知道了
配置都进来了,注意上面的红框,如果你网上搜的脚本导入的,seata是1.0及之前的版本上面是对的,如果1.1及最新的源码改成vgroupMapping了,报错参考另一篇博客
5.修改seata配置
修改file.conf
1 service { 2 #transaction service group mapping 3 vgroupMapping.my_tx_group="default" #此处根据自己的情况修改 4 default.grouplist="127.0.0.1:8091" 5 disableGlobalTransaction=false 6 } 7 ## transaction log store, only used in seata-server 8 store { 9 ## store mode: file、db 10 mode = "db" 11 12 ## file store property 13 file { 14 ## store location dir 15 dir = "sessionStore" 16 # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions 17 maxBranchSessionSize = 16384 18 # globe session size , if exceeded throws exceptions 19 maxGlobalSessionSize = 512 20 # file buffer size , if exceeded allocate new buffer 21 fileWriteBufferCacheSize = 16384 22 # when recover batch read size 23 sessionReloadReadSize = 100 24 # async, sync 25 flushDiskMode = async 26 } 27 28 ## database store property 29 db { 30 ## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp) etc. 31 datasource = "druid" 32 ## mysql/oracle/h2/oceanbase etc. 33 dbType = "mysql" 34 driverClassName = "com.mysql.jdbc.Driver" #不要用mysql8的驱动,否则报错 35 url = "jdbc:mysql://127.0.0.1:3306/seata" 36 user = "root" 37 password = "123456" 38 minConn = 1 39 maxConn = 10 40 globalTable = "global_table" 41 branchTable = "branch_table" 42 lockTable = "lock_table" 43 queryLimit = 100 44 } 45 }
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表每个库都要有
如果上面demo.zip跑不通请移步https://gitee.com/sharehappy/learn/tree/master/springcloud_seata下载代码或者进群:513650703讨论
以上是关于springcloud seata nacos环境搭建的主要内容,如果未能解决你的问题,请参考以下文章
SpringCloud第二季之Nacos,Sentinel,Seata以及雪花算法学习笔记
快速创建springboot+springcloud项目(nacos,seata,sentinel,gateway,openfeign)
SpringCloud - Spring Cloud Alibaba 之 Seata分布式事务服务;集成Nacos配置中心(十九)
SpringBoot+SpringCloud+Seata配置