linux下seata1.2.0基于nacos1.3.1部署

部署:nacos

文档:https://nacos.io/zh-cn/docs/deployment.html

前提,安装JDK:https://blog.csdn.net/qq_22049773/article/details/95787772

一、官网下载压缩包

https://github.com/alibaba/nacos/releases

linux下seata1.2.0基于nacos1.3.1部署_第1张图片

二、解压压缩包

nacos-server-1.3.1.tar.gz上传到服务器的自定义目录中,并执行解压命令

tar -zxvf nacos-server-1.3.1.tar.gz

linux下seata1.2.0基于nacos1.3.1部署_第2张图片

 

三、创建Nacos数据库    注意:单例运行nacos时可以不用指定mysql,使用默认的debry数据库就可以

  • 注意nacos1.3.1以下版本不支持mysql8

  • 压缩包中sql脚本路径 /nacos/conf/nacos-mysql.sql

自己手动去创建nacos数据库,并执行官网的sql脚本建库建表

linux下seata1.2.0基于nacos1.3.1部署_第3张图片

四、 修改Nacos的配置文件  

打开配置项比编辑mysql配置

linux下seata1.2.0基于nacos1.3.1部署_第4张图片

#*************** Config Module Related Configurations ***************#
### If use MySQL as datasource:
spring.datasource.platform=mysql

### Count of DB:
db.num=1

### Connect URL of DB:
db.url.0=jdbc:mysql://192.168.164.31:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user=root
db.password=123456


#*************** Naming Module Related Configurations ***************#

五、启动Nacos

重点重点重点:启动前修改 startup.sh中的启动参数

linux下seata1.2.0基于nacos1.3.1部署_第5张图片

startup.sh -m standalone

访问nacos

http://192.168.164.35:8848/nacos

linux下seata1.2.0基于nacos1.3.1部署_第6张图片

整合使用教程:https://blog.csdn.net/zjcjava/article/details/88316190

关于dataid的配置:https://www.jianshu.com/p/8db1c16542db

部署:seata

一、下载Seata Server

下载seata的server编译启动程序,下载地址:https://github.com/alibaba/nacos/releases

Linux选择下载seata-server-1.2.0.tar.gz,Windows选择下载seata-server-1.2.0.zip。

二、解压Seata Server

tar -zxvf seata-server-1.2.0.tar.gz

三、修改配置文件

cd /seata/conf

1、registry.conf配置
默认情况下,seata-server的配置模式是file模式,这里选择db如下:

registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  #改为nacos,前面那些配置只有关注nacos就好,其余能够删掉
  type = "nacos" 

  nacos {
    #这里其实官网配置文件是有一个坑的,就是`nacos`的`application`配置,旧值为seata-server,咱们须要批改为serverAddr
    application = "serverAddr"
    serverAddr = "192.168.164.35:8848"  #改为Nacos服务器ip地址
    namespace = "public"  #改为Nacos给Seata用的Namespace,须要上Nacos新建一个,这里使用公共的public
    cluster = "default"
    username = "nacos"  #改为Nacos的用户名
    password = "nacos"  #改为Nacos的密码
  }
}

config {
  # file、nacos 、apollo、zk、consul、etcd3
  #改为nacos,前面那些配置只有关注nacos就好,其余能够删掉
  type = "nacos"

  #同上修改
  nacos {
    serverAddr = "192.168.164.35:8848"
    namespace = "public"
    group = "SEATA_GROUP"
    username = "nacos"
    password = "nacos"
  }
}

2、修改file.conf配置


## transaction log store, only used in seata-server
store {
  ## store mode: file、db
  mode = "db"

  ## database store property
  db {
    ## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp) etc.
    datasource = "druid"
    ## mysql/oracle/postgresql/h2/oceanbase etc.
    dbType = "mysql"
    driverClassName = "com.mysql.jdbc.Driver"
    url = "jdbc:mysql://192.168.164.31:3306/seata"
    user = "root"
    password = "123456"
    minConn = 5
    maxConn = 30
    globalTable = "global_table"
    branchTable = "branch_table"
    lockTable = "lock_table"
    queryLimit = 100
    maxWait = 5000
  }
}

3、创建seata库并建表

