Linux installation and deployment of Seata

Title: Install and deploy Seata distributed transaction solution on Linux

insert image description here

Introduction: Seata is an open source distributed transaction solution designed to solve the transaction consistency problem in a distributed environment. This article will introduce you how to install and deploy Seata on the Linux operating system to add powerful transaction support to your distributed applications.

What is Seata?
Seata (Simple Extensible Autonomous Transaction Architecture) is a flexible, high-performance distributed transaction solution that can be used to support transaction consistency in a microservice architecture. Seata provides three distributed transaction modes: AT (automated transaction, similar to local transaction), TCC (Try-Confirm-Cancel, suitable for scenarios sensitive to business logic) and SAGA (suitable for long transactions and asynchronous scenarios) .

Step 1: Prepare before installation

Before starting to install Seata, make sure you have met the following prerequisites:

  • A server running Linux
  • Java JDK 8 or later
  • MySQL or other supported databases
  • Maven build tool
  • Nacos service

Step 2: Download and Build Seata

download link

  1. Open a terminal and download Seata's binaries with the following command:
wget https://github.com/seata/seata/releases/download/v1.7.0/seata-server-1.7.0.zip
  1. Extract the Seata file
unzip seata-server-1.7.0.zip

Step 3: Create the database

  1. Create a Seata database in MySQL
CREATE DATABASE seata CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
  1. Initialize the database, run seata/script/server/db/mysql.sqlthe file or directly run the following SQL
-- -------------------------------- The script used when storeMode is 'db' --------------------------------
-- the table to store GlobalSession data
CREATE TABLE IF NOT EXISTS `global_table`
(
    `xid`                       VARCHAR(128) NOT NULL,
    `transaction_id`            BIGINT,
    `status`                    TINYINT      NOT NULL,
    `application_id`            VARCHAR(32),
    `transaction_service_group` VARCHAR(32),
    `transaction_name`          VARCHAR(128),
    `timeout`                   INT,
    `begin_time`                BIGINT,
    `application_data`          VARCHAR(2000),
    `gmt_create`                DATETIME,
    `gmt_modified`              DATETIME,
    PRIMARY KEY (`xid`),
    KEY `idx_status_gmt_modified` (`status` , `gmt_modified`),
    KEY `idx_transaction_id` (`transaction_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

-- the table to store BranchSession data
CREATE TABLE IF NOT EXISTS `branch_table`
(
    `branch_id`         BIGINT       NOT NULL,
    `xid`               VARCHAR(128) NOT NULL,
    `transaction_id`    BIGINT,
    `resource_group_id` VARCHAR(32),
    `resource_id`       VARCHAR(256),
    `branch_type`       VARCHAR(8),
    `status`            TINYINT,
    `client_id`         VARCHAR(64),
    `application_data`  VARCHAR(2000),
    `gmt_create`        DATETIME(6),
    `gmt_modified`      DATETIME(6),
    PRIMARY KEY (`branch_id`),
    KEY `idx_xid` (`xid`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

-- the table to store lock data
CREATE TABLE IF NOT EXISTS `lock_table`
(
    `row_key`        VARCHAR(128) NOT NULL,
    `xid`            VARCHAR(128),
    `transaction_id` BIGINT,
    `branch_id`      BIGINT       NOT NULL,
    `resource_id`    VARCHAR(256),
    `table_name`     VARCHAR(32),
    `pk`             VARCHAR(36),
    `status`         TINYINT      NOT NULL DEFAULT '0' COMMENT '0:locked ,1:rollbacking',
    `gmt_create`     DATETIME,
    `gmt_modified`   DATETIME,
    PRIMARY KEY (`row_key`),
    KEY `idx_status` (`status`),
    KEY `idx_branch_id` (`branch_id`),
    KEY `idx_xid` (`xid`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

CREATE TABLE IF NOT EXISTS `distributed_lock`
(
    `lock_key`       CHAR(20) NOT NULL,
    `lock_value`     VARCHAR(20) NOT NULL,
    `expire`         BIGINT,
    primary key (`lock_key`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0);

Step 4: Configure Seata

  1. enter directory
cd seata/conf
  1. Modify the configuration file
vim application.yml 
  • In application.ymlthe middle console、security: copy it out and need to use it later
console:
  user:
    username: seata
    password: seata
seata:
  security:
    secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
    tokenValidityInMilliseconds: 1800000
    ignore:
      urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.jpeg,/**/*.ico,/api/v1/auth/login
  • will be application.ymlrenamed to application-back.ymlas a backup
mv application.yml application-copy.yml
  • application.example.ymlA copy will application.ymlbe used as the main configuration file
cp application.example.yml  application.yml
  • Copy the configuration you just copied to the application.ymlcurrent
vim -r application.yml
  • Modify the Seata registration configuration to Nacos (change the account password of nacos to your own)
seata:
  config:
    # support: nacos 、 consul 、 apollo 、 zk  、 etcd3
    type: nacos
    nacos:
      username: nacos
      password: nacos
  registry:
    # support: nacos 、 eureka 、 redis 、 zk  、 consul 、 etcd3 、 sofa
    type: nacos
    nacos:
      username: nacos
      password: nacos
  store:
    # support: file 、 db 、 redis
    mode: db
    session:
      mode: db
    lock:
      mode: db
    db:
      datasource: druid
      db-type: mysql
      driver-class-name: com.mysql.jdbc.Driver
      url: jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true&useSSL=false
      user: mysql
      password: mysql
  # 把开始复制的配置追加到配置文件,注意缩进位置
  security:
    secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
    tokenValidityInMilliseconds: 1800000
    ignore:
      urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.jpeg,/**/*.ico,/api/v1/auth/login
console:
  user:
    username: seata
    password: seata

Step 5: Start the Seata server

  1. enter directory
cd seata/bin
  1. Run the following command in a terminal to start the Seata service:
sh seata-server.sh 
  1. Check the log output, indicating that Seata has been successfully started:
tail -20f /www/apps/seata/logs/start.out

insert image description here

Step 6: Access Seata Console

Enter the following address in the browser, the default account password: seata/seata, you can access the Seata console:
insert image description here

Step 7: Close Seata

When you no longer need the Seata service, you can shut it down with the following command in the terminal:

sh shutdown.sh

Conclusion:

Through this article, you have learned how to install and deploy the Seata distributed transaction solution on the Linux operating system. Seata provides powerful transaction support for distributed systems, helps you solve distributed transaction consistency issues, and provides stable and reliable transaction guarantees for your microservice architecture. Hope this article can help you successfully complete the installation and deployment process of Seata.

Guess you like

Origin blog.csdn.net/weixin_45626288/article/details/132191412