2. Spring Cloud를 이용한 MSA 구축하기 - config server

프로그래밍|2017. 9. 22. 17:32

https://github.com/namkyu/test_spring_cloud/tree/master/config-servicespring cloud config은 서버와 클라이언트로 나뉜다.

서버에서는 각 클라이언트들의 설정 정보들을 관리하고 클라이언트는 자신의 설정 정보를 config 서버로부터 받아와 사용한다.

이처럼 서비스와 설정을 분리하게 됨으로써 여러 가지 장점을 얻을 수 있다. (갑자기 관심사 분리라는 객체지향 기법이 생각난다.)

 - 설정 관리의 용이성

 - 설정 변경으로 인한 빌드 및 배포 필요 없음




스프링 부트를 이용한 spring cloud config 서버 설정 방법


pom.xml 파일

1
2
3
4
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-server</artifactId>
</dependency>
cs


애노테이션 설정 추가

1
2
3
4
5
6
7
8
@EnableConfigServer
@SpringBootApplication
public class ConfigServiceApplication {
 
    public static void main(String[] args) {
        SpringApplication.run(ConfigServiceApplication.class, args);
    }
}
cs


application.yml

설정 파일 관리에 git을 이용하지 않고 config 서버의 특정 경로에서 관리하도록 하였음 (회사 정책상)

클래스패스의 configs 디렉토리에 config client 설정 파일들 존재

이와 같은 방법의 단점은 yml 설정이 변경되었을 경우 config 서버를 재시작해야 한다.

configs

   |_ eureka-service.yml

   |_ front-service.yml

   |_ order-service.yml


1
2
3
4
5
6
7
8
9
10
11
12
13
server:
  port: 8888
 
spring:
  profiles:
    active: native
  application:
    name: config-service
  cloud:
    config:
      server:
        native:
          searchLocations: classpath:/configs
cs


yml 설정 파일 내용을 웹으로 확인해 보자.

http://localhost:8888/{APPLICATION_NAME}/{profiles}

http://localhost:8888/eureka-service/master


망별 설정 파일 관리는 다음과 같이 한다.

1
2
3
front-service-dev.yml
front-service-test.yml
front-service-live.yml
cs


또는

1
2
3
4
5
6
7
8
9
10
11
---
spring:
  profiles: dev
  
---
spring:
  profiles: test
  
---
spring:
  profiles: live
cs


전체 소스 : https://github.com/namkyu/test_spring_cloud/tree/master/config-service

댓글()