Seata TC集羣搭建以及集成nacos

一、下載seata服務包,這裏通過GitHub下載,本文下載1.1.0版本

https://github.com/seata/seata/releases/download/v1.1.0/seata-server-1.1.0.tar.gz

解壓後目錄結構如下:

 

二、修改conf下的兩個配置文件 ,TC服務分單機和集羣模式,默認單機 file類型模式,我們需要配置成集羣多節點,和集成nacos,所以修改其兩個配置文件。

1.   修改file.conf文件如下,mode 改爲 db模式

2. 修改註冊中心配置,文件爲  registry.conf  ,如下有兩個地方需要修改,一個是registry和config

 三、因爲要使用到nacos作爲配置中心並且使用db的集羣模式,那麼就不會用到2.1中file.conf中的配置,需要手動把TC服務中的配置初始化到nacos中,那麼初始化配置文件從哪裏來,參考如下:

1. 從GitHub上面下載一份1.1.0版本的源碼,download  Zip包就行

Seata 1.1.0版本

2. 解壓後進入  \seata-1.1.0\script\config-center        目錄結構如下:

我們使用的nacos,初始化腳本命令 都在nacos目錄下,進入nacos目錄下 ,運行下面命令即可。

sh nacos-config.sh localhost:8848

我的nacos安裝在同一臺機器,所以用的localhost, 其他請做修改。

 

四、配置存入配置中心nacos後,進入nacos,修改其中的默認配置,主要是修改 store. 開頭的配置項,

比如存儲模式:store.mode

數據庫連接信息:store.db.url   store.db.user  store.db.password   

對應的信息在上面第二點中都有配置過,請仔細覈對。

 

五、創建Seata TC數據庫(這一步可以放到之前的任何地方做),數據庫名稱  seata

DROP TABLE IF EXISTS `branch_table`;
CREATE TABLE `branch_table` (
  `branch_id` bigint(20) NOT NULL,
  `xid` varchar(128) NOT NULL,
  `transaction_id` bigint(20) DEFAULT NULL,
  `resource_group_id` varchar(32) DEFAULT NULL,
  `resource_id` varchar(256) DEFAULT NULL,
  `branch_type` varchar(8) DEFAULT NULL,
  `status` tinyint(4) DEFAULT NULL,
  `client_id` varchar(64) DEFAULT NULL,
  `application_data` varchar(2000) DEFAULT NULL,
  `gmt_create` datetime(6) DEFAULT NULL,
  `gmt_modified` datetime(6) DEFAULT NULL,
  PRIMARY KEY (`branch_id`),
  KEY `idx_xid` (`xid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Table structure for global_table
-- ----------------------------
DROP TABLE IF EXISTS `global_table`;
CREATE TABLE `global_table` (
  `xid` varchar(128) NOT NULL,
  `transaction_id` bigint(20) DEFAULT NULL,
  `status` tinyint(4) NOT NULL,
  `application_id` varchar(32) DEFAULT NULL,
  `transaction_service_group` varchar(32) DEFAULT NULL,
  `transaction_name` varchar(128) DEFAULT NULL,
  `timeout` int(11) DEFAULT NULL,
  `begin_time` bigint(20) DEFAULT NULL,
  `application_data` varchar(2000) DEFAULT NULL,
  `gmt_create` datetime DEFAULT NULL,
  `gmt_modified` datetime DEFAULT NULL,
  PRIMARY KEY (`xid`),
  KEY `idx_gmt_modified_status` (`gmt_modified`,`status`),
  KEY `idx_transaction_id` (`transaction_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Table structure for lock_table
-- ----------------------------
DROP TABLE IF EXISTS `lock_table`;
CREATE TABLE `lock_table` (
  `row_key` varchar(128) NOT NULL,
  `xid` varchar(96) DEFAULT NULL,
  `transaction_id` bigint(20) DEFAULT NULL,
  `branch_id` bigint(20) NOT NULL,
  `resource_id` varchar(256) DEFAULT NULL,
  `table_name` varchar(32) DEFAULT NULL,
  `pk` varchar(36) DEFAULT NULL,
  `gmt_create` datetime DEFAULT NULL,
  `gmt_modified` datetime DEFAULT NULL,
  PRIMARY KEY (`row_key`),
  KEY `idx_branch_id` (`branch_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

六、集羣啓動,進入Linux  seata解壓目錄下,也就是第一點目錄下

1. 啓動第一個節點

[root@localhost seata]# nohup sh bin/seata-server.sh -p 18091 -n 1 &

執行 nohup sh bin/seata-server.sh -p 18091 -n 1 & 命令,啓動第一個 TC Server 在後臺。

-p:Seata TC Server 監聽的端口。
-n:Server node。在多個 TC Server 時,需區分各自節點,用於生成不同區間的 transactionId 事務編號,以免衝突

2. 啓動第二個節點

 執行 nohup sh bin/seata-server.sh -p 28091 -n 2 & 命令,啓動第二個 TC Server 在後臺

七、驗證集羣是否成功

 去nacos控制頁面查詢服務列表,是否有兩個健康節點

 

至此,seata 集羣模式部署完畢。歡迎指正!

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章