男女主網(wǎng)站上做的popo白度指數(shù)
下載安裝包
鏈接: seata
配置seata-server
文件上傳Linux解壓
壓縮包我放在/usr/local/seata中
tar -zxvf seata-server-2.0.0.tar.gz
修改配置文件
設(shè)置nacos為注冊和配置中心
- 進(jìn)入文件夾
cd /usr/local/seata/seata/conf
- 修改application.yml文件
......
......
console:user:username: seatapassword: seata
seata:config:# support: nacos, consul, apollo, zk, etcd3type: nacosnacos:server-addr: ip:8848group: 'DEFAULT_GROUP'namespace: '32e627d0-0b4xxxxxxx'dataId: "seataServer.properties"username: 'nacos'password: 'nacos'registry:# support: nacos, eureka, redis, zk, consul, etcd3, sofatype: nacospreferred-networks: xx.xx.*nacos:application: "seata-server"server-addr: ip:8848group: 'DEFAULT_GROUP'namespace: '32e627d0-0b4xxxxxxx'username: 'nacos'password: 'nacos'
......
......
- 將seata配置文件上傳到nacos
在nacos新建配置文件seataServer.properties
官方供參考的配置文件: config.txt
以下為我修改后的配置文件
#For details about configuration items, see https://seata.io/zh-cn/docs/user/configurations.html
#Transport configuration, for client and server
transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.enableTmClientBatchSendRequest=false
transport.enableRmClientBatchSendRequest=true
transport.enableTcServerBatchSendResponse=false
transport.rpcRmRequestTimeout=30000
transport.rpcTmRequestTimeout=30000
transport.rpcTcRequestTimeout=30000
transport.threadFactory.bossThreadPrefix=NettyBoss
transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker
transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler
transport.threadFactory.shareBossWorker=false
transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector
transport.threadFactory.clientSelectorThreadSize=1
transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread
transport.threadFactory.bossThreadSize=1
transport.threadFactory.workerThreadSize=default
transport.shutdown.wait=3
transport.serialization=seata
transport.compressor=none#Transaction routing rules configuration, only for the client
service.vgroupMapping.default_tx_group=default
#If you use a registry, you can ignore it
service.default.grouplist=127.0.0.1:8091
service.enableDegrade=false
service.disableGlobalTransaction=false#Transaction rule configuration, only for the client
client.rm.asyncCommitBufferLimit=10000
client.rm.lock.retryInterval=10
client.rm.lock.retryTimes=30
client.rm.lock.retryPolicyBranchRollbackOnConflict=true
client.rm.reportRetryCount=5
client.rm.tableMetaCheckEnable=true
client.rm.tableMetaCheckerInterval=60000
client.rm.sqlParserType=druid
client.rm.reportSuccessEnable=false
client.rm.sagaBranchRegisterEnable=false
client.rm.sagaJsonParser=fastjson
client.rm.tccActionInterceptorOrder=-2147482648
client.tm.commitRetryCount=5
client.tm.rollbackRetryCount=5
client.tm.defaultGlobalTransactionTimeout=60000
client.tm.degradeCheck=false
client.tm.degradeCheckAllowTimes=10
client.tm.degradeCheckPeriod=2000
client.tm.interceptorOrder=-2147482648
client.undo.dataValidation=true
client.undo.logSerialization=jackson
client.undo.onlyCareUpdateColumns=true
server.undo.logSaveDays=7
server.undo.logDeletePeriod=86400000
client.undo.logTable=undo_log
client.undo.compress.enable=true
client.undo.compress.type=zip
client.undo.compress.threshold=64k
#For TCC transaction mode
tcc.fence.logTableName=tcc_fence_log
tcc.fence.cleanPeriod=1h#Log rule configuration, for client and server
log.exceptionRate=100#Transaction storage configuration, only for the server. The file, db, and redis configuration values are optional.
store.mode=db
store.lock.mode=db
store.session.mode=db
#Used for password encryption
# store.publicKey=#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.cj.jdbc.Driver
store.db.url=jdbc:mysql://ip:3306/seata?useUnicode=true&rewriteBatchedStatements=true
store.db.user=root
store.db.password=root
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#Transaction rule configuration, only for the server
server.recovery.committingRetryPeriod=1000
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
server.recovery.timeoutRetryPeriod=1000
server.maxCommitRetryTimeout=-1
server.maxRollbackRetryTimeout=-1
server.rollbackRetryTimeoutUnlockEnable=false
server.distributedLockExpireTime=10000
server.xaerNotaRetryTimeout=60000
server.session.branchAsyncQueueSize=5000
server.session.enableBranchAsyncRemove=false
server.enableParallelRequestHandle=false#Metrics configuration, only for the server
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898
創(chuàng)建seata數(shù)據(jù)庫及回滾表
-
在mysql新建了一個名為seata的數(shù)據(jù)庫
-
導(dǎo)入seata回滾所需的表,鏈接: 表結(jié)構(gòu)地址。根據(jù)自己的數(shù)據(jù)庫選擇。
-
在需要接入seata的相關(guān)微服務(wù)數(shù)據(jù)庫中,創(chuàng)建undo_log表。鏈接:表結(jié)構(gòu)地址,根據(jù)自己的數(shù)據(jù)庫選擇。(接入服務(wù)的數(shù)據(jù)庫不同,都要創(chuàng)建一次)
設(shè)置seata自啟動
- 進(jìn)入文件夾
/etc/systemd/system
- 創(chuàng)建seata.service文件
#固定寫法,換一下路徑即可
#!/bin/sh
[Unit]
Description=seata-service
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
Environment="JAVA_HOME=/usr/local/java/jdk1.8.0_311"
ExecStart=/usr/local/seata/seata/bin/seata-server.sh -p 8091 -h ip
PrivateTmp=true
[Install]
WantedBy=multi-user.target
【注意】:此處-h 后接當(dāng)前主機IP,如不接在nacos上注冊的,會顯示為172開頭的虛擬IP
- 設(shè)置開機自啟并刷新配置
systemctl enable seata
systemctl daemon-reload # 刷新配置
- 啟動seata
systemctl start seata
systemctl status seata # 查看服務(wù)狀態(tài)
- 完成
打開瀏覽器ip:7091,即可看到控制臺。賬號密碼為前面修改配置文件設(shè)置的密碼,即seata。
微服務(wù)接入seata
pom中引入seata依賴
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>
yml配置文件設(shè)置
# seata配置
seata:enabled: trueapplication-id: ${spring.application.name}tx-service-group: default_tx_group# 關(guān)閉自動代理enable-auto-data-source-proxy: false# seata nacos注冊中心配置registry:type: nacosnacos:application: seata-serverserver-addr: nacos的ip:8848group: DEFAULT_GROUPnamespace: 32e627d0-0b49-48de-b298-fb959134e1c5username: 'nacos'password: 'nacos'# seata nacos配置中心配置config:type: nacosnacos:server-addr: nacos的IP:8848group: DEFAULT_GROUPnamespace: 32e627d0-0b49-48de-b298-fb959134e1c5data-id: seataServer.propertiesusername: 'nacos'password: 'nacos'
【注意】:這里需要非常注意的是tx-service-group的值,要和seataServer.properties里面的相同。
#Transaction routing rules configuration, only for the client
service.vgroupMapping.default_tx_group=default
使用
主接口增加注解 @GlobalTransactional,遠(yuǎn)程調(diào)用服務(wù)增加注解 @Transactional。項目接入多數(shù)據(jù)源,新建兩方法分別插入數(shù)據(jù)到不同庫,看回滾效果。
TIPS:本項目使用的是mybatis-plus