0
点赞
收藏
分享

微信扫一扫

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


文章目录

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

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

[root@node2 ~]# cd /app/seata/seata-server-1.4.2/
[root@node2 seata-server-1.4.2]# 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/ry-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@node2 seata-server-1.4.2]# cd conf
[root@node2 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
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
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
else
echo "Set $1=$2
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

3. 配置导入nacos配置中心

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

sh nacos-config.sh -h 127.0.0.1

  • -h后面是nacos配置中心的地址
    操作记录:

[root@node2 conf]#  sh nacos-config.sh -h 127.0.0.1
set 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/ry-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@node2 conf]#

RuoYi-Cloud 进阶篇_03( Seata 高可用集群与 NacosConfig配置中心整合)_创建文件

4. 配置验证

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

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


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


举报

相关推荐

0 条评论