Ubuntu24.04利用Docker部署Seata2.6

Title Ubuntu24.04利用Docker部署Seata2.6
Framework Docker
User wy8817399@vip.qq.com
Id 93
Created 8/22/26, 7:40 PM
Modified 8/22/26, 7:40 PM
Published Yes
Content

1、假设所有容器都在Docker下。

2、Seata的目录在Docker/Seata路径下。

3、创建目录结构

mkdir -p /Docker/Seata/{seata-server,seata-namingserver,jars}
cd /Docker/Seata

 

4、从镜像提取 resources 和 libs

docker create --name seata-tmp apache/seata-server:2.6.0
docker cp seata-tmp:/seata-server/resources seata-server/
docker cp seata-tmp:/seata-server/libs        seata-server/
docker rm seata-tmp
docker create --name ns-tmp apache/seata-naming-server:2.6.0.jdk25
docker cp ns-tmp:/seata-naming-server/resources/application.yml seata-namingserver/
docker rm ns-tmp

 

5、修改 seata-server/resources/application.yml配置文件

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
server:
  port: 8091
spring:
  application:
    name: seata-server
  main:
    web-application-type: none
logging:
  config: classpath:logback-spring.xml
  file:
    path: ${log.home:${user.home}/logs/seata}
  extend:
    logstash-appender:
      # off by default
      enabled: false
      destination: 127.0.0.1:4560
    kafka-appender:
      # off by default
      enabled: false
      bootstrap-servers: 127.0.0.1:9092
      topic: logback_to_logstash
      producer:
        acks: 0
        linger-ms: 1000
        max-block-ms: 0
    metric-appender:
      # off by default
      enabled: false

seata:
  config:
    # support: nacos, consul, apollo, zk, etcd3
    type: file
  registry:
    # support: nacos, eureka, redis, zk, consul, etcd3, sofa, seata
    type: seata,nacos # ★ 默认是 file,改成双注册(与原生版一致)
    seata:
      server-addr: seata-namingserver:8081 # ★ 原生版是 192.168.20.140:8081
      cluster: default  # 两个容器都在 timeless 网络里,
      namespace: public # 用容器名互访(Docker DNS 解析)
      heartbeat-period: 5000
      username: seata
      password: seata
    nacos:
      application: seata-server
      server-addr: nacos:8848 # ★ 原生版是 192.168.20.140:8848
      group: SEATA_GROUP #    nacos 容器在 timeless 网络里,
      namespace: "" # container_name 是 nacos,直接用
      cluster: default
      username: nacos # 改成 Nacos 控制台的实际登录账号密码
      password: nacos               
  store:
    # support: file 、 db 、 redis 、 raft
    mode: db
    db:
      datasource: druid
      db-type: mysql
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://192.168.20.140:3306/seata?useSSL=true&serverTimezone=Asia/Shanghai
      user: seata
      password: seata
      min-conn: 5
      max-conn: 30
      global-table: global_table
      branch-table: branch_table
      lock-table: lock_table
      distributed-lock-table: distributed_lock
      query-limit: 100
      max-retry-size: 10
  server:
    service-port: 8091 #If not configured, the default is '${server.port} + 1000'

 

6、修改 seata-namingserver/application.yml配置文件

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
server:
  port: 8081
spring:
  threads:
    virtual:
      enabled: true
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher
  ai:
    mcp:
      server:
        protocol: streamable
        streamable-http:
          mcp-endpoint: /mcp
        name: mcp-server
        version: 1.0.0
  application:
    name: seata-namingserver
logging:
  config: classpath:logback-spring.xml
  file:
    path: ${log.home:${user.home}/logs/seata}
heartbeat:
  threshold: 90000
  period: 60000
console:
  # console username and password configuration
  user:
    username: seata # 主要就是改密码,线上环境不要用seata,seata
    password: seata
  # When the console is deployed independently, configure the namingserver address
