Title: Install and deploy Seata distributed transaction solution on Linux
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
- 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
- Extract the Seata file
unzip seata-server-1.7.0.zip
Step 3: Create the database
- Create a Seata database in MySQL
CREATE DATABASE seata CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
- Initialize the database, run
seata/script/server/db/mysql.sql
the 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
- enter directory
cd seata/conf
- Modify the configuration file
vim application.yml
- In
application.yml
the middleconsole、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.yml
renamed toapplication-back.yml
as a backup
mv application.yml application-copy.yml
application.example.yml
A copy willapplication.yml
be used as the main configuration file
cp application.example.yml application.yml
- Copy the configuration you just copied to the
application.yml
current
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
- enter directory
cd seata/bin
- Run the following command in a terminal to start the Seata service:
sh seata-server.sh
- Check the log output, indicating that Seata has been successfully started:
tail -20f /www/apps/seata/logs/start.out
Step 6: Access Seata Console
Enter the following address in the browser, the default account password: seata/seata, you can access the Seata console:
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.