1. docker run
文档地址:http://seata.io/zh-cn/docs/ops/deploy-by-docker.html
第一步:运行
docker run -d --name seata-server -p 8091:8091 seataio/seata-server:1.4.2
第二步:使用docker cp命令,将容器中的配置文件拷贝出来。
docker cp seata-server:/seata-server/resources /usr/local/cargo/seata/seata-script
第三步:进入到seata-script文件夹,修改file.conf
vim file.conf
## transaction log store, only used in seata-server
store {
## store mode: file、db
## 修改此处为db
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) etc.
datasource = "druid"
## mysql/oracle/postgresql/h2/oceanbase etc.
dbType = "mysql"
driverClassName = "com.mysql.jdbc.Driver"
## 修改为自己数据库的ip、端口和库名
url = "jdbc:mysql://ip:port/seata_demo"
## 修改为自己数据库用户名
user = "user"
## 修改为自己数据库密码
password = "pass"
minConn = 5
maxConn = 30
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
}
第四步:修改registry.conf文件
registry {
# file、nacos 、eureka、redis、zk、consul、etcd3、sofa
## 修改为nacos,后面那些配置只要关注nacos就好,其他可以删掉
type = "nacos"
nacos {
## 注意,这里其实官网配置文件是有一个坑的,就是`nacos`的`application`配置,旧值为seata-server,我们需要修改为serverAddr
application = "seataAddr"
## 修改为Nacos服务器ip地址
serverAddr = "127.0.0.1"
## 修改为Nacos给Seata用的Namespace,需要上Nacos新建一个
namespace = "seata"
cluster = "default"
## 修改为Nacos的用户名
username = "nacos"
## 修改为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
## 修改为nacos
type = "nacos"
## 修改方法同上
nacos {
serverAddr = "127.0.0.1"
namespace = "seata"
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"
}
zk {
serverAddr = "127.0.0.1:2181"
sessionTimeout = 6000
connectTimeout = 2000
username = ""
password = ""
}
etcd3 {
serverAddr = "http://localhost:2379"
}
file {
name = "file.conf"
}
}
第五步:把修改好的配置文件拷贝回seata容器
docker cp /usr/local/cargo/seata/seata-script/registry.conf seata-server:/seata-server/resources
docker cp /usr/local/cargo/seata/seata-script/file.conf seata-server:/seata-server/resources
第六步: 重启seata-server容器
docker restart seata-server
配置注册到naocs
获取/seata/script/config-center/config.txt,修改配置信息
注意:也可以直接添加nacos配置文件,最少配置上面七项
将config.txt注册到nacos,本地下载seata源码
在对应文件夹下打开git窗口,执行相应命令
bash nacos-config.sh -h 47.128.132.224 -p 8848 -g uat -t seata
-h: host,默认值 localhost -p: port,默认值 8848 -g: 配置分组,默认值为 ‘SEATA_GROUP’
-t: 租户信息,对应 Nacos 的命名空间ID字段, 默认值为空 ‘’