Docker安裝配置Seata-Server

JavaEdge發表於2024-11-19

1 部署

官方文件指引

1.1 client

每個業務資料庫都要新建 undo_log 表。

對 springboot 應用,執行 client - MySQL - AT,切tag=1.5.2:

https://github.com/seata/seata/blob/v1.5.2/script/client/at/db/mysql.sql

1.2 server

新建 seata-for-hire 資料庫,執行 server - MySQL:

https://github.com/seata/seata/blob/v1.5.2/script/server/db/mysql.sql

2 Docker

拉取映象:

$ docker pull seataio/seata-server:1.5.2
1.5.2: Pulling from seataio/seata-server
e7c96db7181b: Already exists
f910a506b6cb: Already exists
b6abafe80f63: Pull complete
f9a900a85ba4: Pull complete
7d27a398a423: Pull complete
8fdfdcebe751: Pull complete
6df95cee0f43: Pull complete
5b571cda842d: Pull complete
Digest: sha256:90c7bae99eba72cdf42847b4812b2b03ade16eebfa33b87badd22a122542d647
Status: Downloaded newer image for seataio/seata-server:1.5.2
docker.io/seataio/seata-server:1.5.2

複製命令:

3 啟動容器

$ docker run --name seata-server \
-p 8091:8091 \
-d seataio/seata-server:1.5.2
8a83dd2dec376ad884cb83470e99ede3c91dfecb0d6d5d3f1f5dd747b4965d6c

$ docker ps
CONTAINER ID   IMAGE                        COMMAND                   CREATED          STATUS             PORTS                              NAMES
xx   seataio/seata-server:1.5.2   "xx"   51 seconds ago   Up 48 seconds      7091/tcp, 0.0.0.0:8091->8091/tcp   seata-server

4 配置

進入容器內部看配置檔案:

$ docker exec -it seata-server sh
/seata-server # ls -l
total 16
drwxr-xr-x    6 root     root          4096 Jan  1  1970 classes
drwxr-xr-x    1 root     root          4096 Jan  1  1970 libs
drwxr-xr-x    6 root     root          4096 Jan  1  1970 resources
drwxr-xr-x    2 root     root          4096 Jun 20 07:07 sessionStore


/seata-server # cd resources/
/seata-server/resources # ls -l
total 44
drwxr-xr-x    3 root     root          4096 Jan  1  1970 META-INF
-rw-r--r--    1 root     root          4471 Jan  1  1970 application.example.yml
-rw-r--r--    1 root     root           960 Jan  1  1970 application.yml
-rw-r--r--    1 root     root          2602 Jan  1  1970 logback-spring.xml

application.yml,要掛載它。退出容器,將剛才那個配置檔案複製到宿主機:

$ docker cp seata-server:/seata-server/resources /Users/javaedge/Downloads/soft/seata/
Successfully copied 64.5kB to /Users/javaedge/Downloads/soft/seata/

這就複製到我的宿主機了:

注意 nacos(基於 PC 本地下載的 nacos 原始碼構建啟動的) 的 ip:

修改新增這段配置:

server:
  port: 7091

spring:
  application:
    name: seata-server

logging:
  config: classpath:logback-spring.xml
  file:
    path: ${user.home}/logs/seata
  extend:
    logstash-appender:
      destination: 127.0.0.1:4560
    kafka-appender:
      bootstrap-servers: 127.0.0.1:9092
      topic: logback_to_logstash

console:
  user:
    username: seata
    password: seata

seata:
  config:
    # support: nacos, consul, apollo, zk, etcd3
    type: nacos
    nacos:
      server-addr: 172.17.0.2:8848
      namespace:
      group: SEATA_GROUP
      username: nacos
      password: nacos
  registry:
    # support: nacos, eureka, redis, zk, consul, etcd3, sofa
    type: nacos
    nacos:
      application: seata-server
      server-addr: 172.17.0.2:8848
      group: SEATA_GROUP
      namespace:
      cluster: default
      username: nacos
      password: nacos
  store:
    # support: file 、 db 、 redis
    mode: db
    db:
      datasource: druid
      db-type: mysql
      driver-class-name: com.mysql.jdbc.Driver
      url: jdbc:mysql://127.0.0.1:3306/seata-for-hire?rewriteBatchedStatements=true
      user: root
      password: 123456
      min-conn: 5
      max-conn: 100
      global-table: global_table
      branch-table: branch_table
      lock-table: lock_table
      distributed-lock-table: distributed_lock
      query-limit: 100
      max-wait: 5000
