Ubuntu24.04在jdk25的环境安装seata2.6(MySQL8+nacos3.2.3)

Title Ubuntu24.04在jdk25的环境安装seata2.6(MySQL8+nacos3.2.3)
Framework Ubuntu
User wy8817399@vip.qq.com
Id 91
Created 8/20/26, 9:20 PM
Modified 8/21/26, 9:24 PM
Published Yes
Content

1、创建目录

mkdir -p /Seata && cd /Seata

 

2、下载并解压

wget https://downloads.apache.org/incubator/seata/2.6.0/apache-seata-2.6.0-incubating-bin.tar.gz
tar -xzf apache-seata-2.6.0-incubating-bin.tar.gz
cd apache-seata-2.6.0-incubating-bin/seata-server

 

3、MySQL创建seata用户

mysql -uroot -p
-- 1. 建库
CREATE DATABASE IF NOT EXISTS seata DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

-- 2. 建用户并授权(Seata 专用账号,不要用 root)
CREATE USER IF NOT EXISTS 'seata'@'%' IDENTIFIED BY 'seata';
GRANT ALL PRIVILEGES ON seata.* TO 'seata'@'%';
FLUSH PRIVILEGES;

 

4、导入数据

cat > seata_server.sql <<'EOF'
-- 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.
--

