本文章主要是記錄這幾個組件的組合搭建, 以單機環境為例, 集群環境有待后續嘗試.
一. Nacos
1. 創建數據庫(MySQL): nacos_config, 運行 conf 文件夾下 nacos-mysql.sql 文件

2. 將 application.properties 文件中 db 屬性值修改為自己的數據庫相關信息

3. 將 bin/startup.cmd(Win10環境) 中的 MODE 屬性修改為 standalone (單機, 默認為集群, 啟動會報錯)

4. 到此就可以運行 startup.cmd 啟動nacos了, 默認端口為 8848, 可以通過 http://localhost:8848/nacos 進行訪問, 默認用戶名/密碼: nacos/nacos

二. Seata
1. 將 file.conf 中的 mode 修改為 db, 同時修改 db 中數據庫相關信息

2. 將 file.conf.example 中的 mode 修改為 db, 同時修改 db 中數據庫相關信息

3. 將 registry.conf 中的 registry 和 config 的type屬性修改為 nacos


4. 添加nacos配置
地址: https://github.com/seata/seata/tree/develop/script/config-center
這一步跟1.0之前的版本不一樣, 下載的文件包中不再包含config.txt等配置文件, 需要自己到github上進行下載. 需下載的文件有 config.txt 以及 nacos文件夾中的 nacos-config.sh
這里還有需要注意的地方就是 config.txt文件必須是在nacos-config.sh 文件的上一級目錄中, 而且說在的路徑不能有空格
例如:
- D:\config.txt
- D:\conf\nacos-config.sh
修改config.txt中相關配置

win環境下運行nacos-config.sh需要借助git工具

當看到如下內容則表示已經添加完畢

修改nacos配置列表中 store.db.url 的值

直到這個時候才可以運行 bin/seata-server.bat 啟動 seata

三. MySQL8
安裝步驟略
四. 創建SpringCloud項目
1. 導包
<dependencies>
<!-- nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- seata -->
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<version>1.3.0</version>
<!-- 這里需要排除自身的seata-all -->
<exclusions>
<exclusion>
<artifactId>seata-all</artifactId>
<groupId>io.seata</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- 導入與之前下載的seata版本一致的包 -->
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-all</artifactId>
<version>1.3.0</version>
</dependency>
<!-- feign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
2. application.yml
seata:
enabled: true
# 該屬性需要與前面config.txt文件中的service.vgroupMapping后的值保持一致
tx-service-group: my_test_tx_group
config:
type: nacos
nacos:
namespace:
serverAddr: 127.0.0.1:8848
group: SEATA_GROUP # 這個值未生效, 在nacos中依然為DEFAULT_GROUP, 待檢查原因
registry:
type: nacos
nacos:
# seata 在nacos中的服務名
application: seata-server
serverAddr: 127.0.0.1:8848
# 分組需和seate分組一致
group: SEATA_GROUP
項目正常啟動, 終於不會報 no available server to connect. 這個錯誤提示了
