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

JRE环境下借助jattach使用arthas #2999

Open
1 task done
stqf opened this issue Mar 21, 2025 · 1 comment
Open
1 task done

JRE环境下借助jattach使用arthas #2999

stqf opened this issue Mar 21, 2025 · 1 comment

Comments

@stqf
Copy link

stqf commented Mar 21, 2025

  • 我已经在 issues 里搜索,没有重复的issue。

环境信息

  • arthas-boot.jar 或者 as.sh 的版本: 4.0.3
  • Arthas 版本: 4.0.3
  • 操作系统版本: Linux rabbitmq1 5.10.0-60.18.0.50.oe2203.aarch64 SMP Wed Mar 30 02:43:08 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
  • 目标进程的JVM版本: openjdk version "1.8.0_342"
  • 执行arthas-boot的版本: 4.0.3

重现问题的步骤

  1. 执行命令 jattach 1854582 load instrument false "$PWD/arthas-agent.jar=--target-pid=1854582" 加载agent
  2. 第一天能成功加载 响应如下:
    Connected to remote JVM
    JVM response code = 0
    0
    且成功监听3658和8563端口, 再次通过java -jar $PWD/arthas-client.jar 可以成功连接进入console使用
  3. 第二天不能加载成功, 响应如下:
    Connected to remote JVM
    JVM response code = 0
    100
    3658和8563端口未监听, 再次通过java -jar $PWD/arthas-client.jar 可以连接失败. 未找到任何arthas日志

期望的结果

  1. 在仅存在JRE的环境中, 借助jattach加载agent的详细指导
  2. 响应100表示什么意思? 相关日志在哪里?
  3. 部分环境下通过 jattach 1854582 load instrument false "$PWD/arthas-agent.jar=ip=0.0.0.0" 可以全零监听部分情况不可以 这又是为何? 具体执行的参数有哪些?

实际运行的结果

Image

@TulanCN
Copy link

TulanCN commented Mar 24, 2025

以前我遇到过类似需求,当时写了一份脚本。

#!/bin/bash

# 获取当前脚本所在的目录
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)

# 用户输入进程ID
read -p "请输入进程ID: " pid

# 用户输入可选参数host,提供默认值
read -p "请输入主机地址和端口号(格式:IP 端口,默认为 127.0.0.1 3658): " host
host=${host:-"127.0.0.1 3658"}

# 检查当前目录下是否存在jattach文件
if [[ ! -e "$script_dir/jattach" ]]; then
  # 查找以jattach-linux开头的tgz压缩包
  jattach_tgz=$(find "$script_dir" -maxdepth 1 -type f -name "jattach-linux-*.tgz")

  if [[ -z "$jattach_tgz" ]]; then
    echo "当前目录下未找到名为jattach的文件或符合条件的jattach-linux-*.tgz压缩包。"
    exit 1
  fi

  # 判断系统架构
  system_arch=$(uname -m)
  case $system_arch in
    "aarch64"|"arm64")
      arch="arm64"
      jattach_file="jattach-linux-arm64.tgz"
      ;;
    "x86_64"|"amd64")
      arch="x64"
      jattach_file="jattach-linux-x64.tgz"
      ;;
    *)
      echo "当前系统架构不支持自动解压jattach工具。"
      exit 1
  esac

  # 检查对应的jattach压缩包是否存在
  if [[ ! -f "$script_dir/$jattach_file" ]]; then
    echo "当前目录下未找到与系统架构匹配的$jattach_file压缩包。"
    exit 1
  fi

  # 解压缩对应架构的jattach工具到当前脚本目录,并使用绝对路径
  tar -xzvf "$script_dir/$jattach_file" -C "$script_dir"

  # 检查解压后jattach是否成功生成
  if [[ ! -e "$script_dir/jattach" ]]; then
    echo "解压失败或未能在当前目录找到解压后的jattach文件。"
    exit 1
  fi
fi

# 使用jattach命令加载arthas-agent.jar,使用绝对路径
"$script_dir/jattach" $pid load instrument false "$script_dir/arthas-agent.jar" && \

# 运行arthas客户端,同样使用绝对路径
java -jar "$script_dir/arthas-client.jar" $host

使用方式是把jattach的安装包和这份脚本一起放在arthas的安装目录下,会自动执行安装和attach的操作。路径很重要,不要错。

之前在很多环境验证过,都能正常使用。

我看脚本中的attach逻辑和你提供的命令似乎不太一样,但是我后来也没深究,所以不能回答你的问题。

而且你遇到的问题看上去也并不是Arthas的问题。

另外,这份脚本并没有在docker中验证过,大概率是不可用的😂。

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

No branches or pull requests

2 participants