前言:之前我们只将nacos注册中心和seata进行了整合,如果需要实现完整的功能还需要与nacos的配置中心进行整合。

文章目录

  • 一、配置管理
    • 1. 创建文件config.txt
    • 2. 创建nacos-config.sh
    • 3. 配置导入nacos配置中心
    • 4. 配置验证
一、配置管理
1. 创建文件config.txt

在seata的安装文件夹下创建文件config.txt

[root@localhost ~]# cd /app/seata/
[root@localhost seata]# vim config.txt

添加一下内容:

# 这里order-service值得是订单模块的服务
service.vgroupMapping.order-service=default
# 下面是数据库信息根据自己的实际情况配置
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1/:3306/seata?useUnicode=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.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000

上面的文件是精简后的部分,完整文件可在github中找到

https://github.com/seata/seata/blob/develop/script/config-center/config.txt

2. 创建nacos-config.sh

在conf/文件夹下下载文件https://github.com/seata/seata/blob/develop/script/config-center/nacos/nacos-config.sh 用于将上面的seata配置信息导入到nacos 执行下面的命令

[root@localhost seata]# cd conf/
[root@localhost conf]# vim 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
docase $opt inh)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
doneif [ -z ${host} ]; thenhost=localhost
fi
if [ -z ${port} ]; thenport=8848
fi
if [ -z ${group} ]; thengroup="SEATA_GROUP"
fi
if [ -z ${tenant} ]; thentenant=""
fi
if [ -z ${username} ]; thenusername=""
fi
if [ -z ${password} ]; thenpassword=""
finacosAddr=$host:$port
contentType="content-type:application/json;charset=UTF-8"echo "set nacosAddr=$nacosAddr"
echo "set group=$group"urlencode() {length="${#1}"i=0while [ $length -gt $i ]; dochar="${1:$i:1}"case $char in[a-zA-Z0-9.~_-]) printf $char ;;*) printf '%%%02X' "'$char" ;;esaci=`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/nullif [ -z $(cat "${tempLog}") ]; thenecho " Please check the cluster status. "exit 1fiif [ "$(cat "${tempLog}")" == "true" ]; thenecho "Set $1=$2 successfully "elseecho "Set $1=$2 failure "failCount=`expr $failCount + 1`fi
}count=0
for line in $(cat $(dirname "$PWD")/config.txt | sed s/[[:space:]]//g); docount=`expr $count + 1`key=${line%%=*}value=${line#*=}addConfig "${key}" "${value}"
doneecho "========================================================================="
echo " Complete initialization parameters,  total-count:$count ,  failure-count:$failCount "
echo "========================================================================="if [ ${failCount} -eq 0 ]; thenecho " Init nacos config finished, please start seata-server. "
elseecho " init nacos config fail. "
fi
3. 配置导入nacos配置中心

将seata配置信息导入到nacos config配置中心

[root@localhost conf]# sh nacos-config.sh -h 127.0.0.1set nacosAddr=127.0.0.1:8848
set group=SEATA_GROUP
Set service.vgroupMapping.order-service=default successfully
Set store.mode=db successfully
Set store.db.datasource=druid successfully
Set store.db.dbType=mysql successfully
Set store.db.driverClassName=com.mysql.cj.jdbc.Driver successfully
Set store.db.url=jdbc:mysql://127.0.0.1/:3306/seata?useUnicode=true successfully
Set store.db.user=root successfully
Set store.db.password=123456 successfully
Set store.db.minConn=5 successfully
Set store.db.maxConn=30 successfully
Set store.db.globalTable=global_table successfully
Set store.db.branchTable=branch_table successfully
Set store.db.queryLimit=100 successfully
Set store.db.lockTable=lock_table successfully
Set store.db.maxWait=5000 successfully
=========================================================================Complete initialization parameters,  total-count:15 ,  failure-count:0
=========================================================================Init nacos config finished, please start seata-server.
[root@localhost conf]#

-h后面是nacos配置中心的地址

4. 配置验证

执行完成后登录到nacos 查看配置中心的数据是否导入完毕,如图所示

Seata 与 Nacos Config配置中心整合_03相关推荐

  1. Spring Cloud Alibaba - 19 Nacos Config配置中心加载不同微服务的通用配置的两种方式

    文章目录 Pre 实现 方式一 通过 shared-dataids 方式 方式二 通过 ext-config方式 配置文件优先级 源码 Pre Spring Cloud Alibaba - 18 Na ...

  2. Spring Cloud Alibaba - 18 Nacos Config配置中心加载相同微服务的不同环境下的通用配置

    文章目录 需求 实现 Step 1 Nacos Config 新增公共配置 Step 2 验证 配置文件优先级 源码 需求 举个例子,同一个微服务,通常我们的servlet-context 都是相同的 ...

  3. SpringCloud Alibaba微服务实战(四) - Nacos Config 配置中心

    说在前面 Nacos 是阿里巴巴开源的一个更易于构建云原生应用的动态服务发现.配置管理和服务管理平台.Nacos Config就是一个类似于SpringCloud Config的配置中心. 一.启动N ...

  4. Spring Cloud Alibaba - 17 Nacos Config 配置中心 应用篇

    文章目录 Nacos配置中心基础概念 配置服务 (Configuration Service) 配置管理 (Configuration Management) 配置项 配置集 配置集 ID 配置分组 ...

  5. Spring Cloud Alibaba —— Nacos Config 配置中心

    导航 引言 一.什么是配置中心 二.常见的配置中心组件 三.Nacos Config 入门 四.Nacos Config 动态配置 4.1 硬编码方式(默认支持动态生效) 4.2 属性注入 五.配置共 ...

  6. RuoYi-Cloud 进阶篇_03( Seata 高可用集群与 NacosConfig配置中心整合)

    文章目录 1. 创建文件config.txt 2. 创建nacos-config.sh 3. 配置导入nacos配置中心 4. 配置验证 1. 创建文件config.txt 在seata的安装文件夹下 ...

  7. SpringCloud config 配置中心集群配置以及整合消息总线BUS实现关联微服务配置自动刷新

    一.SpringCloud Config 基本配置中的问题 在上一章节<SpringCloud config 配置中心介绍与基本配置使用>中我们现实了配置中心的配置集中管理.调用微服务应用 ...

  8. 手把手教你搭建SpringCloudAlibaba之Nacos服务配置中心

    SpringCloud Alibaba全集文章目录: 零.手把手教你搭建SpringCloudAlibaba项目 一.手把手教你搭建SpringCloud Alibaba之生产者与消费者 二.手把手教 ...

  9. Spring Cloud Alibba教程:如何使用Nacos作为配置中心

    点击上方"方志朋",选择"置顶公众号" 技术文章第一时间送达! 在上一篇文章中讲解了如何使用Nacos作为服务注册中心注册.Nacos除了可以作为服务注册中心, ...

最新文章

  1. R语言使用magick包的image_border函数和image_background函数自定义图像的边界和背景(Change image border and background)
  2. 仓库码放要求_货物码放规范
  3. Swift2.0语言教程之函数的返回值与函数类型
  4. matlab绘制离散数据图
  5. java throw抛出异常
  6. HTTP 错误 404 - 文件或目录未找到 - 最终解决方法
  7. 一文详解java中对JVM的深度解析、调优工具、垃圾回收
  8. 04-Flutter移动电商实战-打通底部导航栏
  9. 0.Overview----Machine Learning
  10. 亿级流量请求,多级缓存解救
  11. Oracle 集合转字符,PL/SQL Challenge 每日一题:2014-5-30 将逗号隔开的字符串转换为集合...
  12. rust 死后不知道家在哪_赌王儿子何猷君被嘲妈宝,求婚不知道戒指戴哪只手,大喊求助妈妈...
  13. HDOJ 1004:统计气球数
  14. 【软件解决】 解决 TortoiseSVN 图标不显示问题
  15. 畅通工程(并查集模版题)
  16. 前期拍摄注意的简要几点,总结了一哈,与大家分享!
  17. DSP技术-2-DSP的C语言同主机C语言的主要区别在哪里?
  18. Smobiler错误记录
  19. ctf 逆向 回顾与总结
  20. EasyUI中combogrid设置onSelect后 获取不到getSelecte问题解决

热门文章

  1. 《科学》公布2018十大科学突破技术
  2. 女博士7年不毕业,她破解了“量子计算最基础问题”
  3. 解析得了数学,写得了诗书,这是个有趣的灵魂
  4. java使窗体最大化_[转]java窗体运行时最大化及关闭方法示例
  5. Java8 默认方法
  6. html之元素与元素的形成
  7. C语言fread函数了解
  8. C++模板之隐式实例化、显示实例化、隐式调用、显示调用和模板特化详解
  9. 【视频特辑】数据分析师必备,快速制作一张强大好用的大宽表
  10. 进击的数据中台,企业数字化转型的新引擎