当我们把系统代码部署到服务器上的时候会出现的问题,当我们在本地开发的时候是不会出现问题的。因为我们本地开发的时候基本上nacos地址就是localhost

出现问题的日志如下:

nohup: ignoring input
2022-02-24 14:50:25.598  INFO 13070 --- [           main] c.a.b.n.c.u.NacosConfigPropertiesUtils   : nacosConfigProperties : com.alibaba.boot.nacos.config.properties.NacosConfigProperties@7e0ea639
2022-02-24 14:50:25.602  INFO 13070 --- [           main] NacosConfigApplicationContextInitializer : [Nacos Config Boot] : The preload configuration is not enabled
2022-02-24 14:50:25.874  INFO 13070 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.1.RELEASE)

2022-02-24 14:50:26.115  INFO 13070 --- [           main] c.a.n.c.c.impl.LocalConfigInfoProcessor  : LOCAL_SNAPSHOT_PATH:/home/hadoop/nacos/config
2022-02-24 14:50:26.169  INFO 13070 --- [           main] c.a.nacos.client.config.impl.Limiter     : limitTime:5.0
2022-02-24 14:50:26.189 ERROR 13070 --- [           main] c.a.n.c.config.http.ServerHttpAgent      : [NACOS ConnectException httpGet] currentServerAddr:http://localhost:8848, err : Connection refused (Connection refused)
2022-02-24 14:50:26.378 ERROR 13070 --- [           main] c.a.n.c.config.http.ServerHttpAgent      : [NACOS ConnectException httpGet] currentServerAddr:http://localhost:8848, err : Connection refused (Connection refused)
2022-02-24 14:50:26.578 ERROR 13070 --- [           main] c.a.n.c.config.http.ServerHttpAgent      : [NACOS ConnectException httpGet] currentServerAddr:http://localhost:8848, err : Connection refused (Connection refused)
2022-02-24 14:50:26.778 ERROR 13070 --- [           main] c.a.n.c.config.http.ServerHttpAgent      : [NACOS ConnectException httpGet] currentServerAddr:http://localhost:8848, err : Connection refused (Connection refused)
2022-02-24 14:50:26.781 ERROR 13070 --- [           main] c.a.n.client.config.impl.ClientWorker    : [fixed-localhost_8848-56f5f43f-a891-444f-bfc6-03ea90d261be] [sub-server] get server config exception, dataId=postgresql.properties, group=DEFAULT_GROUP, tenant=56f5f43f-a891-444f-bfc6-03ea90d261be

java.net.ConnectException: [NACOS HTTP-GET] The maximum number of tolerable server reconnection errors has been reached
	at com.alibaba.nacos.client.config.http.ServerHttpAgent.httpGet(ServerHttpAgent.java:107) ~[nacos-client-1.1.4.jar!/:na]
	at com.alibaba.nacos.client.config.http.MetricsHttpAgent.httpGet(MetricsHttpAgent.java:48) ~[nacos-client-1.1.4.jar!/:na]
	at com.alibaba.nacos.client.config.impl.ClientWorker.getServerConfig(ClientWorker.java:234) ~[nacos-client-1.1.4.jar!/:na]
	at com.alibaba.nacos.client.config.NacosConfigService.getConfigInner(NacosConfigService.java:173) [nacos-client-1.1.4.jar!/:na]
	at com.alibaba.nacos.client.config.NacosConfigService.getConfig(NacosConfigService.java:122) [nacos-client-1.1.4.jar!/:na]
	at com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder.loadNacosData(NacosPropertySourceBuilder.java:85) [spring-cloud-starter-alibaba-nacos-config-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
	at com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder.build(NacosPropertySourceBuilder.java:74) [spring-cloud-starter-alibaba-nacos-config-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
	at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosPropertySource(NacosPropertySourceLocator.java:204) [spring-cloud-starter-alibaba-nacos-config-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
	at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosDataIfPresent(NacosPropertySourceLocator.java:191) [spring-cloud-starter-alibaba-nacos-config-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
	at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosConfiguration(NacosPropertySourceLocator.java:161) [spring-cloud-starter-alibaba-nacos-config-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
	at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadSharedConfiguration(NacosPropertySourceLocator.java:117) [spring-cloud-starter-alibaba-nacos-config-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
	at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.locate(NacosPropertySourceLocator.java:101) [spring-cloud-starter-alibaba-nacos-config-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
	at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:98) [spring-cloud-context-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
	at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:626) [spring-boot-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
	at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:370) [spring-boot-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
	at com.know.bigdata.statistics.StatisticApplication.main(StatisticApplication.java:28) [classes!/:0.0.1-SNAPSHOT]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_212]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_212]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_212]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_212]
	at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [service_statistics-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [service_statistics-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:51) [service_statistics-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52) [service_statistics-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]

本地开发配置如下:

我们只配置了nacos注册发现的地址、我们并没有配置nacos配置的地址但是在本地开发能用:

原因是:你不配置nacos配置的地址:他就默认为localhost:8848这个服务,正好我本地启动了这个服务,配置参数和服务器上是一致的,所以开发时能用。

# nacos服务器地址
spring.cloud.nacos.discovery.server-addr=http://hadoop17:8848
spring.cloud.nacos.config.enabled=true

当我们把项目打包上传到服务器上的时候就会报开头的错误。

经过折腾分析:原因是找不到nacos配置的地址

修改正确后为如下:

# nacos服务器地址
spring.cloud.nacos.discovery.server-addr=http://hadoop17:8848
spring.cloud.nacos.config.server-addr=http://hadoop17:8848
spring.cloud.nacos.config.enabled=true

我们只需要在配置中加上:spring.cloud.nacos.config.server-addr=http://hadoop17:8848 就可以正常启动了。 

另外我们假如不需要服务之间的调用的话,不需要nacos作为注册中心使用我们可以不配置

spring.cloud.nacos.discovery.server-addr

我们只需要服务之间的调用不需要用nacos的配置就不需要配置

spring.cloud.nacos.config.server-addr

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