05 容器部署Seata

05 容器部署Seata

1 Docker 部署 Seata Server(1.4.2)

避免直接拉取latest版本镜像,latest版本并不一定是released版本,为避免不必要的问题,请到docker镜像仓库确定要拉取的镜像版本

1.1 快速开始

# 启动seata-server实例
docker run --name seata-server -p 8091:8091 seataio/seata-server:1.4.2

# 指定seata-server IP和端口 启动
docker run --name seata-server \
        -p 8091:8091 \
        -e SEATA_IP=192.168.1.1 \
        -e SEATA_PORT=8091 \
        seataio/seata-server

1.2 Docker compose 启动

# docker-compose.yaml 示例
version: "3"
services:
  seata-server:
    image: seataio/seata-server:${latest-release-version}
    hostname: seata-server
    ports:
      - "8091:8091"
    environment:
      - SEATA_PORT=8091
      - STORE_MODE=file

1.3 容器命令行及查看日志

docker exec -it seata-server sh
docker logs -f seata-server

1.4 使用自定义配置文件

自定义配置文件需要通过挂载文件的方式实现,将宿主机上的 registry.conf 和 file.conf 挂载到容器中相应的目录

1.4.1 指定 registry.conf

使用自定义配置文件时必须指定环境变量 SEATA_CONFIG_NAME, 并且值需要以file:开始, 如: file:/root/seata-config/registry

其中 -e 用于配置环境变量, -v 用于挂载宿主机的目录

docker run --name seata-server \
        -p 8091:8091 \
        -e SEATA_CONFIG_NAME=file:/root/seata-config/registry \
        -v /User/seata/config:/root/seata-config  \
        seataio/seata-server

1.4.1 指定 registry.conf

如果需要同时指定 file.conf 配置文件,则需要在 registry.conf 文件中将 config 配置改为以下内容,name 的值为容器中对应的路径

config {
  type = "file"

  file {
    name = "file:/root/seata-config/file.conf"
  }
}

1.5 环境变量

seata-server 支持以下环境变量:

SEATA_IP:可选, 指定seata-server启动的IP, 该IP用于向注册中心注册时使用, 如eureka等
SEATA_PORT:可选, 指定seata-server启动的端口, 默认为 8091
STORE_MODE:可选, 指定seata-server的事务日志存储方式, 支持db ,file,redis(Seata-Server 1.3及以上版本支持), 默认是 file
SERVER_NODE:可选, 用于指定seata-server节点ID, 如 1,2,3..., 默认为 根据ip生成
SEATA_ENV:可选, 指定 seata-server 运行环境, 如 dev, test 等, 服务启动时会使用 registry-dev.conf 这样的配置
SEATA_CONFIG_NAME:可选, 指定配置文件位置, 如 file:/root/registry, 将会加载 /root/registry.conf 作为配置文件,如果需要同时指定 file.conf文件,需要将registry.conf的config.file.name的值改为类似file:/root/file.conf

2 docker-compose 部署 Seata Server

3 Kubernetes 部署 Seata Server

3.1 快速启动

# 创建 seata-server.yaml
apiVersion: v1
kind: Service
metadata:
  name: seata-server
  namespace: default
  labels:
    k8s-app: seata-server
spec:
  type: NodePort
  ports:
    - port: 8091
      nodePort: 30091
      protocol: TCP
      name: http
  selector:
    k8s-app: seata-server

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: seata-server
  namespace: default
  labels:
    k8s-app: seata-server
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: seata-server
  template:
    metadata:
      labels:
        k8s-app: seata-server
    spec:
      containers:
        - name: seata-server
          image: docker.io/seataio/seata-server:latest
          imagePullPolicy: IfNotPresent
          env:
            - name: SEATA_PORT
              value: "8091"
            - name: STORE_MODE
              value: file
          ports:
            - name: http
              containerPort: 8091
              protocol: TCP

你可能感兴趣的:(分布式事务,docker,容器,运维)