实际上就是一个玩法,实际上因为jdwp 是基于tcp 协议的,我们可以使用任何合适的tcp lb 工具解决(iptables 也是可以的)只是rinetd
使用起来还是比较简单的,同时包含了一些简单的访问控制还是不错的
jdwp 使用玩法
集成参考图
环境&测试
一个spring boot 应用,启动的时候开启了jdwp 协议
- docker-compose
version: '3'
services:
app:
build: ./
ports:
- 8080:8080
- 9090:9090
networks:
app:
ipv4_address: 172.16.238.10
proxy:
build:
context: .
dockerfile: ./proxy-Dockerfile
ports:
- 19090:19090
networks:
app:
ipv4_address: 172.16.238.11
networks:
app:
ipam:
driver: default
config:
- subnet: "172.16.238.0/24"
spring boot app dockerfile
FROM eclipse-temurin:8-jdk-alpine
WORKDIR /app
COPY app.jar /app/
COPY app.sh /app/app.sh
RUN chmod +x /app/app.sh
ENTRYPOINT [ "/app/app.sh" ]
app.sh
#!/bin/sh
java -agentlib:jdwp=transport=dt_socket,address=9090,server=y,suspend=n -jar /app/app.jar
proxy dockerfile (基于centos 镜像)
FROM centos:centos7.9.2009
COPY rinetd /app/rinetd
COPY rinetd.conf /app/rinetd.conf
RUN chmod +x /app/rinetd
ENTRYPOINT [ "/app/rinetd","-c","/app/rinetd.conf","-f" ]
rinetd.conf 转发配置,添加如下就可以了
0.0.0.0 19090 172.16.238.10 9090
- 调试
idea 配置
效果
说明
完整代码在github 中,大家可以参考,实际上以上是一个玩法,基于haproxy,nginx (4层proxy),k8s 的nodeport 转发。。。。都是不多的选择
参考资料
https://dzone.com/articles/remote-debugging-java-applications-with-jdwp
https://docs.oracle.com/javase/8/docs/technotes/guides/jpda/jdwp-spec.html
https://blog.aquasec.com/jdwp-misconfiguration-container-images
https://github.com/rongfengliang/rinetd-rpm
https://github.com/rongfengliang/rinetd-java-debug-learning