스프링부트가 가지고 있는 강력한 기능 중 하나가, 바로 액츄에이터 이다. 그 중에서 내가 지금까지 몰랐던 Remote Shell에 대한 기능을 살펴본다. 리모트쉘은 별다른 코딩을 하지 않아도 사용이 가능하다.
리모트쉘의 의존성은 다음과 같다.
dependencies {compile("org.springframework.boot:spring-boot-starter-remote-shell")// 생략}
org.springframework.boot:spring-boot-starter-security 을 추가하지 않으면 다음 클래과 같은 예외가 발생하며 실패한다.
Caused by: java.lang.ClassNotFoundException: org.springframework.security.config.http.SessionCreationPolicyat java.net.URLClassLoader$1.run(URLClassLoader.java:361)at java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(URLClassLoader.java:360)at java.lang.ClassLoader.loadClass(ClassLoader.java:424)at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)at java.lang.ClassLoader.loadClass(ClassLoader.java:357)... 42 more:bootRun FAILED
SSH와 관련해서 필요한 것으로 보인다. 리모트쉘의 기본포트는 2000번이다. 이 부분은 다음에 있는 설정코드에서 수정가능하다. 리모트쉘에서 사용하는 속성은 다음과 같다. 자세한 내용은 레퍼런스 문서를 살펴보기 바란다.
# REMOTE SHELLshell.auth=simple # jaas, key, simple, springshell.command-refresh-interval=-1shell.command-path-patterns= # classpath*:/commands/**, classpath*:/crash/commands/**shell.config-path-patterns= # classpath*:/crash/*shell.disabled-commands=jpa*,jdbc*,jndi* # comma-separated list of commands to disableshell.disabled-plugins=false # don't expose pluginsshell.ssh.enabled= # ssh settings ...shell.ssh.key-path=shell.ssh.port=shell.telnet.enabled= # telnet settings ...shell.telnet.port=shell.auth.jaas.domain= # authentication settings ...shell.auth.key.path=shell.auth.simple.user.name=shell.auth.simple.user.password=shell.auth.spring.roles=
내가 테스트를 위해 설정한 속성은 다음과 같다. application.yml:
# @author: honeymonmanagement:shell:port: 10000port: 10001password: remote-shell
리모트쉘에 접근하는 방법은 다음과 같다.
ssh -p <port-number> <shell.auth.simple.user.name 값>@접근서버 IP 혹은 호스트명//위의 설정에 따르면 다음과 같이 접근이 가능하다.ex) $ ssh -p 10001 honeymon@localhost
텔넷으로 접근하려면 다음의 의존성을 추가해야 한다.
If you want to also enable telnet access you will additionally need a dependency on
org.crsh:crsh.shell.telnetsearch.maven.org crsh.shell.telnet 검색 telnet 접속해보려고 했더니 오류가 발생...
Caused by: java.lang.NoSuchMethodError: org.crsh.vfs.Resource.<init>(Ljava/net/URL;)Vat org.crsh.plugin.PluginManager.getPlugins(PluginManager.java:83)at org.crsh.plugin.PluginContext.start(PluginContext.java:327)at org.crsh.plugin.PluginLifeCycle.start(PluginLifeCycle.java:104)at org.springframework.boot.actuate.autoconfigure.CrshAutoConfiguration$CrshBootstrapBean.init(CrshAutoConfiguration.java:230)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:483)at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:349)at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:300)at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133)... 17 more
처음 접근할 경우에는 다음과 같이 인증키를 저장할지를 묻는다.
리모트쉘로 접근하면 다음과 같은 화면을 볼 수 있다.
리모트쉘에서 사용할 수 있는 명령어는 help 를 타이핑하면 다음과 같은 내용을 볼 수 있다.
> helpTry one of these commands with the -h or --help switch:NAME DESCRIPTIONautoconfig Display auto configuration report from ApplicationContextbeans Display beans in ApplicationContextcron manages the cron plugindashboard a monitoring dashboardegrep search file(s) for lines that match a patternendpoint Invoke actuator endpoints //앱에 설정된 애드포인트 목록들을 확인가능하다.env display the term envfilter a filter for a stream of mapjava various java language commandsjmx Java Management Extensionsjul java.util.logging commandsjvm JVM informationsless opposite of moremail interact with emailsman format and display the on-line manual pagesmetrics Display metrics provided by Spring Bootshell shell related commandsleep sleep for some timesort sort a mapsystem vm system properties commandsthread JVM thread commandshelp provides basic helprepl list the repl or change the current repl
리모트쉘은 CRaSH를 사용했다. 배너를 바꾸고 싶은데... 그 중에서 우와!!하면서 감탄했던 것이 대시보드!
화면크기에 따라 리사이징도 된다! +_+)b
스프링 액츄에이터SpringBoot actuator 에서 제공하는 엔드포인트 중 하나인 metrics 정보를 모니터링할 수 있는 metrics
리모트쉘로 원격접속해서 애플리케이션의 상태를 살필 수 있는 수단이 생겼다는 건 애플리케이션을 관리하는데 더욱 편해진다는 것이다. 리모트쉘로 접근해서... endpoint invoke shutdown을 실행하면!!
당신은 주금!!(애플리케이션을 켜로 터미널로 서버에 접속해야하는 번거로움이 생길 것이다).
리모트쉘에서 애플리케이션을 끄기 위해서는
리모트쉘에서 셧타운을 실행하기 위해서는 application.properties(or yml)에 다음 항목을 추가해야한다.
endpoints.shutdown.enabled=true
이렇게 가볍게 스프링부트가 제공하는 기능 중 하나인 리모트쉘Remote shell을 살펴봤다. 리모트쉘을 통해서 애플리케이션의 상태를 모니터링하고 제어하는 것이 가능해졌다. 스프링부트를 기반으로 배포하는 앱에는 반드시 넣어줘야할 녀석이었다. 바로! 추가!
'Java > SpringBoot' 카테고리의 다른 글
| [SpringBoot] 스프링부트 시작하기 (0) | 2015.09.25 |
|---|---|
| [SpringBoot] 스프링부트 참고문서(1.2.0.BUILD-SNAPSHOT) (아직도)번역중 (0) | 2015.09.10 |
| [SpringBoot] 스프링부트 소개 (0) | 2015.08.02 |
| [SpringBoot] - @ConfigurationProperties in STS (0) | 2015.07.14 |
| SpringBoot: h2database에 접근할 수 있는 h2console 을 애플리케이션과 함께 사용하기 (0) | 2015.05.20 |