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
View Code

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討論

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM