Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

记录如何使用arthas进行远程访问 #442

Closed
haifzhu opened this issue Jan 12, 2019 · 5 comments
Closed

记录如何使用arthas进行远程访问 #442

haifzhu opened this issue Jan 12, 2019 · 5 comments

Comments

@haifzhu
Copy link

haifzhu commented Jan 12, 2019

背景

arthas需要在本地进行attach, 通常情况下,开发没有权限登录服务器,如何让开发使用arthas进行远程诊断呢?

公司内部一般都有一些web管理平台,供开发者去管理自己的应用,如何把arthas集成到自己的web管理平台?

实现思路

在公司内部的web管理平台,基于某个主机上的某个应用有个叫开启arthas调试的按钮,点击该按钮会触发如下操作:

  1. 登录到对应服务器上,基于应用名称查找对应的pid
  2. 检查默认的http端口是不是有pid在监听
  3. 如果该端口没有被监听,直接attach该pid之后返回
    attach命令: sudo su - <应用启动用户> -c "java /opt/arthas/lib/3.0.5/arthas/arthas-boot.jar --target-ip <主机IP> --attach-only <应用pid>"
  4. 如果监听的pid跟应用的pid相同,直接返回
  5. 如果不同,则使用命令shutdown之后,再进行attach操作
    shutdown操作:sudo java /opt/arthas/lib/3.0.5/arthas/arthas-client.jar -c shutdown <主机IP> <http端口>
  6. attach之后,然后再通过web-console连接到该主机IP, 以及http端口就可以使用了

该实现已经被使用起来了

问题

在多个开发者同时针对一个主机上应用进行使用arthas调试的时候可能会出现相互shutdown的情况,这个可以通过流程规范就可以了, 或者有个选择是否把对方连接shutdown的选择;对于这种也可以维护一个端口池,同一个主机上不同应用进行attach的时候使用不同端口,这样就可以解决冲突问题

截图

image

image

@sqtds
Copy link

sqtds commented Jan 23, 2019

第三步,attach的时候如何判断远程进程是用的哪个jvm版本呢?如果版本不一致,attach有可能失败

@haifzhu
Copy link
Author

haifzhu commented Jan 29, 2019

第三步,attach的时候如何判断远程进程是用的哪个jvm版本呢?如果版本不一致,attach有可能失败

java安装路径以及版本都可以规范统一

@iceqing
Copy link

iceqing commented Feb 21, 2019

请问如果这样子是不是只要知道ip地址和端口,就可以attach了?会不会有安全问题?

@jujunchen
Copy link

这个是你们内部的管理界面吗?有开源的嘛?

@takejian
Copy link

请问AgentId怎么获取的?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants