티스토리 뷰
[#3 Netflix OSS Eureka Server 구축] Spring boot 기반 마이크로서비스 아키텍처(Microservices Architecture, MSA)
Mr.spock 2021. 3. 31. 08:21#3 Netflix OSS Eureka Server 구축
spring.io/projects/spring-cloud-netflix
Spring Cloud Netflix
Spring Cloud Netflix features: Service Discovery: Eureka instances can be registered and clients can discover the instances using Spring-managed beans Service Discovery: an embedded Eureka server can be created with declarative Java configuration Circuit B
spring.io
위의 사이트에서 Spring Cloud Netflix가 제공하는 기능을 살펴보면 아래와 같다.
영어는 자신 없으니 구글 번역기를 이용해서 편리하고 빠르게 어떤 기능을 제공하는지 훑어 보자
- Service Discovery: Eureka instances can be registered and clients can discover the instances using Spring-managed beans
흩어져 있는 마이크로 서비스 인스턴스들을 등록, 관리, 검색할 수 있다는 정도의 뜻인 듯하다. - Service Discovery: an embedded Eureka server can be created with declarative Java configuration
간단한 어노테이션 선언 만으로 Eureka Server를 구축할 수 있다는 뜻인 것 같음. - Circuit Breaker: Hystrix clients can be built with a simple annotation-driven method decorator
간단한 주석 기반의 메서드 데코레이션으로 서킷 브레이커를 간단히 구축할 수 있다는 뜻인 듯 Hystrix에 대해서는 https://medium.com/@goinhacker/hystrix-500452f4fae2에서 자세한 내용을 확인해 보자 - Circuit Breaker: embedded Hystrix dashboard with declarative Java configuration
이것도 Java의 선언만으로 Hystrix의 dashboad를 사용할 수 있다는 뜻인 듯. - Declarative REST Client: Feign creates a dynamic implementation of an interface decorated with JAX-RS or Spring MVC annotations
Feign은 JAX-RS 또는 Spring MVC주석으로 장식된 인터페이스의 동적 구현을 생성합니다. - Client Side Load Balancer: Ribbon
Ribbon을 이용한 로드 밸런서 역할 가능 - External Configuration: a bridge from the Spring Environment to Archaius (enables native configuration of Netflix components using Spring Boot conventions)
Sprnig 환경에서 Archaius 로의 연결 (Spring Boot 규칙을 사용하여 Netflix 구성 요소의 기본 구성 활성화) - Router and Filter: automatic registration of Zuul filters, and a simple convention over configuration approach to reverse proxy creation
Zuul 필터의 자동 등록 및 역방향 프락시 생성에 대한 구성 접근 방식에 대한 간단한 규칙
뭔가 어려운 개념도 말도 많은 것 같아서 걱정이 되지만 일단 흩어져 있는 마이크로 서비스 인스턴트들을 등록, 관리, 검색할 수 있는 기능과 이후 소개할 Zuul(API Gateway) 사용에 필히 필요하기 때문에 아무튼 사용을 해볼 것이다.
- Spring Cloud Netflix Eureka Server 구축을 위한 프로젝트 생성
프로젝트 생성 방식은 별도 설명하지 않겠다. 앞의 글에서 여러 번 설명을 했기 때문에 아래 내용 기준으로 일단 생성을 한다.
Spring boot Version : 2.3.9
Language : Java
Group Id : com.example
Artifact Id : eureka
Packaging Type : war
Java version : 16
dependencies : Spring Web, Spring Boot Actuator, Eureka Server
프로젝트 생성을 한 뒤 /src/main/resources/application.properties 파일을. yml파일로 변경하고 아래와 같이 내용을 작성한다.
spring:
application:
name: Eureka Server
server:
port: 9999
eureka:
client:
serviceUrl:
defaultZone: http://localhost:9999/eureka/
register-with-eureka: false
fetch-registry: false
server:
## Self-Preservation 모드를 켜고 끌 수 있는 설정이다. 가급적이면 운영 상황에서는 끄지 않는 것을 권장한다.
enable-self-preservation: true
서버의 포트는 9999로 설정했고 (의미는 없다.. 그냥 안 겹칠 것 같은 것으로 정한 거), 이런저런 설정 몇 가지를 하였다.
설정에 대한 옵션은 아주 고마운 분께서 상세히 작성해 둔 블로그를 찾아서 해당 링크를 넣어 둘 테니, 나도 나중에 정독을 해야 될 것 같고, 다른 분들도 여기서 보시면 될 것 같다.
Eureka application.properties Configuration 번역
Eureka를 사용하면서 application.properties (application.yml) 에서 설정값에 대한 공부를 자세히 하고싶은데 자료를 찾는것이 쉽지 않다. 대부분의 포스팅은 매번 사용하는 비슷한 설정만 사용하고 그 외
oingdaddy.tistory.com
그리고 EurekaApplication.java 파일에 아래와 같이 @EnableEurekaServer 어노테이션을 붙여준다. 이것으로 서버가 구축이 된 것이다. 이래서 다들 Spring boot Spring boot 하는구나 싶다.
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplication
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}
그리고 서버를 실행(F5)하게 되면 아래와 같이 정상적으로
서버가 동작하는 것을 알 수 있다. http://localhost:9999으로 접속을 해보면 아래와 같이 나타난다.
말만 들으면 좋아 보이고 어려워 보이기도 하고 못할 것 같아 보이지만, 생각보다 쉽게 구축이 된다. 물론, 제공해주는 소스가 그만큼 잘 되어 있다고 볼 수 있기도 하다.
Eureka를 Server만 띄워두려면 사실 띄우는 의미가 없다, 이제 각 클라이언트에서 어떻게 연결하고 활용하는지 살펴보자
- Spring Cloud Netflix Eureka Client 설정 및 테스트
지난번 글에 작성했던 부분에서 Spring Config Client테스트를 위해 생성한 프로젝트처럼 아래의 구성으로 생성하면 된다.
Spring boot Version : 2.3.9
Language : Java
Group Id : com.example
Artifact Id : eureka
Packaging Type : war
Java version : 16
dependencies : Spring Web, Spring Boot Actuator, Eureka Client
application.yml 파일에는 아래와 같이 설정을 해준다.
spring:
profiles:
active: dev
---
server:
port: 80
spring:
profiles: dev
application:
name: ms2
eureka:
client:
service-url:
defaultZone: http://localhost:9999/eureka/
register-with-eureka: true
fetch-registry: true
그리고 Ms1 Application.java파일에 아래와 같이 @EnableEurekaClient를 붙여준다.
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@EnableEurekaClient
@SpringBootApplication
public class Ms1Application {
public static void main(String[] args) {
SpringApplication.run(Ms1Application.class, args);
}
}
이렇게 해두고 서버를 시작해보면 아래와 같이 정상적으로 실행되며 로그를 살펴보면
MS2라는 이름으로 애플리케이션이 등록되고.. 이런저런 내용들이 있다. 아까 띄워둔 Eureka서버에 들어가 보자
위의 캡처 화면과 같이 서버를 실행한 client가 자동으로 등록되어 있는 것을 확인할 수 있다.
Eureka client는 30초(기본값, 변경할 수 있음)마다 서버로 상태 정보를 보내고 서버에서는 현재 등록된 서비스들의 상태 정보를 보내준다. client는 해당 서버의 정보들을 로컬 레지스트리에 저장해 두고 필요시 사용할 수 있도록 되어 있다.
여기까지가 Eureka서버를 구축하고 Client에서 Eureka서버에 등록하는 설정을 알아보았고, 다음 글에서는 Zuul(API Gateway)를 구축하여 Eureka서버를 이용해서 게이트웨이를 통해 원하는 서비스의 API를 호출하는 내용에 대해서 작성하도록 하겠다.
'development' 카테고리의 다른 글
- Total
- Today
- Yesterday
- 풍경그림
- 트랜잭션 추적
- spring boot
- zookeeper
- 그림 그리기
- MSA
- Kafka
- slueth
- 카프카클러스터
- Python
- Eclipse
- windows환경
- 신세계 아카데미
- axios
- 목탄
- 취미생활
- ADL-LRS
- zookeeper 클러스터
- 초보
- 프레임워크
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |