alibaba / nacos

an easy-to-use dynamic service discovery, configuration and service management platform for building cloud native applications.
https://nacos.io
Apache License 2.0
30.37k stars 12.86k forks source link

docker-compose 部署seata-server 并注册到nacos失败 #10053

Closed yuluo-yx closed 1 year ago

yuluo-yx commented 1 year ago

堆栈异常

seata-example-seata-server  | 01:38:58.557 ERROR --- [                     main] c.a.n.c.config.http.ServerHttpAgent      : [NACOS ConnectException httpGet] currentServerAddr:http://127.0.0.1:8848, err : Connection refused (Connection refused)
seata-example-seata-server  | 01:38:58.758 ERROR --- [                     main] c.a.n.c.config.http.ServerHttpAgent      : [NACOS ConnectException httpGet] currentServerAddr:http://127.0.0.1:8848, err : Connection refused (Connection refused)
seata-example-seata-server  | 01:38:58.760 ERROR --- [                     main] c.a.n.client.config.impl.ClientWorker    : [fixed-127.0.0.1_8848-b94cfd49-3743-4bac-b1d3-41dcc2d07070] [sub-server] get server config exception, dataId=store.db.dbType, group=SEATA_GROUP, tenant=b94cfd49-3743-4bac-b1d3-41dcc2d07070
seata-example-seata-server  | ==>
seata-example-seata-server  | java.net.ConnectException: [NACOS HTTP-GET] The maximum number of tolerable server reconnection errors has been reached
seata-example-seata-server  |   at com.alibaba.nacos.client.config.http.ServerHttpAgent.httpGet(ServerHttpAgent.java:125)
seata-example-seata-server  |   at com.alibaba.nacos.client.config.http.MetricsHttpAgent.httpGet(MetricsHttpAgent.java:51)
seata-example-seata-server  |   at com.alibaba.nacos.client.config.impl.ClientWorker.getServerConfig(ClientWorker.java:200)
seata-example-seata-server  |   at com.alibaba.nacos.client.config.NacosConfigService.getConfigInner(NacosConfigService.java:160)
seata-example-seata-server  |   at com.alibaba.nacos.client.config.NacosConfigService.getConfig(NacosConfigService.java:100)
seata-example-seata-server  |   at io.seata.config.nacos.NacosConfiguration.getLatestConfig(NacosConfiguration.java:109)
seata-example-seata-server  |   at io.seata.config.AbstractConfiguration.getConfig(AbstractConfiguration.java:141)
seata-example-seata-server  |   at io.seata.config.AbstractConfiguration.getConfig(AbstractConfiguration.java:132)
seata-example-seata-server  |   at io.seata.config.AbstractConfiguration.getConfig(AbstractConfiguration.java:146)
seata-example-seata-server  |   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
seata-example-seata-server  |   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
seata-example-seata-server  |   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
seata-example-seata-server  |   at java.lang.reflect.Method.invoke(Method.java:498)
seata-example-seata-server  |   at io.seata.config.ConfigurationCache.lambda$proxy$1(ConfigurationCache.java:116)
seata-example-seata-server  |   at io.seata.config.Configuration$$EnhancerByCGLIB$$e11dcb61.getConfig(<generated>)
seata-example-seata-server  |   at io.seata.server.console.impl.db.BranchSessionDBServiceImpl.<init>(BranchSessionDBServiceImpl.java:64)
seata-example-seata-server  |   at io.seata.server.console.impl.db.BranchSessionDBServiceImpl$$EnhancerBySpringCGLIB$$41c8ca8c.<init>(<generated>)
seata-example-seata-server  |   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
seata-example-seata-server  |   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
seata-example-seata-server  |   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
seata-example-seata-server  |   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
seata-example-seata-server  |   at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:211)
seata-example-seata-server  |   at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
seata-example-seata-server  |   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1326)
seata-example-seata-server  |   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1232)
seata-example-seata-server  |   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
seata-example-seata-server  |   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
seata-example-seata-server  |   at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
seata-example-seata-server  |   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
seata-example-seata-server  |   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
seata-example-seata-server  |   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
seata-example-seata-server  |   at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
seata-example-seata-server  |   at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1380)
seata-example-seata-server  |   at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300)
seata-example-seata-server  |   at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:544)
seata-example-seata-server  |   at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:520)
seata-example-seata-server  |   at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:673)
seata-example-seata-server  |   at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:228)
seata-example-seata-server  |   at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
seata-example-seata-server  |   at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:329)
seata-example-seata-server  |   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431)
seata-example-seata-server  |   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619)
seata-example-seata-server  |   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
seata-example-seata-server  |   at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
seata-example-seata-server  |   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
seata-example-seata-server  |   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
seata-example-seata-server  |   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
seata-example-seata-server  |   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944)
seata-example-seata-server  |   at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
seata-example-seata-server  |   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
seata-example-seata-server  |   at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144)
seata-example-seata-server  |   at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:771)
seata-example-seata-server  |   at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:763)
seata-example-seata-server  |   at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:438)
seata-example-seata-server  |   at org.springframework.boot.SpringApplication.run(SpringApplication.java:339)
seata-example-seata-server  |   at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329)
seata-example-seata-server  |   at org.springframework.boot.SpringApplication.run(SpringApplication.java:1318)
seata-example-seata-server  |   at io.seata.server.ServerApplication.main(ServerApplication.java:30)
seata-example-seata-server  | <==

