1. 程式人生 > 程式設計 >Springcloud seata nacos環境搭建過程圖解

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指令碼預設叢集啟動,不改引數也不加啟動引數會報錯

Springcloud seata nacos環境搭建過程圖解

啟動成功

4.下載seata,建議直接下載原始碼編譯

mvn -Prelease-all -DskipTests clean install -U

5.使用db模式匯入配置

Springcloud seata nacos環境搭建過程圖解

上面是原始碼目錄,mysql.sql為seata庫必須的表,執行sql即可

Springcloud seata nacos環境搭建過程圖解

將上面的config.txt檔案複製到seata目錄,nacos中的nacos-config.shnacos-config.py複製到seata的conf目錄

Springcloud seata nacos環境搭建過程圖解

git 命令框執行 sh nacos-config.sh hostip 即可,位置為什麼這樣自己看下指令碼就知道了

Springcloud seata nacos環境搭建過程圖解

配置都進來了,注意上面的紅框,如果你網上搜的指令碼匯入的,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

Springcloud seata nacos環境搭建過程圖解

如果之前在其他ip啟動過,將file_store/data下的檔案清掉,不然會報錯

7.springcloud程式碼

去https://gitee.com/code_fun/example.git 把demo.zip下載跑就可以了,前提是建好資料庫哦

demo.sql有表結構,undo_log表每個庫都要有

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。