Docker部署seata

 后端   大苹果   2024-01-18 18:00   1934

下载seata-server

seata-server

解压部署

目录结构

image.png

修改配置文件(conf/application.yml)

server:
  port: 7091

spring:
  application:
    name: seata-server
  cloud:
    nacos:
      discovery:
        server-addr: nocas-ip:8848
        ip: ${HOST:192.168.40.167}
        port: 8081
logging:
  config: classpath:logback-spring.xml
  file:
    path: ${log.home:${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: file
  registry:
    # support: nacos, eureka, redis, zk, consul, etcd3, sofa
    type: nacos
    nacos: # tc
      server-addr: nocas-ip:8848
      namespace: ""
      group: DEFAULT_GROUP
      application: seata-tc-server # tc服务在nacos中的服务名称
      cluster: SH
  store:
    # support: file 、 db 、 redis 、 raft
    mode: file
  #  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,/**/*.jpeg,/**/*.ico,/api/v1/auth/login,/metadata/v1/**

tar -zxvf seata-server-2.0.0.tar.gz
cd seata
docker build . --tag seata:v1.0
# 指定与nacos 同网络
# SEATA_IP 指定公网ip
docker run -d --network example_default --add-host=nocas-ip:192.168.40.167 --name seata-server -p 8091:8091 -p 7091:7091 -e SEATA_IP=192.168.40.167 seata:v1.0
# 查看日志
docker logs -f seata-server

客户端数据库创建undo_log表


CREATE TABLE `undo_log` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `branch_id` bigint(20) NOT NULL,
  `xid` varchar(100) NOT NULL,
  `context` varchar(128) NOT NULL,
  `rollback_info` longblob NOT NULL,
  `log_status` int(11) NOT NULL,
  `log_created` datetime NOT NULL,
  `log_modified` datetime NOT NULL,
  `ext` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

docker-compose部署seata

  • docker-compose.yml
version: "3.1"
services:
  seata-server:
     # 镜像
    image: seataio/seata-server:1.5.2
    ports:
	# 宿主端口:容器端口
      - "7092:7091"
      - "8092:8092"
     # 环境变量
    environment:
      - STORE_MODE=db
      # 以SEATA_IP作为host注册seata server
      - SEATA_IP=192.168.40.167
      - SEATA_PORT=8092
      - STORE_MODE=file
    # 目录挂载
    volumes:
      - "/usr/share/zoneinfo/Asia/Shanghai:/etc/localtime"        #设置系统时区
      - "/usr/share/zoneinfo/Asia/Shanghai:/etc/timezone"  #设置时区
      # 假设我们通过docker cp命令把资源文件拷贝到相对路径`./seata-server/resources`中
      # 如有问题,请阅读上面的[注意事项]以及[使用自定义配置文件]
      #- "./seata-server/resources:/seata-server/resources"
      - "./seata-server/resources:/seata-server/config"
    # 指定网络
    networks: 
      - example_default
# 指定已有网络
networks:
  example_default:
    external: true
  • application.yml
server:
  port: 7091
debug: false
spring:
  application:
    name: seata-server
  cloud:
    nacos:
      server-addr: 172.22.0.2:8848
seata:
  config:
    # support: nacos, consul, apollo, zk, etcd3
    type: file
    # nacos:
    #   server-addr: 172.22.0.2:8848
    #   namespace: 
    #   group: DEFAULT_GROUP
    #   username: nacos
    #   password: nacos
    #   data-id: seataServer.properties
  store:
    # support: file 、 db 、 redis 、 raft
    mode: file
  security:
    secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
    tokenValidityInMilliseconds: 1800000
    ignore:
      urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.jpeg,/**/*.ico,/api/v1/auth/login,/metadata/v1/**
  registry: # TC服务注册中心的配置,微服务根据这些信息去注册中心获取tc服务地址
    # 参考tc服务自己的registry.conf中的配置
    type: nacos
    nacos: # tc
      server-addr: 172.22.0.2:8848
      namespace: ""
      group: DEFAULT_GROUP
      application: seata-tc-server # tc服务在nacos中的服务名称
      cluster: HZ
  • 部署
docker compose up -d