配置文件

server:
  port: 7091

spring:
  application:
    name: seata-server

logging:
  config: classpath:logback-spring.xml
  file:
    path: ${user.home}/logs/seata
  extend:
    logstash-appender:
      destination: 127.0.0.1:4560
    kafka-appender:
      bootstrap-servers: 127.0.0.1:9092
      topic: logback_to_logstash

console:
  user:
    username: admin
    password: admin

seata:
  config:
    # support: nacos, consul, apollo, zk, etcd3
    type: nacos
    nacos:
      server-addr: 127.0.0.1:8848
      up: SEATA_GROUP
      namespace: b94cfd49-3743-4bac-b1d3-41dcc2d07070
      username: nacos
      password: nacos
  registry:
    # support: nacos, eureka, redis, zk, consul, etcd3, sofa
    type: nacos
    nacos:
      application: seata-server
      server-addr: 127.0.0.1:8848
      group: SEATA_GROUP
      namespace: b94cfd49-3743-4bac-b1d3-41dcc2d07070
      username: nacos
      password: nacos
  store:
    # support: file 、 db 、 redis
    mode: db
    db:
      datasource: druid
      ## mysql/oracle/postgresql/h2/oceanbase etc.
      dbType: mysql
      driverClassName: com.mysql.jdbc.Driver
      url: jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true
      user: root
      password: root
      minConn: 5
      maxConn: 100
      globalTable: global_table
      branchTable: branch_table
      lockTable: lock_table
      queryLimit: 100
      maxWait: 5000

  #  server:
  #    service-port: 8091 #If not configured, the default is '${server.port} + 1000'
  security:
    secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
    tokenValidityInMilliseconds: 1800000
    ignore:
      urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login

docker-compsoe file

version: "3"
services:

  # nacos
  nacos:
    container_name: seata-example-nacos
    image: nacos/nacos-server:v2.1.0
    environment:
      - PREFER_HOST_MODE=hostname
      - MODE=standalone
    ports:
      - "8848:8848"
      - "9848:9848"
      - "9849:9849"

  # mysql
  mysql:
    container_name: seata-example-mysql
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: seata
    ports:
      - "3306:3306"
    volumes:
      # 挂载初始化sql文件
      - ./sql/init.sql:/docker-entrypoint-initdb.d/init.sql
    command: [
      --character-set-server=utf8mb4,
      --collation-server=utf8mb4_unicode_ci
    ]

  # seata
  seata-server:
    container_name: seata-example-seata-server
    image: seataio/seata-server:1.5.0
    hostname: seata-server
    ports:
      - "8091:8091"
    environment:
      - STORE_MODE=db
      - SEATA_IP=127.0.0.1
    volumes:
      - ./resources:/seata-server/resources
      - ./mysql-connector-java-5.1.49.jar:/seata-server/lib/mysql-connector-java-5.1.49.jar

Any idea?

yuluo-yx commented 1 year ago

Please See #5405

YunWZ commented 1 year ago

无法访问127.0.0.1:8848, 确认seata是否可访问nacos; 参考docker-compose 的 network部分内容。

KomachiSion commented 1 year ago

currentServerAddr:http://127.0.0.1:8848, err : Connection refused (Connection refused)

你的环境没有监听8848端口, 要么nacos没启动,要么地址不正确。