一:YML配置信息

seata:
  enabled: true
  application-id: ${spring.application.name}
  # 事务组
  tx-service-group: my_test_tx_group
  # 数据源代理模式
  enable-auto-data-source-proxy: true
  # 数据源代理模式
  data-source-proxy-mode: AT
  # 事务组
  service:
    vgroup-mapping:
      my_test_tx_group: default
  #整合nacos配置
  config:
    type: nacos
    nacos:
      server-addr: 192.101:8848
      group: SEATA_GROUP
      namespace: d4874eb0-1917-45fd-8dc1-34f6f3f5265a
      data-id: seataServer.properties
      #可选
      username: nacos
      #可选
      password: nacos
  #整合nacos注册中心
  registry:
    type: nacos
    nacos:
      server-addr: 192.101:8848  
      application: seata-server  
      group: SEATA_GROUP 
      username: nacos
      password: nacos
      namespace: d4874eb0-1917-45fd-8dc1-34f6f3f5265a

二:启动异常日志

2022-12-26 22:26:27.065 ERROR 25384 --- [eoutChecker_1_1] i.s.c.r.netty.NettyClientChannelManager  : no available service 'default' found, please make sure registry config correct

在这里插入图片描述

三:异常信息排查

3.1:锁定包路径 io.seata.core.rpc.netty

在这里插入图片描述

3.2:全局搜索异常关键字:please make sure registry config correct

在这里插入图片描述

3.3:问题定位

打断点一层层查看变量信息,最后是获取不到Nacos对应的vgroupMapping键值对信息。

3.3.1 :注意:如果Seata配置信息是Nacos类型,即使在file文件中配置了vgroupMapping,不是file类型也获取不到,这里用的Nacos,应该在Nacos配置中进行配置

这里的YML中的事务组和Nacos – vgroupMapping配置的事务组信息必须一致

 # 这段不是完整配置信息,单独提出来的
 tx-service-group: my_test_tx_group
   service:
    vgroup-mapping:
      my_test_tx_group: default
seata:
  enabled: true
  application-id: ${spring.application.name}
  # 事务组
  tx-service-group: my_test_tx_group
  # 数据源代理模式
  enable-auto-data-source-proxy: true
  # 数据源代理模式
  data-source-proxy-mode: AT
  # 事务组
  service:
    vgroup-mapping:
      my_test_tx_group: default
service {
  #transaction service group mapping
  vgroupMapping.my_test_tx_group = "default"
  default.grouplist = "192..101:8091"
  #degrade, current not support
  enableDegrade = false
  #disable seata
  disableGlobalTransaction = false
}
#client tr

四:问题解决

4.1. 配置 nacos-config.sh 和 config.txt

在这里插入图片描述

4.1.1. 编辑nacos-config.sh nacos配置文件加载sh执行文件
4.1.1.1 代码如下
#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
 
4.1.2. 编辑config.txt nacos配置文件相关信息
.4.1.2.1 配置信息如下

特别注意下

service.vgroupMapping.my_test_tx_group=default
service.default.grouplist=seata所属Ip:8091
transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.enableClientBatchSendRequest=true
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.my_test_tx_group=default
service.default.grouplist=seata所属Ip: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=db
store.lock.mode=db
store.session.mode=db
#给store.publicKey赋值failure
store.publicKey=failure
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://数据库IP:3306/seata-config?useUnicode=true&rewriteBatchedStatements=true
store.db.user=root
store.db.password=123456
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=127.0.0.1
store.redis.single.port=6379
#分别给下边两个值赋值failure
store.redis.sentinel.masterName=failure
store.redis.sentinel.sentinelHosts=failure
store.redis.maxConn=10
store.redis.minConn=1
store.redis.maxTotal=100
store.redis.database=0
#给store.redis.password赋值failure
store.redis.password=failure
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
4.1.3. 执行 nacos-config sh 脚本
sh nacos-config.sh -h nacos所属机器ip -p 8848 -g SEATA_GROUP -t 对应的命名空间d4874eb0-1917-45fd-8dc1-34f6f3f5265a -u nacos -w nacos

可以看到相关输出

4.1.4. 查看Nacos是否载入配置信息

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

五:重启Seata服务,重启订单微服务

不再输出错误日志,配置相关信息也成功载入
在这里插入图片描述

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