#  namingserver:
#    protocol: http
#    addr:
#      - 127.0.0.1:8081
seata:
  security:
    secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
    tokenValidityInMilliseconds: 1800000
    csrf-ignore-urls: /naming/v1/**,/api/v1/naming/**
    ignore:
      urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.jpeg,/**/*.ico,/api/v1/auth/login,/version.json,/naming/v1/health,/error
  # MCP Server Configuration
  mcp:
    # Maximum query time interval, The unit is milliseconds, Default one day
    query:
      max-query-duration: 86400000

 

7、改造 seata-server/libs

cd /Docker/Seata/seata-server/libs

# ===== 改动 1:移出老 nacos-client(移到 jars/ 备份,别改名留在原地) =====
mv nacos-client-1.4.6.jar /Docker/Seata/jars/

# ===== 改动 2:放入 nacos-client 2.0.4 + 它的两个依赖 =====
# (Seata 2.6.0 自带的 1.4.6 只会调 Nacos v1 HTTP API,而 Nacos 3.x 彻底删除了 v1 API)
wget https://repo1.maven.org/maven2/com/alibaba/nacos/nacos-client/2.0.4/nacos-client-2.0.4.jar
wget https://repo1.maven.org/maven2/org/reflections/reflections/0.9.11/reflections-0.9.11.jar
wget https://repo1.maven.org/maven2/org/javassist/javassist/3.29.2-GA/javassist-3.29.2-GA.jar

# ===== 改动 3:放入 MySQL 驱动(放 libs 根目录!) =====
wget https://repo1.maven.org/maven2/com/mysql/mysql-connector-j/8.0.33/mysql-connector-j-8.0.33.jar

# ===== 确认 =====
ls -lh nacos-client* reflections* javassist* mysql-connector*
# nacos-client-2.0.4 约 14MB(gRPC+protobuf 打包在内,大是正常的)
# reflections 约 130KB,javassist 约 500KB,mysql-connector-j 约 2.4MB

 

8、修改docker-compose.yml文件

services:
  seata-namingserver:
    image: apache/seata-naming-server:2.6.0.jdk25
    container_name: seata-namingserver
    environment:
      - TZ=Asia/Shanghai
    ports:
      - "8081:8081"    # Web Console + MCP(/mcp)
    volumes:
      # 冒号左边是宿主机目录名(我们自己起的,与原生安装命名一致),
      # 右边是镜像内置的容器内路径 /seata-naming-server/...(改不了,照抄)
      - ./Seata/seata-namingserver/application.yml:/seata-naming-server/resources/application.yml
    restart: always
    networks:
      - timeless

  # ==================== seata-server(TC 主程序) ====================
  seata-server:
    image: apache/seata-server:2.6.0
    container_name: seata-server
    environment:
      - SEATA_IP=192.168.20.140       # ★★ 最容易踩的坑,见下方说明
      - SEATA_PORT=8091               # 遗留写法,2.x 实际不生效(端口由 yaml 的
                                     #   seata.server.service-port 决定),删掉也无影响
      - STORE_MODE=db
      - TZ=Asia/Shanghai
    ports:
      - "8091:8091"    # TC 事务端口(TM/RM 客户端连这个)
    volumes:
      - ./Seata/seata-server/resources:/seata-server/resources   # 配置(4.3 改好的)
      - ./Seata/seata-server/libs:/seata-server/libs             # 依赖(4.5 改好的)
    depends_on:                        # ★ 只管同 compose 内的 namingserver
      seata-namingserver:
        condition: service_started     # jib 镜像无健康检查,只等"启动"
    restart: on-failure                # ★★ 主力:Nacos 跨 compose 没法 depends_on,靠失败重试兜底
    networks:
      - timeless

networks:
  timeless:
    name: timeless
    driver: bridge

 

9、浏览器访问测试

http://192.168.20.140:8081/#/transaction/list