apolloconfig / apollo

Apollo is a reliable configuration management system suitable for microservice configuration management scenarios.
https://www.apolloconfig.com
Apache License 2.0
28.93k stars 10.19k forks source link

apollo.meta; nested exception is java.net.UnknownHostException: apollo.meta #5117

Closed starsky20 closed 1 month ago

starsky20 commented 3 months ago

1.我是基于最新的 master 分支 build 编译的,未改动服务端口地址。

2.根据官网说明,分别修改了configservice、adminservice数据库application-github.properties配置。通过idea 分别启动服务指定了激活环境 -Dapollo_profile=github,auth,configservice、adminservice启动正常,通过访问8080测试,eureka正常,两个服务健康状态正常。

3.修改了protal数据库serverconfig 配置 apollo.portal.envs=dev。apollo.portal.meta.servers={"dev":"http://192.168.3.174:8080"}

4.修改protalservice服务配置文件apollo-env.properties,只是配置了dev.meta=http://192.168.3.174:8080, 其他的全部注释了。 修改application-github.properties的数据库连接。启动服务时指定了激活环境-Dapollo_profile=github,auth,dev。

启动报错内容如下: 6912 --- [ main] .f.a.p.e.DefaultPortalMetaServerProvider : Loaded meta server addresses from system property, os environment and properties file: {DEV=http://192.168.3.174:8080} 2024-03-31 21:59:57.482 WARN 16912 --- [erviceLocator-1] c.c.f.a.p.e.PortalMetaDomainService : Meta server address fallback to [http://apollo.meta] for env [FAT], because it is not available in MetaServerProvider 2024-03-31 21:59:57.611 ERROR 16912 --- [erviceLocator-1] c.c.f.a.p.c.AdminServiceAddressLocator : Get admin server address from meta server failed. env: FAT, meta server address:http://apollo.meta

org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://apollo.meta/services/admin": apollo.meta; nested exception is java.net.UnknownHostException: apollo.meta at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:791) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:717) at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:340) at com.ctrip.framework.apollo.portal.component.AdminServiceAddressLocator.getAdminServerAddress(AdminServiceAddressLocator.java:141) at com.ctrip.framework.apollo.portal.component.AdminServiceAddressLocator.refreshServerAddressCache(AdminServiceAddressLocator.java:121) at com.ctrip.framework.apollo.portal.component.AdminServiceAddressLocator.access$200(AdminServiceAddressLocator.java:43) at com.ctrip.framework.apollo.portal.component.AdminServiceAddressLocator$RefreshAdminServerAddressTask.run(AdminServiceAddressLocator.java:102) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) at java.util.concurrent.FutureTask.run(FutureTask.java) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: java.net.UnknownHostException: apollo.meta at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)

请问异常apollo.meta时什么原因?

dosubot[bot] commented 3 months ago

Hey @starsky20, back for more Apollo adventures, I see! 🚀

Based on the error log you provided, it seems that the Apollo service is trying to resolve a hostname (apollo.meta) that is not defined in your environment or DNS settings. This typically happens when the application tries to connect to a server with a hostname that cannot be resolved to an IP address.

In the Apollo codebase, the apollo.meta hostname is referenced in the context of loading meta server addresses. This is done by looking for keys that end with "_meta" (for system properties and OS environment variables) and ".meta" (for user's configuration files) in a case-insensitive manner. The relevant code segments are found in the DefaultPortalMetaServerProvider class, specifically in the methods getDomainsFromSystemProperty(), getDomainsFromOSEnvironment(), and getDomainsFromPropertiesFile(). These methods are responsible for loading the meta server addresses from the system properties, OS environment variables, and properties file (apollo-env.properties), respectively. You can find this in the DefaultPortalMetaServerProvider.java file.

To resolve this issue, you have a couple of options:

  1. Define apollo.meta in your Hosts File: If apollo.meta is supposed to point to a specific IP address, you can manually add an entry to your hosts file to resolve this hostname to the correct IP. This is done by editing the hosts file on your system (/etc/hosts on Linux/macOS, C:\Windows\System32\drivers\etc\hosts on Windows) and adding a line like 127.0.0.1 apollo.meta (replace 127.0.0.1 with the actual IP address if it's not meant to point to localhost).

  2. Update Your Application Configuration: If the usage of apollo.meta is a mistake or if it should be replaced with one of the defined meta server URLs (dev_meta, fat_meta, uat_meta, pro_meta), update your application's configuration to use the correct meta server URL based on your environment.

Without more specific details on where apollo.meta is being referenced in your application, these are general approaches to resolve the java.net.UnknownHostException. You'll need to identify where apollo.meta is being used (e.g., in application properties, environment variables, or code) and apply one of the above solutions accordingly.

I also found a similar issue in the Apollo repository: apollo客户端无法获取项目下apollo-env.properties中的dev.meta地址. The suggested solution there is to ensure that the server.properties file is correctly placed in the C:\opt\settings\ directory and that the file does not have a hidden extension like .txt. Also, verify that the apollo-env.properties file is placed in the correct location, which should be the resources directory, and ensure that this directory is marked as a resource folder in your project settings. Lastly, make sure that the environment is set correctly, for example, env=DEV or env=dev, and that the apollo-env.properties file contains the correct property for the environment, such as dev.meta.

If the issue persists, consider debugging the com.ctrip.framework.apollo.core.internals.LegacyMetaServerProvider#getMetaServerAddress(com.ctrip.framework.apollo.core.enums.Env) logic and the com.ctrip.framework.apollo.core.MetaDomainConsts#initMetaServerAddress to find out why the dev.meta is not being retrieved.

I hope this helps! If you need further assistance, please provide more details about your configuration and where apollo.meta is being referenced in your application.

Sources

#### About Dosu This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot.
starsky20 commented 3 months ago

按照您提供的解决办法,分别验证了以下几种办法: 1.在apollo-env.properties设置中设置dev.meta=http://192.168.3.174:8080、apollo.meta=http://192.168.3.174:8080

2.在C:\opt\settings\server.properties 文件中添加env=DEV image

3.启动增加jvm参数 -Dapollo_profile=github -Denv=dev -Dapollo.meta=http://192.168.3.174:8080

以上三种方式都不可以,还是提示无法java.net.UnknownHostException: apollo.meta。调试代码后发现是env环境没有生效导致。 通过打成jar包后,修改application.yml的激活环境为github,dev,auth,然后在命令行直接执行 java -jar apollo-portal-2.3.0-SNAPSHOT.jar 启动无任务问题。

image

nobodyiam commented 3 months ago

可以在系统信息页面看到详情

image

stale[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.

stale[bot] commented 1 month ago

This issue has been automatically closed because it has not had activity in the last 7 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted". Thank you for your contributions.