背景
在SpringBoot 2应用中加入arthas-spring-boot-starter后,spring会启动arthas,并且attach自身进程,并配合tunnel server实现远程管理。这样的方案非常适合在微服务容器环境中进行远程诊断,在容器网络环境中仅需要对外暴露tunnel server的端口。
环境
JDK 1.8(arthas只能运行在JDK环境,JRE不支持)
SpringBoot 2.2.5.RELEASE
SpringCloud Hoxton.SR3
SpringCloudAlibaba 2.2.1.RELEASE
arthas-spring-boot-starter 3.4.4
部署Arthas tunnel server和WebConsole
1.从https://github.com/alibaba/arthas/releases下载arthas-tunnel-server-3.4.4-fatjar.jar
2.Arthas tunnel server是一个spring boot fat jar应用,直接启动:
java -jar arthas-tunnel-server-3.4.4-fatjar.jar
3.启动之后,可以访问http://127.0.01:8080打开WebConsole;
4.Arthas agent端口是7777,用于和每个SpringBoot应用的Arthas进行通信,这个端口会在后面用到。
在SpringBoot应用中引入Arthas
pom.xml依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>com.taobao.arthas</groupId>
<artifactId>arthas-spring-boot-starter</artifactId>
<version>3.4.4</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.5.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependencies>
</dependencyManagement>
application.yml配置
arthas:
agent-id: URJZ5L48RPBR2ALI5K4V #需手工指定agent-id
tunnel-server: ws://127.0.0.1:7777/ws
使用WebConsole连接
打开WebConsole,分别输入Arthas agent的ip(127.0.0.1)和port(7777),和SpringBoot应用里配置的agent-id(URJZ5L48RPBR2ALI5K4V),点Connect即可。
有关Arthas命令详见官方文档。