赞
踩
官网下载地址: Releases · seata/seata · GitHub
这里我下载的是1.2版本
然后进行解压压缩包
解压后里面文件目录如下
进入配置文件conf
默认目录如下
修改 registry.conf 为如下,这里没有用的配置删除了,只留nacos的配置了;
代码如下:
- registry {
- # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
- type = "nacos"
-
- nacos {
- application = "seata-server"
- serverAddr = "192.168.1.215"
- namespace = "public"
- cluster = "default"
- username = "nacos"
- password = "nacos"
- }
-
- }
-
- config {
- # file、nacos 、apollo、zk、consul、etcd3
- type = "file"
-
- nacos {
- serverAddr = "192.168.1.215"
- namespace = "public"
- group = "SEATA_GROUP"
- username = "nacos"
- password = "nacos"
- }
-
- }
修改 file.conf 配置文件,修改mode为db ,同时修改数据库链接信息;这里也可以不修改 file的配置文件,这里看有没有,如果用不用db模式启动,就需要这个file配置文件了
添加 nacos-config.txt 文件
代码如下:
- transport.type=TCP
- transport.server=NIO
- transport.heartbeat=true
- transport.thread-factory.boss-thread-prefix=NettyBoss
- transport.thread-factory.worker-thread-prefix=NettyServerNIOWorker
- transport.thread-factory.server-executor-thread-prefix=NettyServerBizHandler
- transport.thread-factory.share-boss-worker=false
- transport.thread-factory.client-selector-thread-prefix=NettyClientSelector
- transport.thread-factory.client-selector-thread-size=1
- transport.thread-factory.client-worker-thread-prefix=NettyClientWorkerThread
- transport.thread-factory.boss-thread-size=1
- transport.thread-factory.worker-thread-size=8
- transport.shutdown.wait=3
- service.vgroup_mapping.service-product=default
- service.vgroup_mapping.service-order=default
- service.enableDegrade=false
- service.disable=false
- service.max.commit.retry.timeout=-1
- service.max.rollback.retry.timeout=-1
- client.async.commit.buffer.limit=10000
- client.lock.retry.internal=10
- client.lock.retry.times=30
- client.lock.retry.policy.branch-rollback-on-conflict=true
- client.table.meta.check.enable=true
- client.report.retry.count=5
- client.tm.commit.retry.count=1
- client.tm.rollback.retry.count=1
- store.mode=db
- store.file.dir=file_store/data
- store.file.max-branch-session-size=16384
- store.file.max-global-session-size=512
- store.file.file-write-buffer-cache-size=16384
- store.file.flush-disk-mode=async
- store.file.session.reload.read_size=100
- store.db.datasource=dbcp
- store.db.db-type=mysql
- store.db.driver-class-name=com.mysql.jdbc.Driver
- store.db.url=jdbc:mysql://192.168.1.215:3306/seata?useUnicode=true
- store.db.user=root
- store.db.password=root
- store.db.min-conn=1
- store.db.max-conn=3
- store.db.global.table=global_table
- store.db.branch.table=branch_table
- store.db.query-limit=100
- store.db.lock-table=lock_table
- recovery.committing-retry-period=1000
- recovery.asyn-committing-retry-period=1000
- recovery.rollbacking-retry-period=1000
- recovery.timeout-retry-period=1000
- transaction.undo.data.validation=true
- transaction.undo.log.serialization=jackson
- transaction.undo.log.save.days=7
- transaction.undo.log.delete.period=86400000
- transaction.undo.log.table=undo_log
- transport.serialization=seata
- transport.compressor=none
- metrics.enabled=false
- metrics.registry-type=compact
- metrics.exporter-list=prometheus
- metrics.exporter-prometheus-port=9898
- support.spring.datasource.autoproxy=false
修改地方
这里的语法为: service.vgroup_mapping.${your-service-gruop}=default ,中间的
${your-service-gruop} 为自己定义的服务组名称, 这里需要我们在程序的配置文件中配置。
然后创建 nacos-config.py
- #!/usr/bin/env python3
- # -*- coding: UTF-8 -*-
-
- import http.client
- import sys
-
- if len(sys.argv) != 2:
- print ('python nacos-config.py nacosIp')
- exit()
-
- headers = {
- 'content-type': "application/x-www-form-urlencoded"
- }
-
- hasError = False
- for line in open('nacos-config.txt'):
- pair = line.split('=')
- if len(pair) < 2:
- continue
- print (line),
- url_prefix = sys.argv[1] + ':8848'
- conn = http.client.HTTPConnection(url_prefix)
- url_postfix = '/nacos/v1/cs/configs?dataId={}&group=SEATA_GROUP&content={}'.format(str(pair[0]),str(line[line.index('=')+1:])).strip()
- conn.request("POST", url_postfix, headers=headers)
- res = conn.getresponse()
- data = res.read()
- if data.decode("utf-8") != "true":
- hasError = True
- if hasError:
- print ("init nacos config fail.")
- else:
- print ("init nacos config finished, please start seata-server.")
然后创建 nacos-config.sh,如果不知道怎么创建 .sh 文件,可以先创建text文件,然后修改后缀名
- #!/usr/bin/env bash
- if [ $# != 1 ]; then
- echo "./nacos-config.sh nacosIp"
- exit -1
- fi
-
- nacosIp=$1
- echo "set nacosIp=$nacosIp"
- error=0
-
- for line in $(cat nacos-config.txt)
-
- do
-
- key=${line%%=*}
- value=${line#*=}
- echo "\r\n set "${key}" = "${value}
-
- result=`curl -X POST "http://$nacosIp:8848/nacos/v1/cs/configs?dataId=$key&group=SEATA_GROUP&content=$value"`
-
- if [ "$result"x == "true"x ]; then
-
- echo "\033[42;37m $result \033[0m"
-
- else
-
- echo "\033[41;37 $result \033[0m"
- let error++
-
- fi
-
- done
-
-
- if [ $error -eq 0 ]; then
-
- echo "\r\n\033[42;37m init nacos config finished, please start seata-server. \033[0m"
-
- else
-
- echo "\r\n\033[41;33m init nacos config fail. \033[0m"
-
- fi
创建完相关文件后,目录如下
# 初始化 seata 的nacos配置
# 注意: 这里要保证nacos是已经正常运行的
然后再conf目录下执行下面代码,将seata配置信息添加到nacos中
C:\Users\admin-xu\Desktop\seata-server-1.2.0\seata\conf>nacos-config.sh 192.168.1.215
打印日志如下
去nacos配置中心查看
开始启动seata,进入bin目录下
执行命令
C:\Users\admin-xu\Desktop\seata-server-1.2.0\seata\bin>seata-server.bat -p 9000 -m db
打印日志
去nacos服务中看下是否注册到nacos的注册中心,如下信息启动成功
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。