#  server:
#    service-port: 8091 #If not configured, the default is '${server.port} + 1000'
  security:
    secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
    tokenValidityInMilliseconds: 1800000
    ignore:
      urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login

rewriteBatchedStatements

預設 false。無論 'allowMultiQueries' 設定如何,驅動是否應使用多查詢,以及在呼叫 'executeBatch()' 時,是否應對 INSERT 和 REPLACE 型別的預備語句進行改寫,把它們變為多值子句語句?

如果使用的是非預處理的簡單宣告,並且沒有對輸入資料進行妥善清理,這可能導致 SQL 注入。此外,對預備語句,如在使用 'PreparedStatement.set*Stream()' 時沒有指定流長度,驅動將無法確定每批次的最優引數數量,並可能報錯說生成的資料包過大。 對於僅包括 INSERT 或 REPLACE 語句的批次重寫,'Statement.getGeneratedKeys()' 方法才有效果。

當同時用 "rewriteBatchedStatements=true"、"INSERT ... ON DUPLICATE KEY UPDATE" 對語句改寫時,伺服器對批次操作中所有受影響(或已找到)的行只會返回一個統一值,並且無法將之正確對映回最初的語句。此時,如果批次操作的總計數為零,驅動會為每一個批次語句返回 "0";如果總計數大於零,則返回 'Statement.SUCCESS_NO_INFO'。

Default Value false
Since Version 3.1.13

外部的配置檔案修改完畢後,還要掛載,需要重建容器:

javaedge@JavaEdgedeMac-mini resources % docker stop seata-server
seata-server

javaedge@JavaEdgedeMac-mini resources % docker rm seata-server
seata-server

啟動容器:

javaedge@JavaEdgedeMac-mini resources % docker run --name seata-server \
-p 8091:8091 \
-p 7091:7091 \
-v /Users/javaedge/Downloads/soft/seata/resources://seata-server/resources \
-d seataio/seata-server:1.5.2
455c1a2d108e4e533359bda66b6c7c909366e7536dfe4b5e451e97626743f2e4


javaedge@JavaEdgedeMac-mini resources % docker ps
CONTAINER ID   IMAGE                        COMMAND                   CREATED              STATUS              PORTS                                            NAMES
d2555578d828   seataio/seata-server:1.5.2   "java -Djava.securit…"   About a minute ago   Up About a minute   0.0.0.0:7091->7091/tcp, 0.0.0.0:8091->8091/tcp   seata-server

檢視容器內日誌,啟動成功:

成功註冊到 nacos:

關注我,緊跟本系列專欄文章,咱們下篇再續!

作者簡介:魔都架構師,多家大廠後端一線研發經驗,在分散式系統設計、資料平臺架構和AI應用開發等領域都有豐富實踐經驗。

各大技術社群頭部專家博主。具有豐富的引領團隊經驗,深厚業務架構和解決方案的積累。

負責:

  • 中央/分銷預訂系統效能最佳化
  • 活動&券等營銷中臺建設
  • 交易平臺及資料中臺等架構和開發設計
  • 車聯網核心平臺-物聯網連線平臺、大資料平臺架構設計及最佳化
  • LLM Agent應用開發
  • 區塊鏈應用開發
  • 大資料開發挖掘經驗
  • 推薦系統專案

目前主攻市級軟體專案設計、構建服務全社會的應用系統。

參考:

  • 程式設計嚴選網

本文由部落格一文多發平臺 OpenWrite 釋出!

相關文章