天天看點

Windowns10配置安裝Seata14.0(注冊中心和配置中心用的都是nacos)

翻來翻來csnd,倒騰了一天一夜,也沒看到一篇關于Windowns10下安裝配置nacos完整的解釋,都是缺胳膊少腿的,廢話不多說直接進入主題!!!

我的環境:window10+nacos2.0.2+seata1.4.0+git2.3.0+mysql8.0

安裝步驟:

  1. 安裝nacos(資料持久化在MySQL),此處省略
  2. 下載下傳windows版本的seata1.4.0安裝版本、源碼版本(源碼版本不下載下傳也行,等下說名用途)

    第一個是安裝包,第二個是源碼包,打開分布解壓就行

    Windowns10配置安裝Seata14.0(注冊中心和配置中心用的都是nacos)
  3. MySQL資料庫建立事務相關的庫和表

    在你的MySQL資料庫建立一個用處存儲tc事務相關屬性的庫:seata,然後打開指令行執行建表

-- The script used when storeMode is 'db' ----------
-- the table to store GlobalSession data
CREATE TABLE IF NOT EXISTS `global_table`
(
    `xid`                       VARCHAR(128) NOT NULL,
    `transaction_id`            BIGINT,
    `status`                    TINYINT      NOT NULL,
    `application_id`            VARCHAR(32),
    `transaction_service_group` VARCHAR(32),
    `transaction_name`          VARCHAR(128),
    `timeout`                   INT,
    `begin_time`                BIGINT,
    `application_data`          VARCHAR(2000),
    `gmt_create`                DATETIME,
    `gmt_modified`              DATETIME,
    PRIMARY KEY (`xid`),
    KEY `idx_gmt_modified_status` (`gmt_modified`, `status`),
    KEY `idx_transaction_id` (`transaction_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8;

-- the table to store BranchSession data
CREATE TABLE IF NOT EXISTS `branch_table`
(
    `branch_id`         BIGINT       NOT NULL,
    `xid`               VARCHAR(128) NOT NULL,
    `transaction_id`    BIGINT,
    `resource_group_id` VARCHAR(32),
    `resource_id`       VARCHAR(256),
    `branch_type`       VARCHAR(8),
    `status`            TINYINT,
    `client_id`         VARCHAR(64),
    `application_data`  VARCHAR(2000),
    `gmt_create`        DATETIME(6),
    `gmt_modified`      DATETIME(6),
    PRIMARY KEY (`branch_id`),
    KEY `idx_xid` (`xid`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8;

-- the table to store lock data
CREATE TABLE IF NOT EXISTS `lock_table`
(
    `row_key`        VARCHAR(128) NOT NULL,
    `xid`            VARCHAR(96),
    `transaction_id` BIGINT,
    `branch_id`      BIGINT       NOT NULL,
    `resource_id`    VARCHAR(256),
    `table_name`     VARCHAR(32),
    `pk`             VARCHAR(36),
    `gmt_create`     DATETIME,
    `gmt_modified`   DATETIME,
    PRIMARY KEY (`row_key`),
    KEY `idx_branch_id` (`branch_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8;
           
  1. 配置registry.conf

    在安裝包根目錄conf檔案夾有個registry.conf 檔案,打開并配置:注冊中心和配置中心

    **注冊中心:把seata注冊到nacos上。

    **配置中心:**出廠的時候預設設定是fiel,讀取conf目錄下本地的file.conf檔案,這個檔案是用來儲存TC事務的一些屬性的。如果設定配置中心為nacos,則不需要配置file.conf,但是需要配置config.txt(下面會說這個玩意哪裡來的)并上傳到nacos。我這是用的是nacos作為配置中心。

# **注冊中心**:
registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "nacos" #這裡寫nacos
  loadBalance = "RandomLoadBalance"
  loadBalanceVirtualNodes = 10
  nacos {
    application = "seata-server" #seata的服務名稱
    serverAddr = "localhost:8848" #nacos的位址和端口
    group = "SEATA_GROUP" #預設就行
    namespace = ""#預設就行
    username = "nacos" #nacos的賬号
    password = "nacos" #nacos的密碼
  }
  #省略了一堆代碼,往下拉
  ...
  ...
  ...
# **配置中心**:
config {
  # file、nacos 、apollo、zk、consul、etcd3
  type = "nacos" #寫nacos

  nacos {
    serverAddr = "localhost:8848" #nacos位址端口
    namespace = "" #預設空
    group = "SEATA_GROUP" #預設
    username = "nacos" #nacos賬号
    password = "nacos"  #nacos密碼
    dataId = "seata.properties" #這個可以都不寫,反正我寫了,也沒啥
  }
  
           
  1. 配置config.txt

    其實config.txt和file.conf檔案兩者的内容其實都是一樣的,隻是格式不一樣而已:這裡主要配置資料庫還有這個seata将用于哪個微服務。

    config.txt來源:1、seata源碼目錄script\config-center

    2、github

#mysql配置
store.mode=db #存儲類型db
store.file.dir=file_store/data
store.file.maxBranchSessionSize=16384
store.file.maxGlobalSessionSize=512
store.file.fileWriteBufferCacheSize=16384
store.file.flushDiskMode=async
store.file.sessionReloadReadSize=100
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.cj.jdbc.Driver #msyql8.0用這個驅動
store.db.url=jdbc:mysql://localhost:3306/seata
store.db.user=username
store.db.password=password
#service配置
service.vgroupMapping.my_test_tx_group=seata-order-service#這個得記住了,不能寫預設的
service.default.grouplist=127.0.0.1:8091
service.enableDegrade=false
service.disableGlobalTransaction=false
           

儲存!!!

6. 配置nacos

主要是命名空間的ID可以自定義也可以系統生成,建立後記住那串命名空間的ID号,等下要用。

Windowns10配置安裝Seata14.0(注冊中心和配置中心用的都是nacos)

7.git下上傳配置檔案

在對應的源碼目錄,也就是下面這個,打開git指令行

Windowns10配置安裝Seata14.0(注冊中心和配置中心用的都是nacos)

執行:

sh nacos/nacos-config.sh -h localhost -p 8848 -g SEATA_GROUP -t 命名空間ID -u nacos賬号 -w nacos密碼
           

說明:

-h:注冊中心nacos的IP

-p:注冊中心nacos端口

-g:配置分組,預設值為’SEATA_GROUP’j即可。

-t:對應Nacos的namespace ID字段。

-u:使用者名

-w:密碼

執行後如下,證明上傳完成。

Windowns10配置安裝Seata14.0(注冊中心和配置中心用的都是nacos)

打開nacos,可以看到,證明配置成功。

Windowns10配置安裝Seata14.0(注冊中心和配置中心用的都是nacos)
  1. 啟東seata:安裝檔案包的bin目錄下,cmd直接啟動seata-server.bat。
    Windowns10配置安裝Seata14.0(注冊中心和配置中心用的都是nacos)
    大功告成,可以開心的撸啦啦啦啦啦啦啦啦啦啦啦。