k8s高可用部署Seata

1.初始seata数据库

wget  https://raw.githubusercontent.com/apache/incubator-seata/1.3.0/script/server/db/mysql.sql
mysql -h rm-uf6ivpxt4j5rrpqal.mysql.rds.aliyuncs.com -uroot -p
CREATE DATABASE IF NOT EXISTS zdbl_seata_config DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;
use zdbl_seata_config;
source  /root/mysql.sql;
CREATE USER 'zdbl_seata'@'%' IDENTIFIED BY 'MXl#GX8hw0wEv!ID';
GRANT ALL PRIVILEGES ON zdbl_seata_config .* TO 'zdbl_seata'@'%';
FLUSH PRIVILEGES;
exit;

2.部署并配置seata

wget https://github.com/apache/incubator-seata/releases/download/v1.3.0/seata-server-1.3.0.tar.gz
tar xf seata-server-1.3.0.tar.gz -C /usr/local/
cd /usr/local/seata/conf/
cp registry.conf registry.conf-bak
cp file.conf.example file.conf

vim file.conf
store {
  ## store mode: file、db、redis
  mode = "db"

  db {
    datasource = "druid"
    dbType = "mysql"
    # 5.7 driverClassName = "com.mysql.jdbc.Driver"
    driverClassName = "com.mysql.cj.jdbc.Driver"
    url = "jdbc:mysql://rm-xxxxxxxxxx.mysql.rds.aliyuncs.com:3306/zdbl_seata_config?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8&rewriteBatchedStatements=true"
    user = "zdbl_seata"
    password = "Mxxxxxxxx!ID"
    minConn = 10
    maxConn = 50
    globalTable = "global_table"
    branchTable = "branch_table"
    lockTable = "lock_table"
    queryLimit = 200
    maxWait = 5000
  }

}

vim registry.conf #根据实际情况添加nacos配置

registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "nacos"

  nacos {
    application = "seata-server"
    serverAddr = "192.168.102.8:8848" #nacos 集群代理地址 TCP
    group = "SEATA_GROUP"
    namespace = "seata"
    cluster = "default"
    username = "nacos"
    password = "eMxxxxxxxxxJ"
  }
}

config {
  # file、nacos 、apollo、zk、consul、etcd3
  type = "nacos"

  nacos {
    serverAddr = "192.168.102.8:8848"
    namespace = "seata"
    group = "SEATA_GROUP"
    username = "nacos"
    password = "eM63S9V1QeXgLeRJ"
  }
}

3.添加nacos配置

下载项目:地址 https://github.com/apache/incubator-seata/tree/1.3.0

image

1.nacos控制台创建新的命名空间
命名空间名称 seata
命名空间ID seata
描述 seata

unzip -q incubator-seata-1.3.0.zip
cd incubator-seata-1.3.0/script
> config.txt
vim config.txt  #注释不能保留需要保留
service.vgroupMapping.direct-rent-group=default
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver #如果是MySQL8则为 com.mysql.cj.jdbc.Driver 
store.db.url=jdbc:mysql://rm-xxxxxxx.mysql.rds.aliyuncs.com:3306/seata?useUnicode=true&rewriteBatchedStatements=true #如果是MySQL8 serverTimezone需要serverTimezone=GMT%2B8 这么配置
store.db.user=seata
store.db.password=xxxx #密码包含特殊字符自带的脚本无法上传,所以需要先随便写再上传,上传后在nacos中修改,如果你的密码没有包含特殊字符则忽略
store.db.minConn=10
store.db.maxConn=100
store.db.queryLimit=100
store.db.maxWait=5000 
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.lockTable=lock_table
metrics.enabled=true
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898



cd config-center
sh nacos/nacos-config.sh -h 192.168.102.8 -p 8848 -g SEATA_GROUP -t seata -u nacos -w eM63S9V1QeXgLeRJ
#如果有报错请登录nacos修改,-t namesapce名称 -w nacos用户的密码

4.配置systemcd管理seata

vim /etc/systemd/system/seata.service
[Unit]
Description=Seata Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/seata/bin/seata-server.sh  -p 8091 -n 1  #每个节点不一样 -n:Server node。集群部署时需区分各自节点,用于生成不同区间的 transactionId 事务编号,以免冲突。
Restart=always

[Install]
WantedBy=multi-user.target


systemctl daemon-reload 
systemctl start seata.service 
systemctl status seata.service 
systemctl enable seata.service 
启动并验证服务
scp -q -r /usr/local/seata/ 192.168.200.102:/usr/local/
scp -q -r /usr/local/seata/ 192.168.200.103:/usr/local/
scp /etc/systemd/system/seata.service 192.168.200.103:/etc/systemd/system/  #注意修改Server node的值
scp /etc/systemd/system/seata.service 192.168.200.102:/etc/systemd/system/

image

 

5.添加监控

1.本地添加
vim file.conf
#新增以下配置
metrics {
  enabled = true
  registryType = "compact"
  exporterList = "prometheus"
  exporterPrometheusPort = 9898
}

1.5.0+中使用 application.yaml
seata:
  metrics:
    enabled: true
    registryType: compact
    exporterList: prometheus
    exporterPrometheusPort: 9898
    
2.使用nacos配置中心,如其他配置中心请参考文档    
将以下配置在nacos中添加
注意事项:
名称空间为seata dataId为键 配置内容为值 group为SEATA_GROUP  类型为Text
metrics.enabled=true
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898

6.注意事项

1.如果使用AT模式模式,则需要在对应的业务库中创建undo_log表,建表语句如下
CREATE TABLE IF NOT EXISTS `undo_log`
(
   `id`            BIGINT(20)   NOT NULL AUTO_INCREMENT COMMENT 'increment id',
   `branch_id`     BIGINT(20)   NOT NULL COMMENT 'branch transaction id',
   `xid`           VARCHAR(100) NOT NULL COMMENT 'global transaction id',
   `context`       VARCHAR(128) NOT NULL COMMENT 'undo_log context,such as serialization',
   `rollback_info` LONGBLOB     NOT NULL COMMENT 'rollback info',
   `log_status`    INT(11)      NOT NULL COMMENT '0:normal status,1:defense status',
   `log_created`   DATETIME     NOT NULL COMMENT 'create datetime',
   `log_modified`  DATETIME     NOT NULL COMMENT 'modify datetime',
   PRIMARY KEY (`id`),
   UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
) ENGINE = InnoDB
 AUTO_INCREMENT = 1
 DEFAULT CHARSET = utf8 COMMENT ='AT transaction mode undo table';
参考文档

 

 

 

 

 

posted @ 2026-03-18 09:35  百衲本  阅读(40)  评论(0)    收藏  举报
cnblogs_post_body { color: black; font: 0.875em/1.5em "微软雅黑" , "PTSans" , "Arial" ,sans-serif; font-size: 15px; } cnblogs_post_body h1 { text-align:center; background: #333366; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 23px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } cnblogs_post_body h2 { text-align:center; background: #006699; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 20px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } cnblogs_post_body h3 { background: #2B6695; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 18px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } 回到顶部 博客侧边栏 回到顶部 页首代码 回到顶部 页脚代码