본문 바로가기

Computer Science

Netflix zuul , Eureka Server

반응형

Eureka Server 란?

Eureka는 Middle-tier server(비즈니스 로직이 위치한 애플리케이션 서버단)의 로드밸런스와 Failover를 위해 서비스를 배치해주는 REST 기반 서비스 이다.

주로 AWS Cloud에서 사용되고, 이를 Eureka Sever라 부른다.

 

Eureka Client

 

서버와 상호작용을 더쉽게 해주는 것을 Eureka Client라 부른다. 클라이언트도 Round-Robin 방식을 기본적으로 사용하는 로드밸런스를 내장하고 있다.

Netfilx에서는 , Eureka에서 기본 로드 밸런스 외에도 트래픽, 리소스 사용량, 에러 상황 요소에 따라 로드밸런스를 할 수 있도록 제공한다.

 

Eureka를 사용한 아키텍처

위의 그림은 Netflix에서 Eureka를 어떻게 사용하고 있는지에 대한 것이다. Region마다 자기 region의 인스턴스에 대해 알고 있는 Eureka서버가 하나씩 잇다. zone에서 문제가 발생할 경우를 대비하여 zone마다 하나씩 Eureka 서버를 구축해놓았다.

Eureka에 등록된 서비스들은 30초마다 상태를 보낸다. 클라이언트가 등록을 일정 시간 못하게 되면, 서버 레지스트리에서 90초 내에 제거된다. 등록 정보와 갱신된 정보는 모든 Eureka에 복제된다. 모든 Zone에 있는 클라이언트들은 자신의 서비스를 등록하거나 다른 서비스를 호출하기 위해 레지스트리 정보를 30초마다 가져온다.

 

Eureka Server 의존성

	<properties>
		<java.version>1.8</java.version>
		<spring-cloud.version>Hoxton.SR8</spring-cloud.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>org.junit.vintage</groupId>
					<artifactId>junit-vintage-engine</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
	</dependencies>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>${spring-cloud.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

 

propertis설정

############################################################
################## Application Settings ####################
spring.application.name=Eureka Server
server.port=${PORT:8080}


############################################################
################## Eureka Configuration ####################
eureka.client.serviceUrl.defaultZone=http://localhost:8080/eureka/
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.server.enable-self-preservation=true

어노테이션

@EnableEurekaServer
@SpringBootApplication
public class EurekaApplication {

	public static void main(String[] args) {
		SpringApplication.run(EurekaApplication.class, args);
	}

}

서버 실행화면

Eureka client server 의존성

<properties>
		<java.version>1.8</java.version>
		<spring-cloud.version>Hoxton.SR8</spring-cloud.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>org.junit.vintage</groupId>
					<artifactId>junit-vintage-engine</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
	</dependencies>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>${spring-cloud.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

어노테이션 추가

@EnableEurekaClient
@SpringBootApplication
public class EurekaClientApplication {

	public static void main(String[] args) {
		SpringApplication.run(EurekaClientApplication.class, args);
	}

}

 

Ribbon 연동

loadBancing에 맞추어서 번갈아가면서 api를 호출하는것을 확인한다.

 

API GATEWAY 이란?

프록시 서버와 같이 Microservice Architecture(MSA)에서 언급되는 컴포넌트 중 하나이며, 모든 클라이언트 요청에 대한 end point를 통합하는 서버이다. 그리고 인증 및 권한, 모니터링, loggin등 추가적인 기능이 있다.
오픈소스는 KONG, API Umbrella등이 있다.

Netflix에서는 APIT GATEWAY를 잘 사용하고 있는 서비스이다. Nextflix에서는 JAVA 프로젝트기반 오픈소스를 제공한다.

Netflix Zuul 이란?

 

Netfilx Fiter의 기능

Authentication and Security
- 클라이언트 요청시, 각 리소스에 대한 인증 요구 사항을 식별하고 이를 만족시키지 않는 요청은 거부
Insights and Monitoring
- 의미있는 데이터 및 통계 제공
Dynamic Routing
- 필요에 따라 요청을 다른 클러스터로 동적으로 라우팅
Stress Testing
- 성능 측정을 위해 점차적으로 클러스터 트래픽을 증가
Load Shedding
- 각 유형의 요청에 대해 용량을 할당하고, 초과하는 요청은 제한
Static Response handling
- 클러스터에서 오는 응답을 대신하여 API GATEWAY에서 응답 처리

 

용어정리

클러스터란?

서버 클러스터란 각기 다른 서버(Server Enterprise or server Datacenter)들을 하나로 묶어서 하나의 시스템같이 동작하게 함으로써, 클라이언트들에게 고가용성의 서비스를 제공하는것을 말한다. 클러스터로 묶인 한시스템에 장애가 발생하면, 정보의 제공 포인트는 클러스터로 묶인 다른 정상적인 서버로 이동한다. 서버클러스터는 사용자로 하여금 서버 기반 정보를 지속적이고, 끊기지않게 제공받을수 있게 한다.

 

Zuul Filter

  1. PRE Filter - 라우팅전에 실행되며 필터이다. 주로 logging, 인증등이 pre Filter에서 이루어 진다.

  2. ROUTING Filter - 요청에 대한 라우팅을 다루는 필터이다. Apache httpclient를 사용하여 정해진 Url로 보낼수 있고, Neflix Ribbon을 사용하여 동적으로 라우팅 할 수도 있다.

  3. POST Filter - 라우팅 후에 실행되는 필터이다. response에 HTTP header를 추가하거나, response에 대한 응답속도, Status Code, 등 응답에 대한 statistics and metrics을 수집한다.

  4. ERROR Filter - 에러 발생시 실행되는 필터이다.

Ribbon

리본은 클라이언트 사이드 IPC 라이브러리이다.

특징
- Load balancing
- Fault tolerance
- Multiple protocol(HTTP,TCP,UDP)
- Caching and batching

 

의존성

		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
		</dependency>

반응형

'Computer Science' 카테고리의 다른 글

URI, URL 차이  (0) 2020.10.04
MSA  (0) 2020.10.04
스케일 아웃 vs 스케일 업  (0) 2020.10.04
웹 브라우저 에서의 양방향 통신 방법  (0) 2020.10.04
Redis란  (0) 2020.10.04