2022-12-31 17:33:47 +08:00
|
|
|
|
> 本文由 [简悦 SimpRead](http://ksria.com/simpread/) 转码, 原文地址 [developer.aliyun.com](https://developer.aliyun.com/article/913897)
|
|
|
|
|
|
|
|
|
|
> Docker 安装 Seata 分布式事务
|
|
|
|
|
|
|
|
|
|
1、简介
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
之前已经对分布式事务 Seata 做了详细介绍,可参考:
|
|
|
|
|
[分布式事务解决方案:Spring Cloud + Nacos + Seata 整合](https://yunfan.blog.csdn.net/article/details/123140907)
|
|
|
|
|
|
|
|
|
|
接下来直接上手,Docker 安装部署 Seata。
|
|
|
|
|
|
|
|
|
|
2、下载镜像
|
|
|
|
|
------
|
|
|
|
|
|
2023-01-02 02:16:21 +08:00
|
|
|
|
```shell
|
2022-12-31 17:33:47 +08:00
|
|
|
|
docker pull seataio/seata-server:1.4.2
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
3、启动容器
|
|
|
|
|
------
|
|
|
|
|
|
2023-01-02 02:16:21 +08:00
|
|
|
|
```shell
|
2022-12-31 17:33:47 +08:00
|
|
|
|
docker run -d --name seata-server -p 8091:8091 seataio/seata-server:1.4.2
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
4、拷贝文件
|
|
|
|
|
------
|
|
|
|
|
|
2023-01-02 02:16:21 +08:00
|
|
|
|
```shell
|
2022-12-31 17:33:47 +08:00
|
|
|
|
docker cp seata-server:/seata-server /docker-data/seata
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
5、修改配置文件
|
|
|
|
|
--------
|
|
|
|
|
|
|
|
|
|
(1)修改配置文件 / docker-data/seata/resources/registry.conf,改为 Nacos 信息。
|
|
|
|
|
|
2023-01-02 02:16:21 +08:00
|
|
|
|
```shell
|
2022-12-31 17:33:47 +08:00
|
|
|
|
registry {
|
|
|
|
|
|
|
|
|
|
type = "nacos"
|
|
|
|
|
|
|
|
|
|
nacos {
|
|
|
|
|
application = "seata-server"
|
|
|
|
|
serverAddr = "127.0.0.1:8848"
|
|
|
|
|
group = "SEATA_GROUP"
|
|
|
|
|
namespace = ""
|
|
|
|
|
cluster = "default"
|
|
|
|
|
username = "nacos"
|
|
|
|
|
password = "nacos"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
......
|
|
|
|
|
|
|
|
|
|
config {
|
|
|
|
|
|
|
|
|
|
type = "nacos"
|
|
|
|
|
|
|
|
|
|
nacos {
|
|
|
|
|
serverAddr = "127.0.0.1:8848"
|
|
|
|
|
namespace = ""
|
|
|
|
|
group = "SEATA_GROUP"
|
|
|
|
|
username = "nacos"
|
|
|
|
|
password = "nacos"
|
|
|
|
|
dataId = "seataServer.properties"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
(2)修改配置文件 / docker-data/seata/resources/file.conf,改为 DB 信息。
|
|
|
|
|
|
2023-01-02 02:16:21 +08:00
|
|
|
|
```shell
|
2022-12-31 17:33:47 +08:00
|
|
|
|
store {
|
|
|
|
|
|
|
|
|
|
mode = "db"
|
|
|
|
|
|
|
|
|
|
......
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db {
|
|
|
|
|
|
|
|
|
|
datasource = "druid"
|
|
|
|
|
|
|
|
|
|
dbType = "mysql"
|
|
|
|
|
driverClassName = "com.mysql.cj.jdbc.Driver"
|
|
|
|
|
|
|
|
|
|
url = "jdbc:mysql://localhost:3306/seata?rewriteBatchedStatements=true"
|
|
|
|
|
user = "root"
|
|
|
|
|
password = "root"
|
|
|
|
|
minConn = 5
|
|
|
|
|
maxConn = 100
|
|
|
|
|
globalTable = "global_table"
|
|
|
|
|
branchTable = "branch_table"
|
|
|
|
|
lockTable = "lock_table"
|
|
|
|
|
queryLimit = 100
|
|
|
|
|
maxWait = 5000
|
|
|
|
|
}
|
|
|
|
|
......
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
6、停掉旧容器
|
|
|
|
|
-------
|
|
|
|
|
|
2023-01-02 02:16:21 +08:00
|
|
|
|
```shell
|
2022-12-31 17:33:47 +08:00
|
|
|
|
docker stop seata-server
|
|
|
|
|
docker rm seata-server
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
7、启动新容器
|
|
|
|
|
-------
|
|
|
|
|
|
2023-01-02 02:16:21 +08:00
|
|
|
|
```shell
|
2022-12-31 17:33:47 +08:00
|
|
|
|
docker run -d \
|
|
|
|
|
--restart always \
|
|
|
|
|
--name seata-server \
|
|
|
|
|
-p 8091:8091 \
|
|
|
|
|
-v /docker-data/seata:/seata-server \
|
|
|
|
|
-e SEATA_IP=外网IP \
|
|
|
|
|
-e SEATA_PORT=8091 \
|
|
|
|
|
seataio/seata-server:1.4.2
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**注意:** 遇到的坑,如果是部署云服务器,没有设置 SEATA_IP,默认注册的是 docker 的内网 ip,seata 启动虽然没有问题,但是微服务项目启动连接时,会报错 can not register RM,err:can not connect to services-server.
|
|
|
|
|
|
|
|
|
|
8、查看 Nacos 注册情况
|
|
|
|
|
---------------
|
|
|
|
|
|
|
|
|
|
![](assets/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA56iL5bqP5ZGY5LqR5biG5ZOl,size_20,color_FFFFFF,t_70,g_se,x_16-16724774944563.png)
|