构建自己专属seata-server 镜像(分布式事务)?(第二篇)
2023-12-13 13:28:51
码云地址:https://gitee.com/jessyxu/yc-seata-server
一.镜像构建前确保自己的seata-server 能够启动成功!
seata-server
官方建议:JDK版本不低于
1.8.0_281
版本,兼容JDK 8、JDK11,可使用OpenJDK 8/11
、Alibaba Dragonwell 8/
、BiShengJDK 8/11
一 部署前准备
1.1 导入数据库脚本
导入数据库脚本前需要创建数据库
方式一:
Seata官方提供的数据库脚本
将/script/server/db/mysql.sql
导入数据库中
方式二:
本文最上方csdn资源-提供的数据库脚本,包括
Seata
相关表、Seata
在Nacos
中的配置、环境相关配置信息
将yc-database
项目中的/java微服务/{version}/nacos-mysql.sql
导入数据库中
1.2 修改配置文件
注册至Nacos
打开/conf/application.yml
配置文件,找到第11行,修改Nacos
相关配置,如下所示
spring:
application:
name: seata-server
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 127.0.0.1:30099
config:
server-addr: ${spring.cloud.nacos.discovery.server-addr}
读取nacos上的配置
打开/conf/application.yml
配置文件,找到第46行,如下所示,
seata-server.properties
为Nacos的配置
seata:
config:
# support: nacos 、 consul 、 apollo 、 zk 、 etcd3
type: nacos
nacos:
# nacos ip地址
server-addr: ${spring.cloud.nacos.discovery.server-addr}
group: DEFAULT_GROUP
namespace:
username: "nacos"
password: "nacos"
##if use MSE Nacos with auth, mutex with username/password attribute
#access-key: ""
#secret-key: ""
# 读取nacos上的配置文件
data-id: seata-server.properties
1.3 增加Nacos配置
打开Nacos
控制台并登录,依次点击【配置管理】-【配置列表】-【public】,点击右侧【+】,
- Data ID:
seata-server
(注意:和上述1.2中读取nacos上的配置
中的data-id
名称保持一致) - Group:默认即可
- 配置格式:
Properties
(注意:和上述1.2中读取nacos上的配置
中的data-id
格式保持一致) - 配置内容:复制
/script/config-center/config.txt
所有内容,并做如下调整
# 第26行
#######事务分组名#######
service.vgroupMapping.default_tx_group=default
# 第28行
#######Seata服务地址#######
service.default.grouplist=127.0.0.1:30095
# 第69-71
######mode改成db模式(根据实际场景修改)######
store.mode=db
store.lock.mode=db
store.session.mode=db
# 第86-89行
######MySQL配置内容######
store.db.datasource=druid
store.db.dbType=mysql
# MySQL5.7.x 驱动为com.mysql.jdbc.Driver,MySQL8.0.x驱动为com.mysql.cj.jdbc.Driver
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/yc_nacos?characterEncoding=utf8&rewriteBatchedStatements=true&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=GMT%2B8
store.db.user=username
store.db.password=password
二、启动、停止操作
2.1 Windows环境
- 启动:双击
seata-server.bat
- 停止:双击
shutdown.bat
2.2 Linux环境
# 启动
sh startup.sh
# 停止
sh shutdown.sh
三 访问控制台
- 访问地址: http://127.0.0.1:30095
- 用户名:seata
- 密码:seata
四 常见问题
如果直接使用官方下载的安装包并在JDK11
环境下运行,需要将bin/seata-server.sh
文件中第132行
替换成如下内容
JAVA_MAJOR_VERSION=$($JAVACMD -version 2>&1 | head -1 | cut -d'"' -f2 | sed 's/^1\.//' | cut -d'.' -f1)
二、构建docker镜像
nacos 配置文件如下
#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:30095
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=kryo
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=
#If `store.mode,store.lock.mode,store.session.mode` are not equal to `file`, you can remove the configuration block.
store.file.dir=file_store/data
store.file.maxBranchSessionSize=16384
store.file.maxGlobalSessionSize=512
store.file.fileWriteBufferCacheSize=16384
store.file.flushDiskMode=async
store.file.sessionReloadReadSize=100
#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://10.0.2.211:31190/nacos_dev?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=GMT%2B8
store.db.user=nacos
store.db.password=nacos
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
#These configurations are required if the `store mode` is `redis`. If `store.mode,store.lock.mode,store.session.mode` are not equal to `redis`, you can remove the configuration block.
store.redis.mode=single
store.redis.single.host=10.0.2.211
store.redis.single.port=31120
store.redis.sentinel.masterName=
store.redis.sentinel.sentinelHosts=
store.redis.maxConn=10
store.redis.minConn=1
store.redis.maxTotal=100
store.redis.database=0
store.redis.password=123qwe##
store.redis.queryLimit=100
#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
docker镜像源码目录结构,请参看本文的资源
构建docker 运行配置
构建日志
Sending build context to Docker daemon…
[==================================================>] 130.1MB
Done
Step 1/12 : FROM openjdk:8u232-jre-stretch
---> b3f3caa5767c
Step 2/12 : LABEL maintainer="Seata <seata.io>"
---> Using cache
---> b0097c486d2f
Step 3/12 : WORKDIR /$BASE_DIR
---> Using cache
---> 0f0989dffd45
Step 4/12 : ADD bin/ /seata-server/bin
---> Using cache
---> cf3e4e1c8999
Step 5/12 : ADD ext/ /seata-server/ext
---> Using cache
---> 950ef7efe613
Step 6/12 : ADD target/ /seata-server/target
---> Using cache
---> ce72c7af1f96
Step 7/12 : ADD lib/ /seata-server/lib
---> Using cache
---> 3805cc58ad95
Step 8/12 : ADD conf/ /seata-server/conf
---> Using cache
---> e88a16b691b6
Step 9/12 : ADD LICENSE /seata-server/LICENSE
---> Using cache
---> 2b0d5c93750e
Step 10/12 : ENV LOADER_PATH="/seata-server/lib"
---> Using cache
---> 61d27642c102
Step 11/12 : ENV TZ="Asia/Shanghai"
---> Using cache
---> 50c76acd87c7
Step 12/12 : CMD ["bash","-c","/seata-server/bin/seata-server.sh && tail -f /dev/null"]
---> Using cache
---> 5ba8681944cd
Successfully built 5ba8681944cd
Successfully tagged yc-seata-server:1.0.0
Creating container…
Container Id: 0d315169c09de2a3cef87d3dcab37a5b6bb054ba875d798e1b6569c02447b483
Container name: 'yc-seata-server'
Starting container 'yc-seata-server'
'yc-seata-server Dockerfile: dockerfile/1spring-cloud-alibaba/yc-seata-server/Dockerfile' has been deployed successfully.
启动日志
apm-skywalking not enabled
2023-12-13T02:20:17.130679960Z JMX disabled
2023-12-13T02:20:17.135467210Z /usr/local/openjdk-8/bin/java -Dlog.home=/root/logs/seata -server -Dloader.path=/seata-server/lib -Xmx2048m -Xms2048m -Xss640k -XX:SurvivorRatio=10 -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:MaxDirectMemorySize=1024m -XX:-OmitStackTraceInFastThrow -XX:-UseAdaptiveSizePolicy -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/root/logs/seata/java_heapdump.hprof -XX:+DisableExplicitGC -Xloggc:/root/logs/seata/seata_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -Dio.netty.leakDetectionLevel=advanced -Dapp.name=seata-server -Dapp.pid=7 -Dapp.home=/seata-server -Dbasedir=/seata-server -Dspring.config.additional-location=/seata-server/conf/ -Dspring.config.location=/seata-server/conf/application.yml -Dlogging.config=/seata-server/conf/logback-spring.xml -jar /seata-server/target/seata-server.jar >> /dev/null 2>&1 &
2023-12-13T02:20:17.135748459Z seata-server is starting, you can check the /root/logs/seata/ *.log
启动页面
网址:127.0.0.1:30085
账号:seata
密码:seata
文章来源:https://blog.csdn.net/bj_xuzhiqiang/article/details/134965020
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!