欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

docker中安装seata

程序员文章站 2022-06-23 14:58:54
1.获取镜像## 使用下面命令获取最新版本的镜像,此时我的最新版本是1.3.0 ## 或者可以使用docker pull seataio/seata-server:1.3.0t获取指定版本的镜像docker pull seataio/seata-server:latest2.运行容器并获取配置为方便我们对seata配置修改我们需要先运行下seata-server,然后将配置拷贝到宿主机中,完成之后删除之前配置并通过宿主机运行容器。## 运行容器docker run --name seata-...

1.获取镜像

## 使用下面命令获取最新版本的镜像,此时我的最新版本是1.3.0 
## 或者可以使用docker pull seataio/seata-server:1.3.0t获取指定版本的镜像
docker pull seataio/seata-server:latest

2.运行容器并获取配置

为方便我们对seata配置修改我们需要先运行下seata-server,然后将配置拷贝到宿主机中,完成之后删除之前配置并通过宿主机运行容器。

## 运行容器
docker run --name seata-server -p 8091:8091 -d  seataio/seata-server:latest
## 将容器中的配置拷贝到/usr/local/seata-1.3.0
docker cp seata-server:/seata-server /usr/local/seata-1.3.0
## 完成后就会在/usr/local/seata-1.3.0出现容器的配置,我们现在可以将原来容器停止并删除
docker stop seata-server
docekr rm seata-server

3.修改配置文件

进入目录/usr/local/seata-1.3.0/resources中修改file.conf和registry.conf中的内容
file.conf中的内容:

## transaction log store, only used in seata-server
store {
  ## store mode: file、db、redis
  mode = "db" ## 原来为file
 
  ## file store property
  file {
    ## store location dir
    dir = "sessionStore"
    # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
    maxBranchSessionSize = 16384
    # globe session size , if exceeded throws exceptions
    maxGlobalSessionSize = 512
    # file buffer size , if exceeded allocate new buffer
    fileWriteBufferCacheSize = 16384
    # when recover batch read size
    sessionReloadReadSize = 100
    # async, sync
    flushDiskMode = async
  }

  ## database store property
  db {
    ## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp)/HikariDataSource(hikari) etc.
    datasource = "druid"
    ## mysql/oracle/postgresql/h2/oceanbase etc.
    dbType = "mysql"
    driverClassName = "com.mysql.jdbc.Driver"
    ## 因为设置为db,所以需要选择数据库,这里设置数据库及密码,seata是需要创建的,默认的表是通过脚本运行得到的
    url = "jdbc:mysql://192.168.1.23:3306/seata"
    user = "root"
    password = "123456"
    minConn = 5
    maxConn = 30
    globalTable = "global_table"
    branchTable = "branch_table"
    lockTable = "lock_table"
    queryLimit = 100
    maxWait = 5000
  }

  ## redis store property
  redis {
    host = "127.0.0.1"
    port = "6379"
    password = ""
    database = "0"
    minConn = 1
    maxConn = 10
    queryLimit = 100
  }

registry.conf内容:

registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  ## 我们这里使用nacos作为注册中心,所以需要设置type为nacos并设置nacos的属性
  type = "nacos"
  nacos {
    application = "seata-server"
    serverAddr = "192.168.1.23:8848"
    group = "SEATA_GROUP"
    ## 这里的namespace是你nacos服务的namespace的data-id,设置那里,到时就会在那个namespace中
    namespace = "a1493ff3-a94b-4f76-91af-7999fabff7d5"
    cluster = "default"
    username = "nacos"
    password = "nacos"
  }
}

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

  file {
    name = "file.conf"
  }
}

这里配置完成后,需要初始化数据库,这里参考另一篇博客的第二步。

3.启动seata

docker run -d --restart always  --name  seata-server -p 8091:8091  -v /usr/local/seata-1.3.0:/seata-server -e SEATA_IP=192.168.1.23 -e SEATA_PORT=8091 seataio/seata-server:latest

第一次启动完成后,以后可以用docker restart <imageid>docker start <imageid>进行启动或者关闭

本文地址:https://blog.csdn.net/github_38924695/article/details/108998782