一、环境说明
IP | 操作系统 | 程序 | 备注 |
---|---|---|---|
10.0.61.22 | ubuntu20.04 | PostgreSQL-14.11 | 已提前部署 |
10.0.61.21 | ubuntu20.04 | Nacos-2.1.0 | 已提前部署 |
10.0.61.22 | ubuntu20.04 | seata-server-1.7.1 | 本文将要部署 |
二、部署
1. 下载
wget https://github.com/seata/seata/releases/download/v1.7.1/seata-server-1.7.1.tar.gz
2. 解压
tar -zxvf seata-server-1.7.1.tar.gz
# 解压出的文件名 seata,改个名,标注版本
mv seata seata-1.7.1
3. 配置
3.1 application.yml 配置
cd seata-1.7.1
# 备份
cp ./conf/application.yml ./conf/application.yml.bak
# 修改
vim ./conf/application.yml
内容如下,具体配置参照 application.example.yml
中配置修改
server:
port: 8891
spring:
application:
name: seata-server
logging:
config: classpath:logback-spring.xml
file:
path: ./logs/seata
console:
user:
username: seata
password: seata
seata:
config:
type: nacos
nacos:
server-addr: 10.0.61.21:8848
group: SEATA_GROUP
namespace: b1b4b131-0fa9-47cf-8ddb-afe1a4c3e7e2
username: xxxx
password: xxxx
registry:
type: nacos
nacos:
application: seata-server
server-addr: 10.0.61.21:8848
group: SEATA_GROUP
namespace: b1b4b131-0fa9-47cf-8ddb-afe1a4c3e7e2
cluster: default
username: xxxx
password: xxxx
security:
secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
tokenValidityInMilliseconds: 1800000
ignore:
urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login
3.2 seataServer.properties配置
属性配置官方文档说明(未更新,还是1.4.2版本):https://seata.io/zh-cn/docs/user/configurations.html
详细配置(由于Github访问限制,给个Gitee仓库的链接):https://gitee.com/seata-io/seata/blob/v1.7.1/script/config-center/config.txt
- 创建 seataServer.properties ,注意 namespace 、 group 、data-id 和上述 application.yml 配置中心的配置 保持一致,内容参照 详细配置链接 中配置按需配即可
- 事务分组概念: https://seata.io/zh-cn/docs/user/txgroup/transaction-group.html
#transport
transport.compressor=none
transport.enableRmClientBatchSendRequest=true
transport.enableTcServerBatchSendResponse=false
transport.enableTmClientBatchSendRequest=false
transport.heartbeat=true
transport.rpcRmRequestTimeout=30000
transport.rpcTcRequestTimeout=30000
transport.rpcTmRequestTimeout=30000
transport.serialization=seata
transport.server=NIO
transport.shutdown.wait=3
transport.threadFactory.bossThreadPrefix=NettyBoss
transport.threadFactory.bossThreadSize=1
transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector
transport.threadFactory.clientSelectorThreadSize=1
transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread
transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler
transport.threadFactory.shareBossWorker=false
transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker
transport.threadFactory.workerThreadSize=default
transport.type=TCP
#service
service.default.grouplist=10.0.61.21:8891
service.disableGlobalTransaction=false
service.enableDegrade=false
service.vgroupMapping.swkj_tx_group=default
#client
client.rm.asyncCommitBufferLimit=10000
client.rm.lock.retryInterval=10
client.rm.lock.retryPolicyBranchRollbackOnConflict=true
client.rm.lock.retryTimes=30
client.rm.reportRetryCount=5
client.rm.reportSuccessEnable=false
client.rm.sagaBranchRegisterEnable=false
client.rm.sagaJsonParser=fastjson
client.rm.sqlParserType=druid
client.rm.tableMetaCheckEnable=true
client.rm.tableMetaCheckerInterval=60000
client.rm.tccActionInterceptorOrder=-2147482648
client.tm.commitRetryCount=5
client.tm.defaultGlobalTransactionTimeout=60000
client.tm.degradeCheck=false
client.tm.degradeCheckAllowTimes=10
client.tm.degradeCheckPeriod=2000
client.tm.interceptorOrder=-2147482648
client.tm.rollbackRetryCount=5
client.undo.compress.enable=true
client.undo.compress.threshold=64k
client.undo.compress.type=zip
client.undo.dataValidation=true
client.undo.logSerialization=jackson
client.undo.logTable=undo_log
client.undo.onlyCareUpdateColumns=true
#server
server.distributedLockExpireTime=10000
server.enableParallelRequestHandle=false
server.maxCommitRetryTimeout=-1
server.maxRollbackRetryTimeout=-1
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.committingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
server.recovery.timeoutRetryPeriod=1000
server.rollbackRetryTimeoutUnlockEnable=false
server.session.branchAsyncQueueSize=5000
server.session.enableBranchAsyncRemove=false
server.undo.logDeletePeriod=86400000
server.undo.logSaveDays=7
server.xaerNotaRetryTimeout=60000
#tcc
tcc.fence.cleanPeriod=1h
tcc.fence.logTableName=tcc_fence_log
#log
log.exceptionRate=100
#store
store.db.branchTable=branch_table
store.db.datasource=druid
store.db.dbType=postgresql
store.db.distributedLockTable=distributed_lock
store.db.driverClassName=org.postgresql.Driver
store.db.globalTable=global_table
store.db.lockTable=lock_table
store.db.maxConn=30
store.db.maxWait=5000
store.db.minConn=5
store.db.password=xxx
store.db.queryLimit=100
store.db.url=jdbc:postgresql://10.0.61.22:8832/postgres?useUnicode=true&characterEncoding=UTF-8&useSSL=false
store.db.user=postgres
store.file.dir=file_store/data
store.file.fileWriteBufferCacheSize=16384
store.file.flushDiskMode=async
store.file.maxBranchSessionSize=16384
store.file.maxGlobalSessionSize=512
store.file.sessionReloadReadSize=100
store.lock.mode=db
store.mode=db
store.redis.database=0
store.redis.maxConn=10
store.redis.maxTotal=100
store.redis.minConn=1
store.redis.mode=single
store.redis.password=xxx
store.redis.queryLimit=100
store.redis.single.host=10.0.61.21
store.redis.single.port=8879
store.session.mode=db
#metrics
metrics.enabled=false
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898
metrics.registryType=compact
3.3 PostgreSQL脚本
client端:
-- for AT mode you must to init this sql for you business database. the seata server not need it.
CREATE TABLE IF NOT EXISTS public.undo_log
(
id SERIAL NOT NULL,
branch_id BIGINT NOT NULL,
xid VARCHAR(128) NOT NULL,
context VARCHAR(128) NOT NULL,
rollback_info BYTEA NOT NULL,
log_status INT NOT NULL,
log_created TIMESTAMP(0) NOT NULL,
log_modified TIMESTAMP(0) NOT NULL,
CONSTRAINT pk_undo_log PRIMARY KEY (id),
CONSTRAINT ux_undo_log UNIQUE (xid, branch_id)
);
CREATE SEQUENCE IF NOT EXISTS undo_log_id_seq INCREMENT BY 1 MINVALUE 1 ;
Server端:
-- -------------------------------- The script used when storeMode is 'db' --------------------------------
-- the table to store GlobalSession data
CREATE TABLE IF NOT EXISTS public.global_table
(
xid VARCHAR(128) NOT NULL,
transaction_id BIGINT,
status SMALLINT 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 TIMESTAMP(0),
gmt_modified TIMESTAMP(0),
CONSTRAINT pk_global_table PRIMARY KEY (xid)
);
CREATE INDEX idx_status_gmt_modified ON public.global_table (status, gmt_modified);
CREATE INDEX idx_transaction_id ON public.global_table (transaction_id);
-- the table to store BranchSession data
CREATE TABLE IF NOT EXISTS public.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 SMALLINT,
client_id VARCHAR(64),
application_data VARCHAR(2000),
gmt_create TIMESTAMP(6),
gmt_modified TIMESTAMP(6),
CONSTRAINT pk_branch_table PRIMARY KEY (branch_id)
);
CREATE INDEX idx_xid ON public.branch_table (xid);
-- the table to store lock data
CREATE TABLE IF NOT EXISTS public.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 SMALLINT NOT NULL DEFAULT 0,
gmt_create TIMESTAMP(0),
gmt_modified TIMESTAMP(0),
CONSTRAINT pk_lock_table PRIMARY KEY (row_key)
);
comment on column public.lock_table.status is '0:locked ,1:rollbacking';
CREATE INDEX idx_branch_id ON public.lock_table (branch_id);
CREATE INDEX idx_xid ON public.lock_table (xid);
CREATE INDEX idx_status ON public.lock_table (status);
CREATE TABLE distributed_lock (
lock_key VARCHAR(20) NOT NULL,
lock_value VARCHAR(20) NOT NULL,
expire BIGINT NOT NULL,
CONSTRAINT pk_distributed_lock_table PRIMARY KEY (lock_key)
);
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);
注:在部署过程中遇到一个问题导致Seata无法启动,要注意Seata Server端需要配置环境变量在/etc/profile中:
#seata
export SEATA_IP=192.168.28.128
环境变量生效,命令如下:
# source /etc/profile
启动 seata-server,命令如下:
# nohup bash ./bin/seata-server.sh start -h 192.168.28.128 -m db &> seata.log &
开启以下端口:
8891,9891
到此Centos7 安装Seata1.7.1介绍完成。