BE/BE
Eureka와 Eureka 설정방법
bandal-gom
2024. 11. 20. 10:40
Eureka 란?
- Netflix가 개발한
서비스 디스커버리
툴 - MSA 아키텍쳐에서 각 인스턴스의 위치를 자동으로 찾고, 관리
서비스 디스커버리?
- MSA에서 중요한 컴포넌트 → monolithic 에서는 서로의 인스턴스를 찾을 필요가 없었으니까!
- 여러 서비스 인스턴스와 그 위치를 자동으로 탐지하고 관리하는 기능 → 분리되어있는 MSA 환경에서의 개발은 복합적인 MSA의 호출 발생
- 서비스가 서로를 찾고 통신할 수 있도록 해주며, 수동으로 서비스 위치를 관리하는
복잡성을 낮춤
!
Eureka의 구성요소
Eureka Server
- 서비스 등록과 조회 기능을 제공
- 모든 클라이언트가 서버에 등록을 해야함
Eureka Client
- 각 MSA 서비스
- E.g. product msa, order msa
주요기능
서비스 등록
과발견
하트비트
매커니즘- 클라이언트(=msa)는 정해진 간격으로 Eureka 서버에 하트비트 신호를 보내서
"아직 잘 살아있어!"
라고 알림. 이를 통해 Eureka 서버가 서비스의가용성
을 판단.
- 클라이언트(=msa)는 정해진 간격으로 Eureka 서버에 하트비트 신호를 보내서
- 자가 보호 모드
- 네트워크 문제 등의 이유로 다수의 클라이언트가 동시에 서버와의 연결이 끊어졌을 때, Eureka 서버는 이를 장애로 간주하지 않고 일시적인 문제로 판단 후 자동으로 가용 서비스 목록을 유지.
- 서버 클러스터링
서버 가용성
과부하분산
을 향상 시키기 위해 여러 서버 인스턴스를 그룹화하는 프로세스- 이런기능이 왜 필요할까요?
- 클라이언트 측 로드밸런싱
@LoadBalanced
-> 다중 서버환경에서 하나의 서버로만 요청을 보내지 않고 골고루 분산해 주는 방식.- Eureka 단독으로 사용했을 시, 내부적으로 Spring cloud Load balancer를 사용하여 동작함
동작방식
+----------------+ +-------------------+
| | 1. 등록 | |
| Eureka Client +-----------------> Eureka Server |
| = MSA service | | |
| | | |
+--------+-------+ +---------+---------+
| |
| |
| 2. 주기적으로 하트비트 전송 |
|------------------------------------->|
| |
| |
| 3. 레지스트리 정보 가져오기 |
|<-------------------------------------|
| |
+ +
- 서비스 A가 시작될 때, 서비스 인스턴스 정보 (IP주소, 포트, 상태 등)을 Eureka Server에
등록
요청을 보냄. 이 정보는eureka server registry
에 저장 - 서비스 인스턴스는 설정된 시간마다 (default 30초) Eureka Server에 하트비트를 보냄. 하트비트를 통해 server는 client의 가용성을 파악하고, 어떤 인스턴스가 여전히 활성 상태인지 판단
- MSA 서비스 A가 다른 서비스 B와 통신을 시작하기 전에 Eureka server에 MSA 서비스 B의 위치 정보를 요청! 서버는 이 요청을 처리하고, B의 최신정보를 A에 반환
구성도
설정
Eureka- Server
설정
build.gradle
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
Application.java
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
application.yml (단일)
server:
port: 8761
eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
enableSelfPreservation: false # 네트워크 문제 시 서버의 자가 보호 모드 비활성화
application.yml (클러스터링)
server:
port: 8761
eureka:
client:
registerWithEureka: true # Eureka 서버끼리 통신 하기 위해
fetchRegistry: true
defaultZone: http://eureka-server1.com:8761/eureka/,http://eureka-server2.com:8761/eureka/,http://eureka-server3.com:8761/eureka/
server:
enableSelfPreservation: false # 네트워크 문제 시 서버의 자가 보호 모드 비활성화
Eureka- Client
설정
build.gradle
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
Application.java
@SpringBootApplication
@EnableDiscoveryClient
public class EurekaClientApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaClientApplication.class, args);
}
}
application.yml (단일)
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
application.yml (클러스터링)
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://eureka-server1.com:8761/eureka/,http://eureka-server2.com:8761/eureka/,http://eureka-server3.com:8761/eureka/
반응형