Seata Deployment (Centos and Docker)

1. Introduction

Seata is an open source distributed transaction framework. Committed to providing high-performance and easy-to-use distributed transaction services under the microservice architecture. Before Seata was open-sourced, the corresponding internal version of Seata had been playing the role of distributed and consistent middleware in the Alibaba economy, helping the economy to survive the Double 11 over the years and providing strong support for the business of each business unit . After years of precipitation and accumulation, commercial products have been sold on Alibaba Cloud and Financial Cloud successively. 2019.1 In order to create a more complete technology ecosystem and inclusive technology achievements, Seata officially announced that it is open source. In the future, Seata will help its technology to be more reliable and complete in the form of community co-construction.

Seta: https://seata.io/zh-cn/index.html

Seata's github address: https://github.com/seata/seata

Seata product modules

There are three major modules in Seata, namely TM, RM and TC. Among them, TM and RM are integrated with the business system as the client of Seata, and TC is independently deployed as the server of Seata.

  • TC (Transaction Coordinator) - The transaction coordinator maintains the state of global and branch transactions, and drives global transaction commit or rollback.

  • TM (Transaction Manager) - The transaction manager defines the scope of a global transaction: start a global transaction, commit or rollback a global transaction.

  • RM (Resource Manager) - The resource manager manages resources for branch transactions, talks to TCs to register branch transactions and report the status of branch transactions, and drives branch transaction commits or rollbacks.

2. Deployment

1. Centos deploys Seata

1) Download

Seata Server is TC, just download and start directly from the official warehouse, download address: https://github.com/seata/seata/releases

After downloading, extract the installation package to the CENTOS directory.

[root@docker_124 seata]# ls
bin  conf  Dockerfile  ext  lib  LICENSE  logs  script  target

2) Prepare the database

MySQL is used here, the table initialization script is in /script/server/dbthe directory of the installation package, and the corresponding script is mysql.sql

[root@docker_124 db]# pwd
/data/seata/script/server/db
[root@docker_124 db]# ls
mysql.sql  oracle.sql  postgresql.sql
[root@docker_124 db]#

Create a database seataand execute the script, the steps are omitted.

3) Configure NACOS

Create nacos configuration, dataId seataserver.properties, GroupSEATA_GROUP

Modify the configuration and fill in the storage configuration. Because the storage I am about to configure is Mysql, I only need to copy the database configuration. The configuration is at https://github.com/seata/seata/blob/develop/script/config-center/config. txt text copy

#These configurations are required if the `store mode` is `db`. If `store.mode,store.lock.mode,store.session.mode` are not equal to `db`, you can remove the configuration block.
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true&rewriteBatchedStatements=true
store.db.user=username
store.db.password=password
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.distributedLockTable=distributed_lock
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000

The introduction reference document link for each configuration https://seata.io/zh-cn/docs/user/configurations.html

4) Modify the configuration file

Modify the configuration confin the software directory application.yml(the configuration of the old version may be a configuration similar to json, and my new version is yaml), and a sample is provided in the same directory application.example.ymlfor reference

#  Copyright 1999-2019 Seata.io Group.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

# 服务商品
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
# 控制台的用户名密码,类似nacos
console:
  user:
    username: seata
    password: seata
seata:
	# 配置中心,使用nacos,并配置nacos的地址等
  config:
    # support: nacos, consul, apollo, zk, etcd3
    type: nacos
    nacos:
      server-addr: http://10.4.7.1:8848
      # namespace: 7392baed-d98b-48a4-8676-34e1b38eade6
      namespace: e2df44d5-bd8e-4135-9314-7315f633077e
      group: SEATA_GROUP
      username: nacos
      password: nacos
      ##if use MSE Nacos with auth, mutex with username/password attribute
      #access-key: ""
      #secret-key: ""
      data-id: seataServer.properties
  # 注册中心,使用nacos,并配置
  registry:
    # support: nacos, eureka, redis, zk, consul, etcd3, sofa
    type: nacos
    nacos:
      server-addr: http://10.4.7.1:8848
      # namespace: 7392baed-d98b-48a4-8676-34e1b38eade6
      namespace: e2df44d5-bd8e-4135-9314-7315f633077e
      group: SEATA_GROUP
      username: nacos
      password: nacos
      ##if use MSE Nacos with auth, mutex with username/password attribute
      #access-key: ""
      #secret-key: ""
      data-id: seataServer.properties
  # 存储,使用db,在nacos中配置了数据库的信息
  store:
    # support: file 、 db 、 redis
    mode: db
