Tickatch MSA의 서비스 디스커버리 서버입니다.
- 모든 마이크로서비스 등록 및 관리
- 서비스 위치 정보 제공 (Service Registry)
- 헬스 체크 및 장애 감지
- 이중화 구성으로 고가용성 확보
| 항목 |
버전 |
| Java |
21 |
| Spring Boot |
4.0.0 |
| Spring Cloud |
2025.1.0 |
| Spring Cloud Netflix Eureka |
5.0.x |
# 이미지 빌드
./gradlew clean bootJar
docker build -t ghcr.io/tickatch/eureka-server:latest .
# 컨테이너 실행
docker-compose up -d
┌─────────────────────┐ ┌─────────────────────┐
│ eureka-server-1 │◄───────►│ eureka-server-2 │
│ :3150 (/eureka1) │ │ :3151 (/eureka2) │
└─────────────────────┘ └─────────────────────┘
▲ ▲
│ │
└───────────┬───────────────────┘
│
┌───────────────┴───────────────┐
│ Microservices │
│ (Config, Gateway, Auth, ...) │
└───────────────────────────────┘
두 Eureka 서버가 서로 등록하여 한 대 장애 시에도 정상 동작합니다.
| 인스턴스 |
포트 |
Context Path |
| eureka-server-1 |
3150 |
/eureka1 |
| eureka-server-2 |
3151 |
/eureka2 |
| 변수 |
설명 |
예시 |
SERVER_PORT |
서버 포트 |
3150, 3151 |
SERVER_SERVLET_CONTEXT_PATH |
Context Path |
/eureka1, /eureka2 |
EUREKA_INSTANCE_HOSTNAME |
인스턴스 호스트명 |
eureka-server-1 |
EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE |
피어 Eureka 주소 |
http://eureka-server-2:3151/eureka2/eureka/ |
| 변수 |
설명 |
기본값 |
EUREKA_SELF_PRESERVATION |
자기 보호 모드 |
false |
ZIPKIN_ENDPOINT |
Zipkin 엔드포인트 |
http://zipkin:9411/api/v2/spans |
LOGSTASH_HOST |
Logstash 호스트 |
logstash:5000 |
JAVA_OPTS |
JVM 옵션 |
-Xms256m -Xmx512m |
LOG_LEVEL |
로그 레벨 |
INFO |
# ========================================
# Eureka Server Configuration
# ========================================
# 이 파일을 .env로 복사하여 사용하세요
# cp .env.example .env
# ========================================
# ========================================
# Image
# ========================================
EUREKA_IMAGE=ghcr.io/tickatch/eureka-server:latest
# ========================================
# Eureka Settings
# ========================================
EUREKA_SELF_PRESERVATION=false
# ========================================
# Monitoring
# ========================================
ZIPKIN_ENDPOINT=http://zipkin:9411/api/v2/spans
LOGSTASH_HOST=logstash:5000
# ========================================
# JVM Options
# ========================================
JAVA_OPTS=-Xms256m -Xmx512m
# ========================================
# Logging
# ========================================
LOG_LEVEL=INFO
version: '3.8'
services:
eureka-server-1:
image: ghcr.io/tickatch/eureka-server:latest
container_name: tickatch-eureka-1
env_file:
- .env
environment:
- SERVER_PORT=3150
- SERVER_SERVLET_CONTEXT_PATH=/eureka1
- EUREKA_INSTANCE_HOSTNAME=eureka-server-1
- EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE=http://eureka-server-2:3151/eureka2/eureka/
- LOGSTASH_HOST=logstash:5000
ports:
- "3150:3150"
networks:
- tickatch-network
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3150/eureka1/actuator/health"]
interval: 30s
timeout: 10s
retries: 5
eureka-server-2:
image: ghcr.io/tickatch/eureka-server:latest
container_name: tickatch-eureka-2
env_file:
- .env
environment:
- SERVER_PORT=3151
- SERVER_SERVLET_CONTEXT_PATH=/eureka2
- EUREKA_INSTANCE_HOSTNAME=eureka-server-2
- EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE=http://eureka-server-1:3150/eureka1/eureka/
- LOGSTASH_HOST=logstash:5000
ports:
- "3151:3151"
networks:
- tickatch-network
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3151/eureka2/actuator/health"]
interval: 30s
timeout: 10s
retries: 5
networks:
tickatch-network:
external: true
| 엔드포인트 |
설명 |
/{context-path}/ |
Eureka 대시보드 |
/{context-path}/eureka/apps |
등록된 서비스 목록 |
/{context-path}/actuator/health |
헬스 체크 |
/{context-path}/actuator/info |
서비스 정보 |
/{context-path}/actuator/prometheus |
Prometheus 메트릭 |
/{context-path}/actuator/metrics |
Spring 메트릭 |
# eureka-server-1 대시보드
curl http://localhost:3150/eureka1/
# eureka-server-2 등록 서비스 목록
curl http://localhost:3151/eureka2/eureka/apps
# 헬스 체크
curl http://localhost:3150/eureka1/actuator/health
eureka-server/
├── src/
│ └── main/
│ ├── java/
│ │ └── com/tickatch/eurekaserver/
│ │ └── EurekaServerApplication.java
│ └── resources/
│ ├── application.yaml
│ └── logback-spring.xml
├── .env.example # 환경 변수 템플릿
├── .gitignore # .env 제외
├── docker-compose.yml
├── build.gradle
├── Dockerfile
└── README.md
server:
port: ${SERVER_PORT:8761}
spring:
application:
name: eureka-server
eureka:
instance:
hostname: ${EUREKA_INSTANCE_HOSTNAME:localhost}
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
server:
enable-self-preservation: ${EUREKA_SELF_PRESERVATION:false}
eviction-interval-timer-in-ms: 5000
| 설정 |
설명 |
register-with-eureka: false |
자기 자신은 등록하지 않음 (단독 실행 시) |
fetch-registry: false |
다른 서비스 목록 가져오지 않음 (단독 실행 시) |
enable-self-preservation: false |
개발 환경에서 빠른 장애 감지 |
eviction-interval-timer-in-ms: 5000 |
5초마다 비정상 인스턴스 제거 |
참고: 이중화 구성 시 register-with-eureka와 fetch-registry는 Docker Compose 환경변수로 오버라이드됩니다.
- Console: 표준 출력 (traceId, spanId 포함)
- Logstash: ELK 스택 연동 (TCP 5000 포트)
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%X{traceId:-},%X{spanId:-}] %-5level %logger{36} - %msg%n
logging:
level:
root: INFO
com.netflix.eureka: WARN # Eureka 내부 로그 최소화
com.netflix.discovery: WARN # Discovery 로그 최소화
| 엔드포인트 |
설명 |
/actuator/health |
서비스 상태 (상세 정보 포함) |
/actuator/prometheus |
Prometheus 메트릭 |
/actuator/metrics |
Spring 메트릭 |
/actuator/info |
서비스 정보 |
- Sampling Probability: 100% (
1.0)
- Zipkin 연동 지원
마이크로서비스에서 Eureka에 등록하려면:
eureka:
client:
service-url:
defaultZone: http://eureka-server-1:3150/eureka1/eureka/,http://eureka-server-2:3151/eureka2/eureka/
register-with-eureka: true
fetch-registry: true
instance:
prefer-ip-address: true
┌─────────────────────────────────────┐
│ Eureka Server (HA) │
│ ┌─────────────┐ ┌─────────────┐ │
│ │ :3150 │◄►│ :3151 │ │
│ │ /eureka1 │ │ /eureka2 │ │
│ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────┘
▲
│ 등록
│
┌─────────────┴─────────────┐
│ Microservices │
├───────────────────────────┤
│ Config Server (:3100) │
│ Gateway Server (:8080) │
│ Auth Service (:8090) │
│ User Service (:8091) │
│ Product Service (:8092) │
│ ... │
└───────────────────────────┘
Eureka Server는 가장 먼저 기동되어야 합니다.
.env 파일은 절대 Git에 커밋하지 마세요
- 운영 환경에서는
EUREKA_SELF_PRESERVATION=true 권장
- 두 Eureka 서버가 서로 다른 호스트에 배포되면 가용성 향상
- Context Path 설정 시 클라이언트도 동일하게 맞춰야 함