1. 环境seata1.5.2. nacos2.1.0
本地配置好nacos之后
新建一个seata的命名空间,seata 需要使用
seata准备
1: 创建mysql的seata数据库 执行\seata-server-1.5.2\script\server\db\mysql.sql
2: 拷贝config.txt 从seata-server-1.5.2\script\config-center\config.txt 移动到seata-server-1.5.2\config.txt
修改2处地方 存储模式/ 数据库地址 https://www.exyb.cn/news/show-780131.html?action=onClick
store.mode=db store.db.url=jdbc:mysql://127.0.0.1:3306/demo-seata?useUnicode=true&rewriteBatchedStatements=true store.db.user=root store.db.password=123456
3.修改seata-server-1.5.2\conf\application.yml文件
server: port: 7091 spring: application: name: seata-server logging: 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_logstash console: user: username: seata password: seata seata: config: # support: nacos, consul, apollo, zk, etcd3 type: nacos nacos: server-addr: 127.0.0.1:8848 namespace: 4f4d5421-73ba-4a34-90b6-82b899ea2377 group: SEATA_GROUP username: nacos password: nacos data-id: seataServer.properties registry: # support: nacos, eureka, redis, zk, consul, etcd3, sofa type: nacos nacos: application: seata-server server-addr: 127.0.0.1:8848 namespace: 4f4d5421-73ba-4a34-90b6-82b899ea2377 group: SEATA_GROUP cluster: default username: nacos password: nacos store: # support: file 、 db 、 redis mode: db db: datasource: druid db-type: mysql driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/demo-seata?rewriteBatchedStatements=true&useUnicode=true user: root password: 123456 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
4. 上传config.txt配置到Nacos 执行脚本 \seata-server-1.5.2\script\config-center\nacos\目录右键在 Git Bash Here,执行以下脚本
sh -h nacosIP 。。
5. Srping boot配置seata, Nacos的seata命名空间增加dataId: service.vgroupMapping.demo_account_tx_group 值default
seata: application-id: ${spring.application.name} service: vgroup-mapping: demo_account_tx_group: default # 指定事务分组至集群映射关系,即映射到哪一个seata-server集群上,需与server端注册到Nacos的cluster保持一致 config: # support: nacos, consul, apollo, zk, etcd3 type: nacos nacos: server-addr: 127.0.0.1:8848 namespace: 4f4d5421-73ba-4a34-90b6-82b899ea2377 group: SEATA_GROUP username: nacos password: nacos registry: type: nacos nacos: server-addr: 127.0.0.1:8848 application: seata-server namespace: 4f4d5421-73ba-4a34-90b6-82b899ea2377 group: SEATA_GROUP username: nacos password: nacos tx-service-group: demo_account_tx_group
Spring Boot启动项目提示 RM注册成功
RM will register :jdbc:mysql://127.0.0.1:3306/seata_order 2023-09-26 09:34:59.684 INFO 14780 --- [ main] i.s.core.rpc.netty.NettyPoolableFactory : NettyPool create channel to transactionRole:RMROLE,address:192.168.16.134:8091,msg:< RegisterRMRequest{resourceIds='jdbc:mysql://127.0.0.1:3306/seata_order', applicationId='cloudalibaba-seata-order', transactionServiceGroup='demo_account_tx_group'} > 2023-09-26 09:34:59.693 INFO 14780 --- [ main] i.s.c.rpc.netty.RmNettyRemotingClient : register RM success. client version:1.5.1, server version:1.5.2,channel:[id: 0xc04eee32, L:/192.168.16.134:59333 - R:/192.168.16.134:8091] 2023-09-26 09:34:59.694 INFO 14780 --- [ main] i.s.core.rpc.netty.NettyPoolableFactory : register success, cost 8 ms, version:1.5.2,role:RMROLE,channel:[id: 0xc04eee32, L:/192.168.16.134:59333 - R:/192.168.16.134:8091] Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
然后使用@GloalTransation注解使用
标签:127.0,seata,0.1,db,nacos,server,naocs,使用,Seata From: https://www.cnblogs.com/eason-d/p/17729688.html