DOCKER安装SEATA注册到NACOS

33 篇文章 8 订阅 ¥39.90 ¥99.00
本文档详细记录了如何在Docker环境下安装SEATA,并将其注册到Nacos的过程。首先确保创建了SEATA所需数据库并执行SQL。接着,在CentOS7.4上,使用最新版的SEATA、Nacos和MySQL5.7。配置file.conf和registry.conf文件,并启动SEATA。成功后,SEATA服务会显示在Nacos中。若想将配置迁移到Nacos,需要下载SEATA源码,修改conf.txt配置,创建Nacos命名空间,并通过Nacos配置命令行工具完成配置上传。最后,重启SEATA以应用新配置。
摘要由CSDN通过智能技术生成

因为总是多多少少的会出现问题,所以我自行搭建成功,跳过所有坑之后写了个博客,此处没有使用集群

说明:请创建对应seata所需的数据库,将seata源码中的sql执行进去

1、使用最新的seata和nacos以及mysql5.7版本,基于centos7.4

1

docker pull seataio/seata-server

2、增加配置文件file.conf和registry.conf,内容如下

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

## transaction log store, only used in seata-server

store {

  ## store mode: file、db、redis

  mode = "db"

  ## database store property

  db {

    ## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp)/HikariDataSource(hikari) etc.

    datasource = "druid"

    dbType = "mysql"

    driverClassName = "com.mysql.cj.jdbc.Driver"

    url = "jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai"

    user = "root"

    password = "123456"

    minConn = 5

    maxConn = 100

    globalTable = "global_table"

    branchTable = "branch_table"

    lockTable = "lock_table"

    queryLimit = 100

    maxWait = 5000

  }

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

registry {

  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa

  type = "nacos"

  nacos {

    application = "seata-server"

    serverAddr = "192.168.0.1:8848"

    namespace ""

    cluster = "luim-tx-group"

    username = "nacos"

    password = "nacos"

  }

  eureka {

    serviceUrl = "http://localhost:8761/eureka"

    application = "default"

    weight = "1"

  }

  redis {

    serverAddr = "localhost:6379"

    db = 0

    password = ""

    cluster = "default"

    timeout = 0

  }

  zk {

    cluster = "default"

    serverAddr = "127.0.0.1:2181"

    sessionTimeout = 6000

    connectTimeout = 2000

    username = ""

    password = ""

  }

  consul {

    cluster = "default"

    serverAddr = "127.0.0.1:8500"

  }

  etcd3 {

    cluster = "default"

    serverAddr = "http://localhost:2379"

  }

  sofa {

    serverAddr = "127.0.0.1:9603"

    application = "default"

    region = "DEFAULT_ZONE"

    datacenter = "DefaultDataCenter"

    cluster = "default"

    group "SEATA_GROUP"

    addressWaitTime = "3000"

  }

  file {

    name = "file.conf"

  }

}

config {

  # file、nacos 、apollo、zk、consul、etcd3

  type = "nacos"

  nacos {

    serverAddr = "192.168.0.1:8848"

    namespace ""

    group "SEATA_GROUP"

    username = "nacos"

    password = "nacos"

  }

  consul {

    serverAddr = "127.0.0.1:8500"

  }

  apollo {

    appId = "seata-server"

    apolloMeta = "http://192.168.1.204:8801"

    namespace "application"

  }

  zk {

    serverAddr = "127.0.0.1:2181"

    sessionTimeout = 6000

    connectTimeout = 2000

    username = ""

    password = ""

  }

  etcd3 {

    serverAddr = "http://localhost:2379"

  }

  file {

    name = "file.conf"

  }

}

  

3、启动seata

1

2

3

4

5

6

7

docker run --name seata -d \

-e SEATA_PORT=8091 \

-v /opt/seata/conf/registry.conf:/seata-server/resources/registry.conf \

-v /opt/seata/logs:/root/logs \

--privileged=true \

-p 8091:8091 \

 seataio/seata-server

目前已经可以在nacos中查看到了

如果你想要将配置文件配置到nacos上的话那就继续看

1、首先去github上下载seata的源码放服务器上

2、进入script/conf-center,修改conf.txt的配置,我把我的粘贴出来,期中遇到了nacos初始化错误的问题,不能有空的,要不不传要不不能为空,屏蔽也不可以

注意这个参数service.vgroupMapping.my_test_tx_group=default,需要和yml文件中的格式一样,尤其是vgroupMapping

yml配置文件中不要配置seata.config和seata.register

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

transport.type=TCP

transport.server=NIO

transport.heartbeat=true

transport.enableClientBatchSendRequest=false

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=127.0.0.1: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.tm.commitRetryCount=5

client.tm.rollbackRetryCount=5

client.tm.defaultGlobalTransactionTimeout=60000

client.tm.degradeCheck=false

client.tm.degradeCheckAllowTimes=10

client.tm.degradeCheckPeriod=2000

store.lock.mode=file

store.session.mode=file

store.publicKey=1

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.jdbc.Driver

store.db.url=jdbc:mysql://ip:3306/seata?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.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

store.redis.sentinel.masterName=master

store.redis.sentinel.sentinelHosts=127.0.0.1

store.redis.maxConn=10

store.redis.minConn=1

store.redis.maxTotal=100

store.redis.database=0

store.redis.password=redis

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

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

2、在nacos网站上创建命名空间

 将命名空间id记录下来,下面需要使用

2、然后进入nacos路径执行以下命令

1

sh nacos-config.sh -h ip -p 8848 -g SEATA_GROUP -t 命名空间id

sh nacos-config.sh 
-h 172.16.9.48 配置中心的ip
-p 8848 配置中心的端口
-g SEATA_GROUP group名字
-t 55730921-9411-4004-973c-156f01c31c1b 命名空间的id,就是前面创建之后的id

3、执行成功之后就可以在nacos上看到配置信息了

 4、重启seata

1

docker restart seata

你可以按照以下步骤将Seata安装Nacos中: 1. 首先,请确保已经安装DockerDocker Compose。 2. 创建一个名为 `docker-compose.yml` 的文件,并将以下内容复制到该文件中: ```yml version: '2' services: nacos: image: nacos/nacos-server:latest container_name: nacos ports: - "8848:8848" environment: - MODE=standalone seata: image: seataio/seata-server:latest container_name: seata environment: - SEATA_PORT=8091 - SEATA_CONFIG_NAME=file:/root/seata-config/registry.conf - SEATA_IP=nacos - SEATA_CONFIG_TYPE=nacos - SEATA_CONFIG_NACOS_ADDR=nacos:8848 volumes: - ./seata-config:/root/seata-config ``` 3. 创建一个名为 `registry.conf` 的文件,并将以下内容复制到该文件中: ```conf service { vgroupMapping.my_test_tx_group = "default" default.grouplist = "127.0.0.1:8091" enableDegrade = false disableGlobalTransaction = false } client { rm { asyncCommitBufferLimit = 10000 lock { retryInterval = 10 retryTimes = 30 retryPolicyBranchRollbackOnConflictEnable = true } reportRetryCount = 5 tableMetaCheckEnable = false } tm { commitRetryCount = 5 rollbackRetryCount = 5 } undo { dataValidation = true logSerialization = "jackson" logTable = "undo_log" logDb = "seata" } log { exceptionRate = 100 } } config { type = "file" file { name = "file.conf" } } ``` 4. 在终端中进入包含上述两个文件的目录,并运行以下命令启动容器: ```bash docker-compose up -d ``` 5. 等待一段时间,NacosSeata容器将会启动并运行。 现在,你已成功将Seata安装Nacos中。你可以通过访问 `http://localhost:8848/nacos` 来访问Nacos的管理界面,使用默认的用户名和密码(都是 `nacos`)登录。 希望这能帮到你!如果你有任何其他问题,请随时问我。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值