Seata chính thức: https://seata.io/vi-vn/
Cấu hình Nacos 2.0.4 sử dụng MySQL làm cơ sở lưu trữ. Lưu ý: Seata hỗ trợ 3 chế độ lưu trữ (file, db, redis). Với hệ thống đơn lẻ và chế độ file, chỉ cần giải nén và khởi động. Chế độ redis yêu cầu Seata Server 1.3+.
Thông tin tương thích Spring Cloud Alibaba: https://github.com/alibaba/spring-cloud-alibaba/wiki/Version-Notes
- Khởi tạo cơ sở dữ liệu
Bộ script SQL chính thức: https://github.com/seata/seata/tree/master/script/server/db
Script MySQL mẫu (thay đổi cấu trúc bảng):
CREATE TABLE IF NOT EXISTS seata_global ( transaction_id BIGINT NOT NULL, transaction_group VARCHAR(32), transaction_status TINYINT NOT NULL, application_id VARCHAR(32), branch_id VARCHAR(64), begin_time BIGINT, timeout INT, gmt_create DATETIME, gmt_modified DATETIME, PRIMARY KEY (transaction_id), KEY idx_status (transaction_status) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; CREATE TABLE IF NOT EXISTS seata_branch ( branch_id BIGINT NOT NULL, transaction_id BIGINT, resource_id VARCHAR(256), branch_type VARCHAR(8), status TINYINT, client_id VARCHAR(64), gmt_create DATETIME, gmt_modified DATETIME, PRIMARY KEY (branch_id), KEY idx_transaction_id (transaction_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; CREATE TABLE IF NOT EXISTS seata_lock ( row_key VARCHAR(128) NOT NULL, transaction_id BIGINT, branch_id BIGINT NOT NULL, resource_id VARCHAR(256), table_name VARCHAR(32), pk VARCHAR(36), lock_status TINYINT DEFAULT 0, gmt_create DATETIME, gmt_modified DATETIME, PRIMARY KEY (row_key), KEY idx_lock_status (lock_status) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; INSERT INTO seata_lock (row_key, lock_status) VALUES ('AsyncCommitting', 0), ('RetryCommitting', 0), ('RetryRollbacking', 0), ('TxTimeoutCheck', 0); - Thiết lập gói ứng dụng và cấu hình
Giải nén file:
Chỉnh sửa file cấu hình:
mkdir -p /opt/seata-server tar -xvf seata-server-1.4.2.zip -C /opt/seata-server
vi /opt/seata-server/seata-server-1.4.2/conf/file.conf # Chuyển mode từ file sang db storage_mode = "database" # Cấu hình kết nối MySQL database { driver_class = "com.mysql.cj.jdbc.Driver" connection_url = "jdbc:mysql://127.0.0.1:3306/seata_db?useSSL=false&serverTimezone=UTC" username = "seata_user" password = "secure_password" min_pool_size = 5 max_pool_size = 100 global_table = "seata_global" branch_table = "seata_branch" lock_table = "seata_lock" } - Khởi động và kiểm tra
Khởi động dịch vụ:
Kiểm tra trạng thái:
nohup /opt/seata-server/seata-server-1.4.2/bin/seata-server.sh -p 8092 -h 0.0.0.0 -m db > /dev/null 2>&1 &
Lưu ý: Cổng mặc định 8091 bị chiếm dụng nên sử dụng cổng 8092. Lỗi "Address already in use" thường phát sinh khi cổng đang được sử dụng bởi tiến trình khác.ps -ef | grep seata-server # Output mẫu: seata 12345 1 0 10:30 ? 00:00:05 java -Xmx2560m -Xms2560m -Dseata.server.port=8092 ...