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.07k stars 12.81k forks source link

nacos config server-addr invalid #3134

Closed HuangDayu closed 4 years ago

HuangDayu commented 4 years ago

Issue Description

  1. my local not installed nacos server.
  2. nacos discovery service successs,nacos config service failed。
  3. After configuration, the config service address after the application starts is still currentServerAddr:http://localhost:8848.

Error Log

2020-06-21 11:25:46.180  INFO 12896 --- [           main] c.a.n.c.c.impl.LocalConfigInfoProcessor  : LOCAL_SNAPSHOT_PATH:C:\Users\Administrator\nacos\config
2020-06-21 11:25:46.215  INFO 12896 --- [           main] c.a.nacos.client.config.impl.Limiter     : limitTime:5.0
2020-06-21 11:25:48.248 ERROR 12896 --- [           main] c.a.n.c.config.http.ServerHttpAgent      : [NACOS SocketTimeoutException httpGet] currentServerAddr:http://localhost:8848, err : connect timed out
2020-06-21 11:25:50.250 ERROR 12896 --- [           main] c.a.n.c.config.http.ServerHttpAgent      : [NACOS SocketTimeoutException httpGet] currentServerAddr:http://localhost:8848, err : connect timed out
2020-06-21 11:25:50.250 ERROR 12896 --- [           main] c.a.n.c.config.http.ServerHttpAgent      : no available server
2020-06-21 11:25:50.254 ERROR 12896 --- [           main] c.a.n.client.config.impl.ClientWorker    : [fixed-localhost_8848] [sub-server] get server config exception, dataId=service-***, group=DEFAULT_GROUP, tenant=

java.net.ConnectException: no available server
    at com.alibaba.nacos.client.config.http.ServerHttpAgent.httpGet(ServerHttpAgent.java:123) ~[nacos-client-1.3.0.jar:na]
    at com.alibaba.nacos.client.config.http.MetricsHttpAgent.httpGet(MetricsHttpAgent.java:48) ~[nacos-client-1.3.0.jar:na]
    at com.alibaba.nacos.client.config.impl.ClientWorker.getServerConfig(ClientWorker.java:231) ~[nacos-client-1.3.0.jar:na]
    at com.alibaba.nacos.client.config.NacosConfigService.getConfigInner(NacosConfigService.java:143) [nacos-client-1.3.0.jar:na]
    at com.alibaba.nacos.client.config.NacosConfigService.getConfig(NacosConfigService.java:92) [nacos-client-1.3.0.jar:na]
    at com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder.loadNacosData(NacosPropertySourceBuilder.java:85) [spring-cloud-starter-alibaba-nacos-config-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder.build(NacosPropertySourceBuilder.java:74) [spring-cloud-starter-alibaba-nacos-config-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosPropertySource(NacosPropertySourceLocator.java:204) [spring-cloud-starter-alibaba-nacos-config-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosDataIfPresent(NacosPropertySourceLocator.java:191) [spring-cloud-starter-alibaba-nacos-config-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadApplicationConfiguration(NacosPropertySourceLocator.java:142) [spring-cloud-starter-alibaba-nacos-config-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.locate(NacosPropertySourceLocator.java:103) [spring-cloud-starter-alibaba-nacos-config-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:94) [spring-cloud-context-2.1.0.RELEASE.jar:2.1.0.RELEASE]
    at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:621) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:365) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:310) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at c.a.s.v.ServiceApplication.main(ServiceApplication.java:32) [classes/:na]

pom

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            <version>2.1.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
            <version>2.1.2.RELEASE</version>
        </dependency>

yml

spring:
  cloud:
    nacos:
      config:
        enabled: true
        server-addr: test.***.com:8848
        group: springcloud
      discovery:
        enabled: true
        server-addr: test.***.com:8848
        group: springcloud
        metadata:
          instance-id: ${spring.application.name}-${spring.cloud.client.ip-address}:${server.port}
HuangDayu commented 4 years ago

LOCAL_SNAPSHOT_PATH:C:\Users\Administrator\nacos\config does not exist !!!

HuangDayu commented 4 years ago

I have configured a remote nacos server , Why go to get the local configuration file ? The application environment should not require nacos server .

HuangDayu commented 4 years ago
2020-06-21 14:34:29.101 ERROR 9536 --- [-localhost_8848] c.a.n.c.config.http.ServerHttpAgent      : [NACOS ConnectException httpPost] currentServerAddr: http://localhost:8848, err : Connection refused: connect
2020-06-21 14:34:33.108 ERROR 9536 --- [-localhost_8848] c.a.n.c.config.http.ServerHttpAgent      : [NACOS ConnectException httpPost] currentServerAddr: http://localhost:8848, err : Connection refused: connect
2020-06-21 14:34:37.115 ERROR 9536 --- [-localhost_8848] c.a.n.c.config.http.ServerHttpAgent      : [NACOS ConnectException httpPost] currentServerAddr: http://localhost:8848, err : Connection refused: connect
2020-06-21 14:34:41.121 ERROR 9536 --- [-localhost_8848] c.a.n.c.config.http.ServerHttpAgent      : [NACOS ConnectException httpPost] currentServerAddr: http://localhost:8848, err : Connection refused: connect
2020-06-21 14:34:41.121 ERROR 9536 --- [-localhost_8848] c.a.n.client.config.impl.ClientWorker    : [fixed-localhost_8848] [check-update] get changed dataId exception

java.net.ConnectException: [NACOS HTTP-POST] The maximum number of tolerable server reconnection errors has been reached
    at com.alibaba.nacos.client.config.http.ServerHttpAgent.httpPost(ServerHttpAgent.java:170) ~[nacos-client-1.2.1.jar:na]
    at com.alibaba.nacos.client.config.http.MetricsHttpAgent.httpPost(MetricsHttpAgent.java:64) ~[nacos-client-1.2.1.jar:na]
    at com.alibaba.nacos.client.config.impl.ClientWorker.checkUpdateConfigStr(ClientWorker.java:386) [nacos-client-1.2.1.jar:na]
    at com.alibaba.nacos.client.config.impl.ClientWorker.checkUpdateDataIds(ClientWorker.java:354) [nacos-client-1.2.1.jar:na]
    at com.alibaba.nacos.client.config.impl.ClientWorker$LongPollingRunnable.run(ClientWorker.java:521) [nacos-client-1.2.1.jar:na]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_144]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_144]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_144]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_144]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_144]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_144]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_144]