#  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

5) start

After configuration, you can execute the script binin the directory seata-server.shto start. After starting, access and http://ip:7091use seata/seatato log in

If there is a problem with startup, you can check it seata/logs/start.outfor troubleshooting

Some problems were encountered during the configuration and startup process:

  • Mysql must be reinstalled because of the sudden failure of dockerhub, and the remote access authority must be reconfigured, resulting in some problems that cannot connect to mysql
  • During the configuration application.yml, confignacos and nacos-related configurations are configured, but although the registry type is configured with nacos, the detailed configuration information of nacos is not configured, resulting in an localhost:8848inaccessible problem reported in the log.

2. Docker deploys Seata

The official document is here, also very detailed

http://seata.io/zh-cn/docs/ops/deploy-by-docker.html

1) Prepare the database and nacos

This part is the same as centos, the steps are omitted

2) Download the image and start it

To download the image, you can search for the image on the docker hub, do not use the default latest, it may not be the release version, and the jdk may be different.

I chose version 1.6.1

[root@docker_124 conf]# docker pull seataio/seata-server:1.6.1
1.6.1: Pulling from seataio/seata-server
001c52e26ad5: Pull complete
d9d4b9b6e964: Pull complete
2068746827ec: Pull complete
9daef329d350: Pull complete
d85151f15b66: Pull complete
52a8c426d30b: Pull complete
8754a66e0050: Pull complete
5ed2ec2d6ee2: Pull complete
b71086c56a63: Pull complete
1181f8e565af: Pull complete
6d058363682a: Pull complete
adc1f51855c8: Pull complete
5b571cda842d: Pull complete
Digest: sha256:07796d3dff51cc34f4980d55ecde87c5271a34824fe1eeea9ddb57dbfee6b9e6
Status: Downloaded newer image for seataio/seata-server:1.6.1
docker.io/seataio/seata-server:1.6.1

ps: I had a small episode when I downloaded the image on the mac. I can normally docker pull the image in my vmware, but it always retry in the mac. I don’t know why, so I use the command to export the image from the virtual machine docker save -o seata-server-1.6.1.tar seataio/seata-server:1.6.1. Then use it docker import seata-server-1.6.1.tar seataio/seata-server:1.6.1for image import in mac .

Start a temporary seata container and copy the configuration file from the container to the local directory

# 启动临时seata容器
docker run -d --name seata-serve seataio/seata-server:latest
# 导出配置文件
docker cp seata-serve:/seata-server/resources /Users/jiangwujie/files/docker-data/seata/config/resources

Modify application.yml, modify the nacos and db configuration to be the same as the centos configuration

Use the local directory to map the configuration directory of the seata container and start the seata container

docker run -d --name seata-server -p 8091:8091 -p 7091:7091 -v /Users/jiangwujie/files/docker-data/seata/config/resources:/seata-server/resources seataio/seata-server:1.6.1

If it does not start successfully, you can docker logs containerIdcheck the log by.

Because both nacos and mysql are started in docker, and to connect nacos and mysql in the other two docker containers in the seata container, I need to know the ip of nacos and mysql in the docker communication. There is a simple method : Execute the ip route command in the container, and the IP following the default via is the IP of the host machine.

docker run --rm busybox ip route
default via 172.17.0.1 dev eth0
172.17.0.0/16 dev eth0 scope link  src 172.17.0.6

In this way, the addresses of nacos and mysql configured in seata are 172.17.0.1:8848and respectively 172.17.0.1:3306.

After docker starts normally, you can http://localhost:7091access the seata console.

Reference documents:

  • docker deployment seata

    http://seata.io/zh-cn/docs/ops/deploy-by-docker.html

  • Import and export image containers

    https://blog.csdn.net/u010797364/article/details/120430270

  • Nacos achieves persistence through MySQL under Docker

    https://blog.csdn.net/Fyf_010316/article/details/103816599

  • Docker connects to the host's MySQL

    https://blog.csdn.net/xs18952904/article/details/106518424

Guess you like

Origin blog.csdn.net/wejack/article/details/131862344