티스토리 뷰

이번엔 한번 Config-Server에 있는 Yml 파일을 조금 수정해볼려고 합니다. 


#ecommerce.yml

기존 token 값에서 ecommerce 값을 추가해줍니다.

token:
   expiration_time: 86400000
   secret: ggpark_token_ecommerce

gateway:
  ip: 0.0.0.0

#cmd

다시 cmd창을 열고 repositroy 가 있는 경로로 이동해줍니다.

그리고 아래의 커맨드를 입력해줍니다.

git add ecommerce.yml

git commit -m "changed some values"

#Test UserService 

Test를 위해서 다시 User-Service를 재시작해줍니다. 

정상적으로 바뀌었네요...

 

흠... 그런데 말이죠... 이거 묘하게 비효율적으로 보이지 않나요? 

서버도 다시 재시작해야하구...  이럴려고 Config-Server를 만든게 아닌데... 

그래서 이러한 점들을 개선하기 위해서 actuator를 사용합니다. 


#pom.xml

pom.xml 에 actuator를 주입시켜줍니다.

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

#WebSecurity.java

그리고 actuator는 API형태로 사용되기 때문에, 다음과 같이 접속을 허용해줍니다.

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.csrf().disable();
    //http.authorizeRequests().antMatchers("/users/**").permitAll();
    http.authorizeRequests().antMatchers("/actuator/**").permitAll();
    http.authorizeRequests().antMatchers("/**")
            .permitAll() //
            .and()
            .addFilter(getAuthenticationFilter());


    http.headers().frameOptions().disable();
}

 


#application.yml 

Application.yml파일에 다음과 같은 내용을 추가 해줍니다. 가장 중요한 것은 Refresh인데

해당 옵션이 있어야 Refresh를 통해서 yml내용을 업데이트 할 수 있습니다.

management:
   endpoints:
      web:
         exposure:
            include: refresh,health,beans #현재 서버가져올 Config 정보를 Refresh 하겠다는 의미

그럼 어디 테스트 해볼까요?


#Test

마찬 가지로 User-Service를 이번엔 실행 상태로! yml파일을 수정해보겠습니다. 

ecommerce.yml 파일의 token.secret값을 임의로 바꿔주세요. 

저는 다음과 같은 값으로 변경했습니다.

token:
   expiration_time: 86400000
   secret: my_name_is_ggpark_hahaha

gateway:
  ip: 0.0.0.0

 

cmd에서도 해당 정보를 UPDATE 해주시면 됩니다. 

//해당 파일이 있는 곳 으로 cd 후에 진행해주세요.

git add ecommerce.yml

git commit -m "changed some values"

 

자 그럼 어디한번 확인해볼까요?

왜 안되지??

 


#Test 2

Actuator는 API 방식으로 Refresh 가 필요합니다.

다음과 같이 /actuator/refresh 를 url에 붙혀서 POST방식으로 Send해줘야합니다.

그럼 다시한번 확인 해볼까요?

작아서 잘 안보이지만 token secret의 값이 바뀌었다!!

서버를 리부트 시키지 않아도 토큰 값이 변경 되어 있습니다. 엄청나지 않나요? 서버설정 시 귀찮게 서버를

껐다가 다시 켜야할 필요성이 0이 됐습니다!!  다음 시간에는 조금 만 더 자세하게 살펴볼게요.


감사합니다. 

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/09   »
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
29 30
글 보관함