/*
Navicat MySQL Data Transfer

Source Server         : MkzCloud
Source Server Version : 80020
Source Host           : 10.101.128.148:3306
Source Database       : mkz_seata

Target Server Type    : MYSQL
Target Server Version : 80020
File Encoding         : 65001

Date: 2020-05-06 17:20:42
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for branch_table
-- 分支事务表
-- ----------------------------
DROP TABLE IF EXISTS `branch_table`;
CREATE TABLE `branch_table` (
  `branch_id` bigint NOT NULL,
  `xid` varchar(128) NOT NULL,
  `transaction_id` bigint DEFAULT NULL,
  `resource_group_id` varchar(32) DEFAULT NULL,
  `resource_id` varchar(256) DEFAULT NULL,
  `branch_type` varchar(8) DEFAULT NULL,
  `status` tinyint 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 DEFAULT NULL,
  `status` tinyint NOT NULL,
  `application_id` varchar(32) DEFAULT NULL,
  `transaction_service_group` varchar(32) DEFAULT NULL,
  `transaction_name` varchar(128) DEFAULT NULL,
  `timeout` int DEFAULT NULL,
  `begin_time` bigint 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 DEFAULT NULL,
  `branch_id` bigint 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;

使用到seata分布式事务的所有业务库(订单库、积分库、商品库)中都要新建一张undo_log表,记录回滚日志(记录通过整合前置镜像SQL和后置镜像SQL所得的回滚SQL)

-- 注意此处0.3.0+ 增加唯一索引 ux_undo_log
CREATE TABLE `undo_log` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `branch_id` bigint(20) NOT NULL,
  `xid` varchar(100) NOT NULL,
  `rollback_info` longblob NOT NULL,
  `log_status` int(11) NOT NULL,
  `log_created` datetime NOT NULL,
  `log_modified` datetime NOT NULL,
  `ext` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

 

4、下载源码:https://github.com/seata/seata/tree/1.2.0

linux下seata1.2.0基于nacos1.3.1部署_第7张图片

linux下seata1.2.0基于nacos1.3.1部署_第8张图片

将 config.txt 和nacos-config.sh 放到linux中,(可以放到任何位置,只要这两个文件在同一级目录下即可)nacos目录下,自己创建一个other目录

并且赋予nacos-config.sh执行权限

chmod +x nacos-config.sh

linux下seata1.2.0基于nacos1.3.1部署_第9张图片

修改config.txt文件

transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.enableClientBatchSendRequest=false
transport.threadFactory.bossThreadPrefix=NettyBoss
transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker
transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler
transport.threadFactory.shareBossWorker=false
transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector
transport.threadFactory.clientSelectorThreadSize=1
transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread
transport.threadFactory.bossThreadSize=1
transport.threadFactory.workerThreadSize=default
transport.shutdown.wait=3
#所有须要用到Seata的微服务名,须要跟微服务中Seata的配置统一
service.vgroupMapping.my_test_tx_group=default
service.vgroupMapping.my_order_tx_group=default
service.vgroupMapping.my_goods_tx_group=default
service.vgroupMapping.my_product_tx_group=default
service.default.grouplist=192.168.164.35:8091
service.enableDegrade=false
service.disableGlobalTransaction=false
client.rm.asyncCommitBufferLimit=10000
client.rm.lock.retryInterval=10
client.rm.lock.retryTimes=30
client.rm.lock.retryPolicyBranchRollbackOnConflict=true
client.rm.reportRetryCount=5
client.rm.tableMetaCheckEnable=false
client.rm.sqlParserType=druid
client.rm.reportSuccessEnable=false
client.rm.sagaBranchRegisterEnable=false
client.tm.commitRetryCount=5
client.tm.rollbackRetryCount=5
#修改为db模式
store.mode=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.jdbc.Driver
store.db.url=jdbc:mysql://192.168.164.31:3306/seata?useUnicode=true
store.db.user=root
store.db.password=123456
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
server.recovery.committingRetryPeriod=1000
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
server.recovery.timeoutRetryPeriod=1000
server.maxCommitRetryTimeout=-1
server.maxRollbackRetryTimeout=-1
server.rollbackRetryTimeoutUnlockEnable=false
client.undo.dataValidation=true
client.undo.logSerialization=jackson
server.undo.logSaveDays=7
server.undo.logDeletePeriod=86400000
client.undo.logTable=undo_log
client.log.exceptionRate=100
transport.serialization=seata
transport.compressor=none
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898

修改nacos-config.sh    指定config.txt位置

for line in $(cat config.txt | sed s/[[:space:]]//g); do

最后,执行nacos-config.sh,将配置信息注册号nacos中

./nacos-config.sh
bash nacos-config.sh -h nacos的ip -p nacos的端口 -g nacos上seata的group -t nacos上seata的namespace
## 例如
bash nacos-config.sh -h 127.0.0.1 -p 8848 -g seata -t SEATA_GROUP

 linux下seata1.2.0基于nacos1.3.1部署_第10张图片

四、启动seata

./seata-server.sh -p 8091 -h 192.168.164.35 -m db &

脚本参数:
-p 指定启动seata server的端口号。
-h 指定seata server所绑定的主机,这里配置要注意指定的主机IP要与业务服务内的配置文件保持一致,如:-h 192.168.1.10,业务服务配置文件内应该配置192.168.1.10,即使在同一台主机上也要保持一致。
-m 事务日志、事务执行信息存储的方式,目前支持file、db。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(springcloud,springboot,Dubbo,seata,nacos)