-- -------------------------------- The script used when storeMode is 'db' --------------------------------
-- the table to store GlobalSession data
CREATE TABLE IF NOT EXISTS `global_table`
(
    `xid`                       VARCHAR(128) NOT NULL,
    `transaction_id`            BIGINT,
    `status`                    TINYINT      NOT NULL,
    `application_id`            VARCHAR(32),
    `transaction_service_group` VARCHAR(32),
    `transaction_name`          VARCHAR(128),
    `timeout`                   INT,
    `begin_time`                BIGINT,
    `application_data`          VARCHAR(2000),
    `gmt_create`                DATETIME,
    `gmt_modified`              DATETIME,
    PRIMARY KEY (`xid`),
    KEY `idx_status_gmt_modified` (`status` , `gmt_modified`),
    KEY `idx_transaction_id` (`transaction_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

-- the table to store BranchSession data
CREATE TABLE IF NOT EXISTS `branch_table`
(
    `branch_id`         BIGINT       NOT NULL,
    `xid`               VARCHAR(128) NOT NULL,
    `transaction_id`    BIGINT,
    `resource_group_id` VARCHAR(32),
    `resource_id`       VARCHAR(256),
    `branch_type`       VARCHAR(8),
    `status`            TINYINT,
    `client_id`         VARCHAR(64),
    `application_data`  VARCHAR(2000),
    `gmt_create`        DATETIME(6),
    `gmt_modified`      DATETIME(6),
    PRIMARY KEY (`branch_id`),
    KEY `idx_xid` (`xid`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

-- the table to store lock data
CREATE TABLE IF NOT EXISTS `lock_table`
(
    `row_key`        VARCHAR(128) NOT NULL,
    `xid`            VARCHAR(128),
    `transaction_id` BIGINT,
    `branch_id`      BIGINT       NOT NULL,
    `resource_id`    VARCHAR(256),
    `table_name`     VARCHAR(32),
    `pk`             VARCHAR(36),
    `status`         TINYINT      NOT NULL DEFAULT '0' COMMENT '0:locked ,1:rollbacking',
    `gmt_create`     DATETIME,
    `gmt_modified`   DATETIME,
    PRIMARY KEY (`row_key`),
    KEY `idx_status` (`status`),
    KEY `idx_branch_id` (`branch_id`),
    KEY `idx_xid` (`xid`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

CREATE TABLE IF NOT EXISTS `distributed_lock`
(
    `lock_key`       CHAR(20) NOT NULL,
    `lock_value`     VARCHAR(20) NOT NULL,
    `expire`         BIGINT,
    primary key (`lock_key`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0);


CREATE TABLE IF NOT EXISTS `vgroup_table`
(
    `vGroup`    VARCHAR(255),
    `namespace` VARCHAR(255),
    `cluster`   VARCHAR(255),
  UNIQUE KEY `idx_vgroup_namespace_cluster` (`vGroup`,`namespace`,`cluster`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;
EOF
mysql -uroot -p seata < seata_server.sql

 

5、配置seata-server的application.yml

# 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
    seata:
      server-addr: 192.168.20.140:8081   # 本机 namingserver
      cluster: default
      namespace: public
      heartbeat-period: 5000
      username: seata        # 和 namingserver 的 console.user 一致
      password: seata
    nacos:
      application: seata-server # 注册到 Nacos 的服务名(客户端按此名查找 TC)
      server-addr: 192.168.20.140:8848   # ★ Nacos连接地址
      group: SEATA_GROUP        # Nacos 中的分组名
      namespace: ""             # 命名空间 ID,留空 = public(注意:填 ID 不填名称)
      cluster: default          # 集群名,客户端配置必须与此一致
      username: nacos           # Nacos 控制台账号
      password: nacos           # 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                 # Step 4 创建的 Seata 专用账号
      password: seata             # 同上
      min-conn: 5                 # 最小连接数
      max-conn: 30                # 最大连接数
      global-table: global_table          # 对应的表名(和 DDL 一致,不用改)
      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、下载驱动。

cd /Seata/apache-seata-2.6.0-incubating-bin/seata-server/lib/jdbc
wget -P /Seata/seata-server/lib/jdbc/ https://repo1.maven.org/maven2/com/mysql/mysql-connector-j/8.0.33/mysql-connector-j-8.0.33.jar

# 1. 备份并移除老客户端(不能只改名留在 lib 里?其实改后缀为 .bak 即可,PropertiesLauncher 只认 .jar)  
mv nacos-client-1.4.6.jar nacos-client-1.4.6.jar.bak  
  
# 2. 下载 2.0.4(官方 PR #8097 指定的版本,走 gRPC 9848 端口,无需 v1 API)  
wget https://repo1.maven.org/maven2/com/alibaba/nacos/nacos-client/2.0.4/nacos-client-2.0.4.jar  
  
# 3. ★ nacos-client 2.x 多出两个依赖(reflections、javassist),Seata 发行包里没有,必须补上  
#    缺 reflections 会报 NoClassDefFoundError: org/reflections/Reflections  
#    缺 javassist   会报 NoClassDefFoundError: javassist/bytecode/ClassFile  
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  
  
# 4. 确认(nacos-client 2.0.4 约 14MB,reflections 约 130KB,javassist 约 500KB),然后重启 seata-server  
ls -lh nacos-client* reflections* javassist*

 

7、启动seata-server

cd /Seata/apache-seata-2.6.0-incubating-bin/seata-server/bin
./seata-server.sh

#当前情况如果要停服务
kill $(pgrep -f seata-server.jar) 2>/dev/null;

 

8、配置seata-namingserver的application.yml

cd /Seata/apache-seata-2.6.0-incubating-bin/seata-namingserver/conf
vim 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  #加上帐号密码
    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

 

9、启动seata-namingserver

cd /Seata/apache-seata-2.6.0-incubating-bin/seata-namingserver/bin
./seata-namingserver.sh

#当前情况如果要停服务
kill $(pgrep -f seata-namingserver.jar) 2>/dev/null;

 

10、浏览器验证

http://192.168.20.139:8081/

 

11、配 systemd 后台运行

# 先探测 JAVA_HOME(systemd 不读 profile,必须显式写入服务)
JAVA_HOME_PATH=$(dirname $(dirname $(readlink -f $(which java))))
echo "JAVA_HOME = $JAVA_HOME_PATH"

cat > /etc/systemd/system/seata.service << 'EOF'  
[Unit]  
Description=Seata Server (TC) 2.6.0  
After=network.target seata-namingserver.service docker.service  
Wants=seata-namingserver.service docker.service  
  
[Service]  
Type=forking  
Environment=JAVA_HOME=/usr/lib/jvm/jdk-25  
WorkingDirectory=/Seata/seata-server  
ExecStart=/Seata/seata-server/bin/seata-server.sh  
ExecStop=/Seata/seata-server/bin/seata-server.sh stop  
Restart=on-failure  
RestartSec=10  
LimitNOFILE=65536  
  
[Install]  
WantedBy=multi-user.target  
EOF
cat > /etc/systemd/system/seata-namingserver.service << 'EOF'  
[Unit]  
Description=Seata NamingServer (Console) 2.6.0  
After=network.target  
  
[Service]  
Type=forking  
Environment=JAVA_HOME=/usr/lib/jvm/jdk-25  
WorkingDirectory=/Seata/seata-namingserver  
ExecStart=/Seata/seata-namingserver/bin/seata-namingserver.sh  
ExecStop=/Seata/seata-namingserver/bin/seata-namingserver.sh stop  
Restart=on-failure  
RestartSec=10  
LimitNOFILE=65536  
  
[Install]  
WantedBy=multi-user.target  
EOF
# 加载刚加的service
systemctl daemon-reload
# 启动
systemctl start seata-namingserver
systemctl start seata
# 设置为开机自动启动
systemctl enable seata-namingserver seata