Nacos1.3.2 + Seata1.3.0 + MySQL8 + SpringCloud 排坑筆記

本文章主要是記錄這幾個組件的組合搭建, 以單機環境爲例, 集羣環境有待後續嘗試.
mysql

一. Nacos

下載地址: https://github.com/alibaba/nacos/releasesgit

1. 建立數據庫(MySQL): nacos_config, 運行 conf 文件夾下 nacos-mysql.sql 文件

2. 將 application.properties 文件中 db 屬性值修改成本身的數據庫相關信息

1603374721078

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

4. 到此就能夠運行 startup.cmd 啓動nacos了, 默認端口爲 8848, 能夠經過 http://localhost:8848/nacos 進行訪問, 默認用戶名/密碼: nacos/nacos

二. Seata

下載地址: https://github.com/seata/seata/releases/tag/v1.3.0github

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-centerweb

這一步跟1.0以前的版本不同, 下載的文件包中再也不包含config.txt等配置文件, 須要本身到github上進行下載. 需下載的文件有 config.txt 以及 nacos文件夾中的 nacos-config.shspring

這裏還有須要注意的地方就是 config.txt文件必須是在nacos-config.sh 文件的上一級目錄中, 並且說在的路徑不能有空格sql

例如:數據庫

  • D:\config.txt
  • D:\conf\nacos-config.sh

修改config.txt中相關配置
app

win環境下運行nacos-config.sh須要藉助git工具
spring-boot

當看到以下內容則表示已經添加完畢
工具

修改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. 這個錯誤提示了

相關文章
相關標籤/搜索