正常安裝apollo在服務(wù)器之后秧骑,會在本地去注冊的時候 给赞,明明meta填的時候是公網(wǎng)地址,結(jié)果日志打出來是服務(wù)器的內(nèi)網(wǎng)地址
根據(jù)日志定位到 ConfigServiceLocator類
private synchronized void updateConfigServices() {
String url = assembleMetaServiceUrl();
HttpRequest request = new HttpRequest(url);
int maxRetries = 2;
Throwable exception = null;
for (int i = 0; i < maxRetries; i++) {
Transaction transaction = Tracer.newTransaction("Apollo.MetaService", "getConfigService");
transaction.addData("Url", url);
try {
HttpResponse<List<ServiceDTO>> response = m_httpUtil.doGet(request, m_responseType);
transaction.setStatus(Transaction.SUCCESS);
List<ServiceDTO> services = response.getBody();
if (services == null || services.isEmpty()) {
logConfigService("Empty response!");
continue;
}
setConfigServices(services);
return;
} catch (Throwable ex) {
Tracer.logEvent("ApolloConfigException", ExceptionUtil.getDetailMessage(ex));
transaction.setStatus(ex);
exception = ex;
} finally {
transaction.complete();
}
try {
m_configUtil.getOnErrorRetryIntervalTimeUnit().sleep(m_configUtil.getOnErrorRetryInterval());
} catch (InterruptedException ex) {
//ignore
}
}
throw new ApolloConfigException(
String.format("Get config services failed from %s", url), exception);
}
根據(jù)本地斷點調(diào)試得到這個httprequest的請求接口的地址恭取,這個接口返回的meta url 就是為meta的內(nèi)網(wǎng)地址
/services/config?appi=&ip=
根據(jù)這個接口定位到apollo 服務(wù)端的源碼
ServiceController.getConfigService 這個接口
繼續(xù)往下走
public List<ServiceDTO> getServiceInstances(String serviceId) {
Application application = eurekaClient.getApplication(serviceId);
if (application == null || CollectionUtils.isEmpty(application.getInstances())) {
Tracer.logEvent("Apollo.Discovery.NotFound", serviceId);
return Collections.emptyList();
}
return application.getInstances().stream().map(instanceInfoToServiceDTOFunc)
.collect(Collectors.toList());
}
看到這里基本上真相大白了钞瀑,這里只要把eureka的client 注冊地址改成公網(wǎng)的就可以了
于是去script 里面的start.sh 找到
export JAVA_OPTS="$JAVA_OPTS -Dserver.port=$SERVER_PORT -Dlogging.file.name=$LOG_DIR/$SERVICE_NAME.log -XX:HeapDumpPath=$LOG_DIR/HeapDumpOnOutOfMemoryError/"
加上這個參數(shù)就可以了
-Deureka.instance.ip-address=meta的公網(wǎng)地址