当前位置:   article > 正文

Windows系统下安装分布式事务seata服务端,配置中心使用nacos_init nacos config finished, please start seata-ser

init nacos config finished, please start seata-server.

官网下载地址: Releases · seata/seata · GitHub

这里我下载的是1.2版本

然后进行解压压缩包

解压后里面文件目录如下

 进入配置文件conf

默认目录如下

 修改 registry.conf 为如下,这里没有用的配置删除了,只留nacos的配置了;

 代码如下:

  1. registry {
  2. # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  3. type = "nacos"
  4. nacos {
  5. application = "seata-server"
  6. serverAddr = "192.168.1.215"
  7. namespace = "public"
  8. cluster = "default"
  9. username = "nacos"
  10. password = "nacos"
  11. }
  12. }
  13. config {
  14. # file、nacos 、apollo、zk、consul、etcd3
  15. type = "file"
  16. nacos {
  17. serverAddr = "192.168.1.215"
  18. namespace = "public"
  19. group = "SEATA_GROUP"
  20. username = "nacos"
  21. password = "nacos"
  22. }
  23. }

修改  file.conf 配置文件,修改mode为db ,同时修改数据库链接信息;这里也可以不修改 file的配置文件,这里看有没有,如果用不用db模式启动,就需要这个file配置文件了

添加 nacos-config.txt 文件

代码如下:

  1. transport.type=TCP
  2. transport.server=NIO
  3. transport.heartbeat=true
  4. transport.thread-factory.boss-thread-prefix=NettyBoss
  5. transport.thread-factory.worker-thread-prefix=NettyServerNIOWorker
  6. transport.thread-factory.server-executor-thread-prefix=NettyServerBizHandler
  7. transport.thread-factory.share-boss-worker=false
  8. transport.thread-factory.client-selector-thread-prefix=NettyClientSelector
  9. transport.thread-factory.client-selector-thread-size=1
  10. transport.thread-factory.client-worker-thread-prefix=NettyClientWorkerThread
  11. transport.thread-factory.boss-thread-size=1
  12. transport.thread-factory.worker-thread-size=8
  13. transport.shutdown.wait=3
  14. service.vgroup_mapping.service-product=default
  15. service.vgroup_mapping.service-order=default
  16. service.enableDegrade=false
  17. service.disable=false
  18. service.max.commit.retry.timeout=-1
  19. service.max.rollback.retry.timeout=-1
  20. client.async.commit.buffer.limit=10000
  21. client.lock.retry.internal=10
  22. client.lock.retry.times=30
  23. client.lock.retry.policy.branch-rollback-on-conflict=true
  24. client.table.meta.check.enable=true
  25. client.report.retry.count=5
  26. client.tm.commit.retry.count=1
  27. client.tm.rollback.retry.count=1
  28. store.mode=db
  29. store.file.dir=file_store/data
  30. store.file.max-branch-session-size=16384
  31. store.file.max-global-session-size=512
  32. store.file.file-write-buffer-cache-size=16384
  33. store.file.flush-disk-mode=async
  34. store.file.session.reload.read_size=100
  35. store.db.datasource=dbcp
  36. store.db.db-type=mysql
  37. store.db.driver-class-name=com.mysql.jdbc.Driver
  38. store.db.url=jdbc:mysql://192.168.1.215:3306/seata?useUnicode=true
  39. store.db.user=root
  40. store.db.password=root
  41. store.db.min-conn=1
  42. store.db.max-conn=3
  43. store.db.global.table=global_table
  44. store.db.branch.table=branch_table
  45. store.db.query-limit=100
  46. store.db.lock-table=lock_table
  47. recovery.committing-retry-period=1000
  48. recovery.asyn-committing-retry-period=1000
  49. recovery.rollbacking-retry-period=1000
  50. recovery.timeout-retry-period=1000
  51. transaction.undo.data.validation=true
  52. transaction.undo.log.serialization=jackson
  53. transaction.undo.log.save.days=7
  54. transaction.undo.log.delete.period=86400000
  55. transaction.undo.log.table=undo_log
  56. transport.serialization=seata
  57. transport.compressor=none
  58. metrics.enabled=false
  59. metrics.registry-type=compact
  60. metrics.exporter-list=prometheus
  61. metrics.exporter-prometheus-port=9898
  62. support.spring.datasource.autoproxy=false

修改地方

 这里的语法为: service.vgroup_mapping.${your-service-gruop}=default ,中间的
${your-service-gruop} 为自己定义的服务组名称, 这里需要我们在程序的配置文件中配置。

然后创建 nacos-config.py 

  1. #!/usr/bin/env python3
  2. # -*- coding: UTF-8 -*-
  3. import http.client
  4. import sys
  5. if len(sys.argv) != 2:
  6. print ('python nacos-config.py nacosIp')
  7. exit()
  8. headers = {
  9. 'content-type': "application/x-www-form-urlencoded"
  10. }
  11. hasError = False
  12. for line in open('nacos-config.txt'):
  13. pair = line.split('=')
  14. if len(pair) < 2:
  15. continue
  16. print (line),
  17. url_prefix = sys.argv[1] + ':8848'
  18. conn = http.client.HTTPConnection(url_prefix)
  19. url_postfix = '/nacos/v1/cs/configs?dataId={}&group=SEATA_GROUP&content={}'.format(str(pair[0]),str(line[line.index('=')+1:])).strip()
  20. conn.request("POST", url_postfix, headers=headers)
  21. res = conn.getresponse()
  22. data = res.read()
  23. if data.decode("utf-8") != "true":
  24. hasError = True
  25. if hasError:
  26. print ("init nacos config fail.")
  27. else:
  28. print ("init nacos config finished, please start seata-server.")

然后创建 nacos-config.sh,如果不知道怎么创建 .sh 文件,可以先创建text文件,然后修改后缀名

  1. #!/usr/bin/env bash
  2. if [ $# != 1 ]; then
  3. echo "./nacos-config.sh nacosIp"
  4. exit -1
  5. fi
  6. nacosIp=$1
  7. echo "set nacosIp=$nacosIp"
  8. error=0
  9. for line in $(cat nacos-config.txt)
  10. do
  11. key=${line%%=*}
  12. value=${line#*=}
  13. echo "\r\n set "${key}" = "${value}
  14. result=`curl -X POST "http://$nacosIp:8848/nacos/v1/cs/configs?dataId=$key&group=SEATA_GROUP&content=$value"`
  15. if [ "$result"x == "true"x ]; then
  16. echo "\033[42;37m $result \033[0m"
  17. else
  18. echo "\033[41;37 $result \033[0m"
  19. let error++
  20. fi
  21. done
  22. if [ $error -eq 0 ]; then
  23. echo "\r\n\033[42;37m init nacos config finished, please start seata-server. \033[0m"
  24. else
  25. echo "\r\n\033[41;33m init nacos config fail. \033[0m"
  26. 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的注册中心,如下信息启动成功

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号