Seata 是一款開源的分布式事務解決方案,致力於在微服務架構下提供高性能和簡單易用的分布式事務服務。微服務中不可或缺的事務處理,缺少分布式事務管理就會存在數據不統一的情況。
一、下載Seata
地址:http://seata.io/zh-cn/blog/download.html
二、運行Seata
配置文件registry.conf中可以配置注冊中心,因為我要整合服務,之前使用的是nacos,所以這邊修改一下即可。
registry { # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa type = "nacos" nacos { application = "seata-server" serverAddr = "127.0.0.1:8848" group = "SEATA_GROUP" namespace = "" cluster = "default" 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" } ....... }
接着配置file.conf,個人是使用mysql,后期好整合項目,也可以直接file存儲。
sql文件地址:https://github.com/seata/seata/blob/1.2.0/script/server/db/mysql.sql
## transaction log store, only used in seata-server store { ## store mode: file、db、redis mode = "db" ## database store property db { ## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp)/HikariDataSource(hikari) etc. datasource = "druid" ## mysql/oracle/postgresql/h2/oceanbase etc. dbType = "mysql" driverClassName = "com.mysql.jdbc.Driver" url = "jdbc:mysql://xxx.xxx.xxx.xxx:3306/seata" user = "root" password = "123" minConn = 5 maxConn = 30 globalTable = "global_table" ## global_table、branch_table、lock_table這幾個表需要導入,否則會報錯 branchTable = "branch_table" lockTable = "lock_table" queryLimit = 100 maxWait = 5000 } ...... }
bin文件夾中就2個文件,window直接運行seata-server.bat,linux下可以命令運行
sh seata-server.sh
然后登陸http://127.0.0.1:8848/nacos/index.html中查看服務列表,就可以看到
三、總結
seata服務搭建異常順利,已沒有奇怪的bug,可能麻煩的是后面的整合到項目里才會有其他問題產生。