最新版Seata的安装部署
部署TC服务
1、部署Seata的tc-server
1.1、下载
官网下载地址:https://seata.io/zh-cn/blog/download.html
1.2、数据库的创建
创建数据库名为
seatab
的数据库,运行下面的sql语句如果数据库的版本不同,那么部署tc服务的时候就需要指定不同的驱动以及连接方式
SET NAMES utf8mb4;SET FOREIGN_KEY_CHECKS = 0;-- ------------------------------ 分支事务表-- ----------------------------DROP TABLE IF EXISTS `branch_table`;CREATE TABLE `branch_table` ( `branch_id` bigint(20) NOT NULL, `xid` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `transaction_id` bigint(20) NULL DEFAULT NULL, `resource_group_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `resource_id` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `branch_type` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `status` tinyint(4) NULL DEFAULT NULL, `client_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `application_data` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `gmt_create` datetime(6) NULL DEFAULT NULL, `gmt_modified` datetime(6) NULL DEFAULT NULL, PRIMARY KEY (`branch_id`) USING BTREE, INDEX `idx_xid`(`xid`) USING BTREE) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;-- ------------------------------ 全局事务表-- ----------------------------DROP TABLE IF EXISTS `global_table`;CREATE TABLE `global_table` ( `xid` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `transaction_id` bigint(20) NULL DEFAULT NULL, `status` tinyint(4) NOT NULL, `application_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `transaction_service_group` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `transaction_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `timeout` int(11) NULL DEFAULT NULL, `begin_time` bigint(20) NULL DEFAULT NULL, `application_data` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `gmt_create` datetime NULL DEFAULT NULL, `gmt_modified` datetime NULL DEFAULT NULL, PRIMARY KEY (`xid`) USING BTREE, INDEX `idx_gmt_modified_status`(`gmt_modified`, `status`) USING BTREE, INDEX `idx_transaction_id`(`transaction_id`) USING BTREE) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;SET FOREIGN_KEY_CHECKS = 1;
1.3、 解压文件
文件说明:
bin ———-> 运行脚本
conf ———> 配置文件
lib ————>依赖库
logs ———> 日志文件
1.4、修改配置文件
上面下载的是最新版本的。新版的部署与旧版的不同,新版常用的是
yml
配置文件,旧版使用的是.conf
配置文件
新版部署如下:
打开
conf
配置文件,随即打开application.yml
和application.example.yml
两个配置文件进行修改
修改application.yml
配置文件的内容
主要是对于配置文件的读取和服务注册中心的指定使用什么和存储的方式
解读:
config:读取tc服务端的配置文件的方式,这里是从nacos配置中心读取,这样如果tc是集群,可以共享配置
registry:tc服务的注册中心类,这里选择nacos,也可以是eureka、zookeeper等
store:存储的方式,db为数据库存储,就是上面
1.2、数据库创建
的数据库
打开application.example.yml
文件中的参考配置方式,将对应的信息复制到application.yml
配置文件中的config
和registry
和store
下面,如下代码是修改后的application.xml
配置文件的信息
application.example.yml是一个举例文件,需要的可以复制到application.yml
文件中就会起效了
server: port: 7091spring: application: name: seata-serverlogging: config: classpath:logback-spring.xml file: path: ${user.home}/logs/seata extend: logstash-appender: destination: 127.0.0.1:4560 kafka-appender: bootstrap-servers: 127.0.0.1:9092 topic: logback_to_logstashconsole: user: username: seata password: seataseata: config: # support: nacos, consul, apollo, zk, etcd3 type: nacos nacos: server-addr: 127.0.0.1:8848 namespace: group: SEATA_GROUP username: nacos password: nacos ##if use MSE Nacos with auth, mutex with username/password attribute #access-key: "" #secret-key: "" data-id: seataServer.properties registry: # support: nacos, eureka, redis, zk, consul, etcd3, sofa type: nacos preferred-networks: 30.240.* nacos: application: seata-tc-server server-addr: 127.0.0.1:8848 group: DEFAULT_GROUP namespace: cluster: SH username: nacos password: nacos ##if use MSE Nacos with auth, mutex with username/password attribute #access-key: "" #secret-key: "" store: # support: file 、 db 、 redis mode: db db: datasource: druid db-type: mysql driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://127.0.0.1:13306/seata?useUnicode=true&rewriteBatchedStatements=true&serverTimezone=GMT user: mysql password: mysql min-conn: 5 max-conn: 100 global-table: global_table branch-table: branch_table lock-table: lock_table distributed-lock-table: distributed_lock query-limit: 100 max-wait: 5000# server:# service-port: 8091 #If not configured, the default is '${server.port} + 1000' security: secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017 tokenValidityInMilliseconds: 1800000 ignore: urls: /,//*.css,//*.js,//*.html,//*.map,//*.svg,//*.png,//*.ico,/console-fe/public/,/api/v1/auth/login
注意:
-
在
config
下会有很多个不同的配置,我们只需要保留一个nacos的配置,其他的全部去除 -
在
registry
下面的配置同理,选择什么保留什么 -
数据库的存储方式
下载下来的mysql驱动是没有
cj
的这个是修改的,如果使用的5.x版本的就不需要改,一定要对应数据库的连接信息
新版本的可以用在nacos中配置
旧版的配置如下:
修改conf目录下的
registry.conf
文件:
registry { # 服务中心 file 、nacos 、eureka、redis、zk、consul、etcd3、sofa type = "nacos" nacos { application = "seata-tc-server" serverAddr = "127.0.0.1:8848" group = "DEFAULT_GROUP" namespace = "" cluster = "SH" username = "nacos" password = "nacos" }}config { # 配置中心 file、nacos 、apollo、zk、consul、etcd3 type = "nacos" nacos { serverAddr = "127.0.0.1:8848" namespace = "" group = "SEATA_GROUP" username = "nacos" password = "nacos" dataId = "seataServer.properties" }}
在nacos添加配置
特别注意,为了让tc服务的集群可以共享配置,我们选择了nacos作为统一配置中心。因此服务端配置文件seataServer.properties文件需要在nacos中配好。
格式如下:
配置内容如下:
这里默认的mysql版本是5.x
# 数据存储方式,db代表数据库store.mode=dbstore.db.datasource=druidstore.db.dbType=mysqlstore.db.driverClassName=com.mysql.jdbc.Driverstore.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true&rewriteBatchedStatements=truestore.db.user=rootstore.db.password=123store.db.minConn=5store.db.maxConn=30store.db.globalTable=global_tablestore.db.branchTable=branch_tablestore.db.queryLimit=100store.db.lockTable=lock_tablestore.db.maxWait=5000# 事务、日志等配置server.recovery.committingRetryPeriod=3000server.recovery.asynCommittingRetryPeriod=3000server.recovery.rollbackingRetryPeriod=3000server.recovery.timeoutRetryPeriod=3000server.maxCommitRetryTimeout=-1server.maxRollbackRetryTimeout=-1server.rollbackRetryTimeoutUnlockEnable=falseserver.undo.logSaveDays=7server.undo.logDeletePeriod=86400000# 客户端与服务端传输方式transport.serialization=seatatransport.compressor=none# 关闭metrics功能,提高性能metrics.enabled=falsemetrics.registryType=compactmetrics.exporterList=prometheusmetrics.exporterPrometheusPort=9898
其中的数据库地址、用户名、密码都需要修改成你自己的数据库信息。
mysql8.x版本的配置信息如下:
mysql是8.0的,驱动类需要com.mysql.cj.jdbc.Driver,而不是com.mysql.jdbc.Driver。
在数据库的连接信息后面需要添加时区配置,否则也会报错
jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true&rewriteBatchedStatements=true&serverTimezone=GMT
1.5、启动方式
进入bin目录,运行其中的seata-server.bat即可: