1.Seata+Nacos deployment
Script description
client
Address: https://github.com/seata/seata/tree/develop/script/client
Store the configuration and SQL for the client
- At: undo in at mode_ Log table creation statement
- conf: configuration file of the client
- Saga: table creation statement of the required table in Saga mode
- Spring: configuration file supported by springboot application
server
Address: https://github.com/seata/seata/tree/develop/script/server
Store the SQL and deployment scripts required on the server side
- db: the table creation statement of the table required when the save mode on the server side is db
- Docker compose: script deployed through docker compose on the server side
- Helm: script deployed through helm on the server side
- Kubernetes: script deployed through kubernetes on the server side
config-center
Address: https://github.com/seata/seata/tree/develop/script/config-center
It is used to store the initialization scripts of various configuration centers. Config. Is read during execution Txt configuration file and write it to the configuration center
- Nacos: used to add configuration to Nacos
- zk: used to add configuration to ZooKeeper. The script depends on the relevant scripts of ZooKeeper and needs to be downloaded manually; ZooKeeper related configurations can be written in zk params Txt, which can also be entered during execution
- Apollo: add configuration to Apollo. The address and port of Apollo can be written in Apollo params Txt, which can also be entered during execution
- Etcd3: used to add configuration to etcd3
- Consumer: used to add configuration to consumer
1.Nacos registry + Nacos configuration center + DB storage
Using nacos as the configuration, the registry realizes cluster high availability
1.1 config.txt writing
Specify store Mode = file | DB | redis mainly modifies mysql connection or redis connection configuration
**File path: / home / service / Seata / config Txt * * tips: after uploading to nacos, you can modify the configuration on nacos
transport.type=TCP transport.server=NIO transport.heartbeat=true transport.enableTmClientBatchSendRequest=false transport.enableRmClientBatchSendRequest=true transport.rpcRmRequestTimeout=5000 transport.rpcTmRequestTimeout=10000 transport.rpcTcRequestTimeout=10000 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 service.vgroupMapping.default_tx_group=default service.default.grouplist=127.0.0.1:8091 service.enableDegrade=false service.disableGlobalTransaction=false 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=false 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 store.mode=file store.lock.mode=file store.session.mode=file store.publicKey= 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 store.db.datasource=druid store.db.dbType=mysql store.db.driverClassName=com.mysql.cj.jdbc.Driver store.db.url=jdbc:mysql://Server address: 3306 / Seata? serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&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 store.redis.mode=single store.redis.single.host= store.redis.single.port=6379 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=Heihei123.. store.redis.queryLimit=100 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 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 log.exceptionRate=100 transport.serialization=seata transport.compressor=none metrics.enabled=false metrics.registryType=compact metrics.exporterList=prometheus metrics.exporterPrometheusPort=9898 tcc.fence.logTableName=tcc_fence_log tcc.fence.cleanPeriod=1h
1.2 Nacos data import script
https://github.com/seata/seata/tree/develop/script/config-center
File name: Nacos config SH path: / home / service / Seata / conf / Nacos config sh
#!/bin/sh # Copyright 1999-2019 Seata.io Group. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at, # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. while getopts ":h:p:g:t:u:w:" opt do case $opt in h) host=$OPTARG ;; p) port=$OPTARG ;; g) group=$OPTARG ;; t) tenant=$OPTARG ;; u) username=$OPTARG ;; w) password=$OPTARG ;; ?) echo " USAGE OPTION: $0 [-h host] [-p port] [-g group] [-t tenant] [-u username] [-w password] " exit 1 ;; esac done if [ -z ${host} ]; then host=localhost fi if [ -z ${port} ]; then port=8848 fi if [ -z ${group} ]; then group="SEATA_GROUP" fi if [ -z ${tenant} ]; then tenant="" fi if [ -z ${username} ]; then username="" fi if [ -z ${password} ]; then password="" fi nacosAddr=$host:$port contentType="content-type:application/json;charset=UTF-8" echo "set nacosAddr=$nacosAddr" echo "set group=$group" urlencode() { length="${#1}" i=0 while [ $length -gt $i ]; do char="${1:$i:1}" case $char in [a-zA-Z0-9.~_-]) printf $char ;; *) printf '%%%02X' "'$char" ;; esac i=`expr $i + 1` done } failCount=0 tempLog=$(mktemp -u) function addConfig() { dataId=`urlencode $1` content=`urlencode $2` curl -X POST -H "${contentType}" "http://$nacosAddr/nacos/v1/cs/configs?dataId=$dataId&group=$group&content=$content&tenant=$tenant&username=$username&password=$password" >"${tempLog}" 2>/dev/null if [ -z $(cat "${tempLog}") ]; then echo " Please check the cluster status. " exit 1 fi if [ "$(cat "${tempLog}")" == "true" ]; then echo "Set $1=$2 successfully " else echo "Set $1=$2 failure " failCount=`expr $failCount + 1` fi } count=0 for line in $(cat $(dirname "$PWD")/config.txt | sed s/[[:space:]]//g); do count=`expr $count + 1` key=${line%%=*} value=${line#*=} addConfig "${key}" "${value}" done echo "=========================================================================" echo " Complete initialization parameters, total-count:$count , failure-count:$failCount " echo "=========================================================================" if [ ${failCount} -eq 0 ]; then echo " Init nacos config finished, please start seata-server. " else echo " init nacos config fail. " fi
chmod -R 744 /home/service/seata/conf/nacos-config.sh # gives Nacos config SH execution permission
1.3 upload config Txt file content to nacos
Path: / home/service/seata/conf
sh nacos-config.sh -h Nacos Service address -p 8848 -g SEATA_GROUP -t a3c214ff-cfe0-4b23-b311-7eb3c89f76a4
Parameter Description:
-h nacos address - p nacos port - g specify profile grouping - t nacos namespace
config.txt key value is empty, adding will fail
1.4 registry.conf configuration
Path: / home / service / Seata / conf / registry conf
registry { # file ,nacos ,eureka,redis,zk,consul,etcd3,sofa type = "nacos" nacos { application = "seata-server" serverAddr = "nacos Service address" #The partition is consistent with the service grouping group = "huio" namespace = "01354ac8-2db9-42f0-a4bc-223aa13b2423" #Cluster name default cluster = "default" username = "nacos Login user name" password = "nacos Login password" } } config { # file,nacos ,apollo,zk,consul,etcd3 type = "nacos" nacos { serverAddr = "119.91.150.87:8848" namespace = "a3c214ff-cfe0-4b23-b311-7eb3c89f76a4" group = "SEATA_GROUP" username = "CloudHui" password = "shuijiao" } }
1.5 docker-compose. Written by YML
Description: SEATA_IP: the seata service address is consistent with the address of the registration center
STORE_MODE: optional db | reids. The precondition is config Txt configures the connection information. The file mode needs to modify the registry
Path: the path in the same level as the seata folder is / home/service/
version: "3" services: seata-server: image: seataio/seata-server:1.4.2 hostname: seata-server container_name: seate-server restart: always ports: - "8091:8091" environment: - SEATA_IP=ip - SEATA_PORT=8091 - STORE_MODE=db volumes: - "./seata/conf/registry.conf:/seata-server/resources/registry.conf" - "./seata/logs:/root/logs"
2.Nacos registry + file configuration + DB storage
2.1 registry.conf configuration
Path: / home / service / Seata / conf / registry conf
registry { # file ,nacos ,eureka,redis,zk,consul,etcd3,sofa type = "nacos" nacos { application = "seata-server" serverAddr = "nacos Service address:8848" group = "huio" namespace = "01354ac8-2db9-42f0-a4bc-223aa13b2423" #Cluster name default cluster = "default" username = "nacos Login user name" password = "nacos Login password" } } config { # file,nacos ,apollo,zk,consul,etcd3 type = "file" file { name = "file.conf" } }
2.2 file.conf configuration
Path: / home / service / Seata / conf / file conf
Optional mode: file | db | redis
mysql 8 + usage: dB driverClassName = com. mysql. cj. jdbc. Driver
mysql 5 + usage: dB driverClassName = com. mysql. jdbc. Driver
transport { # tcp, unix-domain-socket type = "TCP" #NIO, NATIVE server = "NIO" #enable heartbeat heartbeat = true # the client batch send request enable enableClientBatchSendRequest = true #thread factory for netty threadFactory { bossThreadPrefix = "NettyBoss" workerThreadPrefix = "NettyServerNIOWorker" serverExecutorThread-prefix = "NettyServerBizHandler" shareBossWorker = false clientSelectorThreadPrefix = "NettyClientSelector" clientSelectorThreadSize = 1 clientWorkerThreadPrefix = "NettyClientWorkerThread" # netty boss thread size bossThreadSize = 1 #auto default pin or 8 workerThreadSize = "default" } shutdown { # when destroy server, wait seconds wait = 3 } serialization = "seata" compressor = "none" } service { # Custom transaction group name tx_group, which needs to be consistent with the server vgroupMapping.tx_group = "default" # Only in registry It is only supported when type = file. Please do not set multiple addresses. Configure the IP and port of Seata Server here default.grouplist = "ip:8091" #degrade, current not support enableDegrade = false #disable seata disableGlobalTransaction = false } client { rm { asyncCommitBufferLimit = 10000 lock { retryInterval = 10 retryTimes = 30 retryPolicyBranchRollbackOnConflict = true } reportRetryCount = 5 tableMetaCheckEnable = false reportSuccessEnable = false sagaBranchRegisterEnable = false } tm { commitRetryCount = 5 rollbackRetryCount = 5 defaultGlobalTransactionTimeout = 60000 degradeCheck = false degradeCheckPeriod = 2000 degradeCheckAllowTimes = 10 } undo { dataValidation = true onlyCareUpdateColumns = true logSerialization = "jackson" logTable = "undo_log" } } log { exceptionRate = 100 } ## transaction log store, only used in seata-server store { ## store mode: file,db,redis mode = "db" ## rsa decryption public key publicKey = "" ## database store property db { ## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp)/HikariDataSource(hikari) etc. datasource = "druid" ## mysql/oracle/postgresql/h2/oceanbase etc. dbType = "mysql" driverClassName = "com.mysql.cj.jdbc.Driver" ## if using mysql to store the data, recommend add rewriteBatchedStatements=true in jdbc connection param url = "jdbc:mysql://mysql address: 3306/seata?rewriteBatchedStatements=true" user = "root" password = "root" minConn = 5 maxConn = 100 globalTable = "global_table" branchTable = "branch_table" lockTable = "lock_table" queryLimit = 100 maxWait = 5000 } }
2.3 docker-compose. Written by YML
Description: SEATA_IP: the seata service address is consistent with the address of the registration center
STORE_MODE: optional db | reids | file
Path: same level as seata folder
version: "3" services: seata-server: image: seataio/seata-server:1.4.2 hostname: seata-server container_name: seate-server restart: always ports: - "8091:8091" environment: - SEATA_IP=ip - SEATA_PORT=8091 - STORE_MODE=db volumes: - "./seata/conf/registry.conf:/seata-server/resources/registry.conf" - "./seata/conf/file.conf:/seata-server/resources/file.conf" - "./seata/logs:/root/logs"
3.Nacos deployment
Tips: place the configuration file before creating the container
3.1 application.properties
Location: / home/service/nacos/conf
server.servlet.contextPath=/nacos server.port=8848 nacos.inetutils.ip-address=119.91.150.87 spring.datasource.platform=mysql db.num=1 db.url.0=jdbc:mysql://mysql Ip:3306/nacos?useSSL=true&serverTimezone=GMT&characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true db.user.0=root db.password.0=Heiheihei1233.. db.pool.config.connectionTimeout=30000 db.pool.config.validationTimeout=10000 db.pool.config.maximumPoolSize=20 db.pool.config.minimumIdle=2 nacos.naming.empty-service.auto-clean=true nacos.naming.empty-service.clean.initial-delay-ms=50000 nacos.naming.empty-service.clean.period-time-ms=30000 management.metrics.export.elastic.enabled=false management.metrics.export.influx.enabled=false server.tomcat.accesslog.enabled=true server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i server.tomcat.basedir= nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/** nacos.core.auth.system.type=nacos nacos.core.auth.enabled=false nacos.core.auth.default.token.expire.seconds=18000 nacos.core.auth.default.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789 nacos.core.auth.caching.enabled=true nacos.core.auth.enable.userAgentAuthWhite=true nacos.core.auth.server.identity.key= nacos.core.auth.server.identity.value= nacos.istio.mcp.server.enabled=false
3.2 docker-compose. Written by YML
Location: / home/service
version: '3' services: nacosService: image: nacos/nacos-server:2.0.3 restart: always container_name: nacos ports: - 7848:7848 - 8848:8848 - 9848:9848 - 9849:9849 volumes: - "./nacos/conf/application.properties:/home/nacos/conf/application.properties" - "./nacos/logs:/home/nacos/logs" environment: - MODE=cluster - PREFER_HOST_MODE=ip - NACOS_SERVERS=nacos Service address:8848 - MYSQL_SERVICE_HOST=mysql address - MYSQL_SERVICE_PORT=3306 - MYSQL_SERVICE_DB_NAME=nacos - MYSQL_SERVICE_USER=root - MYSQL_SERVICE_PASSWORD=root - SPRING_DATASOURCE_PLATFORM=mysql - JVM_XMS=512m - JVM_XMX=512m - JVM_XMN=512m