centos7安装分布式事务框架seata
1.安装包及前置准备
- 需要先在虚拟机上安装运行nacos
- tar包准备
下载地址
我这里安装的是seata-server-1.4.0.tar.gz
2.上传
rz或者ftp工具上传
3.解压
tar -zxvf seata-server-1.4.0.tar.gz -C /usr/local
4.进入seata目录
目录结构如上图所示 接下来需要修改conf 目录里的配置
5.修改file.conf配置项
cd conf/
vim file.conf
修改如下
store {
## store mode: file、db、redis
mode = "db"
## file store property
file {
## store location dir
dir = "sessionStore"
# branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
maxBranchSessionSize = 16384
# globe session size , if exceeded throws exceptions
maxGlobalSessionSize = 512
# file buffer size , if exceeded allocate new buffer
fileWriteBufferCacheSize = 16384
# when recover batch read size
sessionReloadReadSize = 100
# async, sync
flushDiskMode = async
}
## 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://127.0.0.1:3306/seata"
user = "root"
password = "root"
minConn = 5
maxConn = 100
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
## redis store property
redis {
host = "127.0.0.1"
port = "6379"
password = ""
database = "0"
minConn = 1
maxConn = 10
maxTotal = 100
queryLimit = 100
}
}
6.修改registry.conf配置
vim registry.conf
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos"
loadBalance = "RandomLoadBalance"
loadBalanceVirtualNodes = 10
nacos {
application = "seata-server"
serverAddr = "127.0.0.1:8848"
group = "SEATA_GROUP"
namespace = ""
cluster = "default"
username = "nacos"
password = "nacos"
}
eureka {
serviceUrl = "http://localhost:8761/eureka"
application = "default"
weight = "1"
}
redis {
serverAddr = "localhost:6379"
db = 0
password = ""
cluster = "default"
timeout = 0
}
zk {
cluster = "default"
serverAddr = "127.0.0.1:2181"
sessionTimeout = 6000
connectTimeout = 2000
username = ""
password = ""
}
consul {
cluster = "default"
serverAddr = "127.0.0.1:8500"
}
etcd3 {
cluster = "default"
serverAddr = "http://localhost:2379"
}
sofa {
serverAddr = "127.0.0.1:9603"
application = "default"
region = "DEFAULT_ZONE"
datacenter = "DefaultDataCenter"
cluster = "default"
group = "SEATA_GROUP"
addressWaitTime = "3000"
}
file {
name = "file.conf"
}
}
config {
# file、nacos 、apollo、zk、consul、etcd3
type = "nacos"
nacos {
serverAddr = "127.0.0.1:8848"
namespace = ""
group = "SEATA_GROUP"
username = "nacos"
password = "nacos"
}
consul {
serverAddr = "127.0.0.1:8500"
}
apollo {
appId = "seata-server"
apolloMeta = "http://192.168.1.204:8801"
namespace = "application"
apolloAccesskeySecret = ""
}
zk {
serverAddr = "127.0.0.1:2181"
sessionTimeout = 6000
connectTimeout = 2000
username = ""
password = ""
}
etcd3 {
serverAddr = "http://localhost:2379"
}
file {
name = "file.conf"
}
}
7.下载资源目录
资源目录
点击上述链接下载该项目到本地
找到script/config-center/config.txt
修改内容如下
service.vgroupMapping.my_test_tx_group=default
service.default.grouplist=127.0.0.1:8091
service.enableDegrade=false
service.disableGlobalTransaction=false
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://192.168.251.100:3306/seata?useUnicode=true
store.db.user=root
store.db.password=root
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
8.进入script\config-center\nacos目录
9.执行sh命令
按住windows键输入git 点击 git bash
然后cd 到 D:\develop\seata\script\config-center\nacos 目录
最后执行下面命令
sh nacos-config.sh -h 192.168.251.100 -p 8848
10.nacos查看配置项
可以看到nacos 都有之前的config.txt中的配置了
11.启动Seata Server
- 先进入到指定目录
cd /usr/local/seata/bin/
- 执行命令
sh seata-server.sh -p 8091 -h 127.0.0.1
看到上述就执行成功了 此时我们回到nacos就可以看到该服务已经注册到nacos中了
- 支持的命令参数
12.最后补充
此时seata的安装就完成了 我们在项目中就可以使用分布式事务了
- 项目中需要引入seata的依赖
<!--seata的依赖-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>
- 项目中需要在application.yml中配置
seata:
registry:
# 配置seata的注册中心, 告诉seata client 怎么去访问seata server(TC)
type: nacos
nacos:
server-addr: 192.168.251.100:8848 # seata server 所在的nacos服务地址
application: seata-server # seata server 的服务名seata-server ,如果没有修改可以不配
username: nacos
password: nacos
group: SEATA_GROUP # seata server 所在的组,默认就是SEATA_GROUP,没有改也可以不配
config:
type: nacos
nacos:
server-addr: 192.168.251.100:8848
username: nacos
password: nacos
group: SEATA_GROUP
spring:
alibaba:
seata:
tx-service-group: my_test_tx_group #配置事务分组
- 使用@GlobalTransactional轻松搞定分布式事务
- 详细项目可参见我的码云