I did not configure this address http://localhost:8848 , but nacos client has been constantly requesting this address.

cloud:
    nacos:
      config:
        enabled: false

When I turn off the config function, the first thing after the application starts is to request the address :http://localhost:8848.

KomachiSion commented 4 years ago

In our environment, it didn't happen. My suggestion is check configuration. Or have a debug and find out why the configuration is not available.

HuangDayu commented 4 years ago

Found the reason.

When I add different configuration files for different environments, for example:

  1. application-dev.yaml
  2. application-test.yaml
  3. application-prod.yaml

Then configure the profiles in bootstrap.yaml, for example:

spring:
  main:
    allow-bean-definition-overriding: true
  profiles:
    active: dev

The configuration of nacos config is in application-dev.yaml, then the configuration of nacos config does not take effect.

HuangDayu commented 4 years ago

When reading the configuration, does not support reading the corresponding configuration file according to spring.profiles.active ?

HuangDayu commented 4 years ago

bootstrap.yaml

spring:
  main:
    allow-bean-definition-overriding: true
  profiles:
    active: dev
  application:
    name: service-***
  cloud:
    config:
      enabled: false
      discovery:
        enabled: false
        service-id: cloud-config
      profile: dev,test,prod
    nacos:
      config:
        enabled: false

application-dev.yaml

spring:
  cloud:
    nacos:
      config:
        enabled: true
        server-addr: test.***.com:8848
        group: springcloud
      discovery:
        enabled: true
        server-addr: test.***.com:8848
        group: springcloud
        metadata:
          instance-id: ${spring.application.name}-${spring.cloud.client.ip-address}:${server.port}

log

2020-06-22 10:52:31.833  INFO 5856 --- [           main] c.a.s.voice.VoiceServiceApplication      : The following profiles are active: dev
2020-06-22 10:52:33 JRebel: Cannot monitor properties in resource URL [jar:file:/D:/maven/repo/org/springframework/integration/spring-integration-core/5.1.6.RELEASE/spring-integration-core-5.1.6.RELEASE.jar!/META-INF/spring.integration.default.properties]
2020-06-22 10:52:33.637  WARN 5856 --- [           main] o.s.boot.actuate.endpoint.EndpointId     : Endpoint ID 'nacos-config' contains invalid characters, please migrate to a valid format.
2020-06-22 10:52:33.643  WARN 5856 --- [           main] o.s.boot.actuate.endpoint.EndpointId     : Endpoint ID 'nacos-discovery' contains invalid characters, please migrate to a valid format.

......

2020-06-22 10:52:50.439  INFO 5856 --- [           main] c.a.n.c.c.impl.LocalConfigInfoProcessor  : LOCAL_SNAPSHOT_PATH:C:\Users\Action9\nacos\config
2020-06-22 10:52:50.458  INFO 5856 --- [           main] c.a.nacos.client.config.impl.Limiter     : limitTime:5.0
2020-06-22 10:52:50.621  WARN 5856 --- [           main] c.a.c.n.c.NacosPropertySourceBuilder     : Ignore the empty nacos configuration and get it based on dataId[service-***] & group[springcloud]
2020-06-22 10:52:50.652  WARN 5856 --- [           main] c.a.c.n.c.NacosPropertySourceBuilder     : Ignore the empty nacos configuration and get it based on dataId[service-***.properties] & group[springcloud]
2020-06-22 10:52:50.677  WARN 5856 --- [           main] c.a.c.n.c.NacosPropertySourceBuilder     : Ignore the empty nacos configuration and get it based on dataId[service-***-dev.properties] & group[springcloud]
2020-06-22 10:52:50.677  INFO 5856 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='NACOS', propertySources=[NacosPropertySource {name='service-***-dev.properties,springcloud'}, NacosPropertySource {name='service-***.properties,springcloud'}, NacosPropertySource {name='service-***,springcloud'}]}

When I turn off nacos config in bootstrap.yaml and open nacos config in application-dev.yaml, after the application starts, I don’t get the local configuration file like the previous one, but after the application is started, it will still get the remote configuration file for test.***.com:8848.

Is there a relationship between bootstrap.yaml and application-dev.yaml reading two configuration files ?

HuangDayu commented 4 years ago

I see, thanks.

application.yml与bootstrap.yml的区别