springcloud 에 hostname 이나 ip 을 등록 하 는 일 들
                                            
 5646 단어  springcloud책.
                    
Spring cloud 는 Spring Boot 를 바탕 으로 하 는 서비스 관리 도구 패키지 로 마이크로 서비스 구조 에서 서 비 스 를 관리 하고 조율 하 는 데 사용 된다.
마이크로 서비스:하나의 단일 프로젝트 를 여러 개의 마이크로 서비스 로 나 누 는 것 이다.모든 마이크로 서 비 스 는 독립 적 인 기술 선택,독립 적 인 개발,독립 적 인 배치,독립 적 인 운영 을 할 수 있다.또한 여러 서비스 가 서로 조 화 롭 고 협조 하 며 최종 적 으로 사용자 의 가 치 를 완성 할 수 있다.
Spring Cloud 는 일련의 프레임 워 크 의 질서 있 는 집합 이다.이 는 Spring Boot 의 개발 편의 성 을 이용 하여 분포 식 시스템 인 프 라 시설 의 개발 을 교묘 하 게 간소화 했다.예 를 들 어 서비스 발견 등록,배치 센터,메시지 버스,부하 균형,차단기,데이터 모니터링 등 은 모두 Spring Boot 의 개발 스타일 로 원 키 작 동 과 배 치 를 할 수 있다.
 
 5 대 중요 구성 요소
서비스 발견-넷 플 릭 스 유레카
고객 센터 부하 균형-넷 플 릭 스 리본/페 인
서비스 게 이 트 웨 이―넷 플 릭 스 줄
차단기--넷 플 릭 스 하 이 스 트 릭 스
분산 설정-Spring Cloud Config
기본적으로 Eureka 는 hostname 을 사용 하여 서비스 등록 과 서비스 정 보 를 표시 합 니 다.만약 에 저희 가 IP 주 소 를 서로 껴 안 는 방식 으로 설정 파일 에 설정 할 수 있 습 니 다.
eureka.instance.prefer-ip-address=true아이디어 중 ctrl+좌 클릭,클릭 eureka.instance.prefer-ip-address=true 하여 보기  EurekaInstanceConfigBean이 속성 을 도입 합 니 다.
EurekaInstanceConfigBean
/**
 * Flag to say that, when guessing a hostname, the IP address of the server should be
 * used in prference to the hostname reported by the OS.
 */
 private boolean preferIpAddress = false;판단 할 곳 이 있 을 거 야. Eureka Instance ConfigBean 검색 preferIpAddress,발견 getHostName 방법,이 방법 은 얻 은 hostname 이나 ip 를 되 돌려 주 는 데 사 용 됩 니 다.
@Override
public String getHostName(boolean refresh) {
 if (refresh && !this.hostInfo.override) {
  this.ipAddress = this.hostInfo.getIpAddress();
  this.hostname = this.hostInfo.getHostname();
 }
 return this.preferIpAddress ? this.ipAddress : this.hostname;
}eureka.instance.ip-address= 이 설정 속성 입 니 다.즉, eureka.intance.ip-address 와 eureka.intance.prefer-ip-address=true 동시 설정 이 우선 입 니 다. eureka.intance.ip-address 설정
public void setIpAddress(String ipAddress) {
 this.ipAddress = ipAddress;
 this.hostInfo.override = true;
 }
public EurekaInstanceConfigBean(InetUtils inetUtils) {
 this.inetUtils = inetUtils;
 this.hostInfo = this.inetUtils.findFirstNonLoopbackHostInfo();
 this.ipAddress = this.hostInfo.getIpAddress();
 this.hostname = this.hostInfo.getHostname();
}
public InetAddress findFirstNonLoopbackAddress() {
 InetAddress result = null;
 try {
  //         
  int lowest = Integer.MAX_VALUE; 
  //       
  for (Enumeration<NetworkInterface> nics = NetworkInterface
   .getNetworkInterfaces(); nics.hasMoreElements();) {
  NetworkInterface ifc = nics.nextElement();
  if (ifc.isUp()) {//        
   log.trace("Testing interface: " + ifc.getDisplayName());
   if (ifc.getIndex() < lowest || result == null) {
   lowest = ifc.getIndex();
   }
   else if (result != null) {
   continue;
   }
   // @formatter:off
   //        
   if (!ignoreInterface(ifc.getDisplayName())) {
   for (Enumeration<InetAddress> addrs = ifc
    .getInetAddresses(); addrs.hasMoreElements();) {
    InetAddress address = addrs.nextElement();
    if (
 address instanceof Inet4Address// IPV4
 && !address.isLoopbackAddress()//      (127.***)
 && isPreferredAddress(address)) {//     ,         ip
    log.trace("Found non-loopback interface: "
     + ifc.getDisplayName());
    result = address;
    }
   }
   }
   // @formatter:on
  }
  }
 }
 catch (IOException ex) {
  log.error("Cannot get first non-loopback address", ex);
 }
 if (result != null) {
  return result;
 }
 try {
  //       JDK InetAddress  
  return InetAddress.getLocalHost();
 }
 catch (UnknownHostException e) {
  log.warn("Unable to retrieve localhost");
 }
 return null;
} InetAddress.getLocalHost() 방법 을 사용한다.이로써 우 리 는 등록 에 관 한 몇 가지 유연 한 설정 을 정리 합 니 다.
위 에서 말씀 드 린 것 은 편집장 님 께 서 소개 해 주신 springcloud 등록 hostname 이나 ip 의 일 입 니 다.도움 이 되 셨 으 면 좋 겠 습 니 다.궁금 한 점 이 있 으 시 면 메 시 지 를 남 겨 주세요.편집장 님 께 서 바로 답 해 드 리 겠 습 니 다.여기 서도 저희 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!
만약 당신 이 본문 이 당신 에 게 도움 이 된다 고 생각한다 면,전 재 를 환영 합 니 다.번 거 로 우 시 겠 지만 출처 를 밝 혀 주 십시오.감사합니다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Spring Cloud에서 Feign에 대한 일반적인 질문 요약1. FeignClient 인터페이스, @GettingMapping 같은 조합 메모는 사용할 수 없음 코드 예: 이쪽 @RequestMapping(value = "/simple/{id}", method = Reque...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.