zl程序教程

您现在的位置是:首页 >  前端

当前栏目

Arthas实操-Web Console

Web Console 实操 arthas
2023-09-14 09:02:03 时间

一、Arthas Web Console简介

Web Console是arthas提供的web页面,它可以让用户在自己的电脑上,连接远程服务器的arthas执行命令,命令的执行方式和在服务器直接操作没有任何区别。Web Console连接远程服务器成功后是这样的,几乎和服务器的界面一样。

二、开放端口

因为需要访问远程服务器,所以要在远程服务器上对本地网络开放 ip 和端口策略,否则无法使用 Web Console。在远程服务器上启动 arthas,启动时要指定 ip 和端口。在阿里云ECS上开放85633658两个端口。

  • Web Console默认使用8563端口。--http-port 参数可以修改Web Console端口。

  • telnet默认使用3658端口。--telnet-port 可以修改telnet端口。

三、操作

3.1 下载并启动math-game

1、登录连接到ECS服务器(窗口1)

ssh root@47.105.*.74

#输入登录密码

2、下载并启动math-game

curl -O https://arthas.aliyun.com/math-game.jar

java -jar math-game.jar

3.2 下载并启动 arthas

1、登录连接到ECS服务器(窗口2)

ssh root@47.105.*.74

#输入登录密码

2、下载并启动arthas

curl -O https://arthas.aliyun.com/arthas-boot.jar

java -jar arthas-boot.jar

运行结果:

root@iZm5eetszs07500os8erolZ:~/data/arthas# java -jar arthas-boot.jar
[INFO] arthas-boot version: 3.6.5
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 24865 demo-0.0.1-SNAPSHOT.jar
  [2]: 25771 math-game.jar

可以看到math-game运行的进程ID是25771,这个进程ID后面会用到。

3.3 启动时指定 ip 和端口

在窗口2中执行:关闭arthas,重新启动。在远程服务器上启动arthas,启动时要指定IP和端口。

java -jar arthas-boot.jar --target-ip 0.0.0.0 --http-port 8563 25771

参数说明:

java -jar arthas.jar:启动命令
--target-ip:指定Web Console连接的IP,也就是服务器的外网IP
--http-port:指定Web Console连接的端口,也就是服务器对外暴露的端口
25771:要监听的java程序的进程ID,即math-game.jar进程ID

运行结果:

root@iZm5eetszs07500os8erolZ:~/data/arthas# java -jar arthas-boot.jar --target-ip 0.0.0.0 --http-port 8563 25771
[INFO] arthas-boot version: 3.6.5
[INFO] arthas home: /root/.arthas/lib/3.6.5/arthas
[INFO] Try to attach process 25771
[INFO] Attach process 25771 success.
[INFO] arthas-client connect 0.0.0.0 3658
  ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.
 /  O  \ |  .--. ''--.  .--'|  '--'  | /  O  \ '   .-'
|  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-.
|  | |  ||  |\  \    |  |   |  |  |  ||  | |  |.-'    |
`--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----'

wiki       https://arthas.aliyun.com/doc
tutorials  https://arthas.aliyun.com/doc/arthas-tutorials.html
version    3.6.5
main_class
pid        25771
time       2022-08-31 16:01:23

[arthas@25771]$

3.4 在浏览器中访问Web Console

在浏览器中输入地址:http://47.105.xxx.74:8563

效果如下:

Web Console

3.5 scrollback URL 参数

scrollback URL 参数3.5.5 版本后支持,默认 Web Console 支持向上回滚的行数是1000。可以在 URL 里用scrollback指定。比如:http://127.0.0.1:8563/?scrollback=3000

四、注意

Web Console需要服务器暴露IP和端口,如果服务器是云端部署,需要考虑网络安全的问题,比如端口只开放给某一个来源IP。

五、实操遇到的问题

5.1 Connect to telnet server error

一开始我将--target-ip设置成了我ECS外网的IP,47.105.xxx.74,启动arthas失败,提示Connect to telnet server error异常。将IP改成--target-ip 0.0.0.0就可以了。

错误场景:

root@iZm5eetszs07500os8erolZ:~/data/arthas# java -jar arthas-boot.jar --target-ip 47.105.xxx.74 --http-port 8563 25771
[INFO] arthas-boot version: 3.6.5
[INFO] arthas home: /root/.arthas/lib/3.6.5/arthas
[INFO] Try to attach process 25771
[INFO] Attach process 25771 success.
[INFO] arthas-client connect 47.105.146.74 3658
Connect to telnet server error: 47.105.xxx.74 3658
java.net.ConnectException: Connection refused (Connection refused)
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:607)
        at org.apache.commons.net.SocketClient.connect(SocketClient.java:188)
        at org.apache.commons.net.SocketClient.connect(SocketClient.java:209)
        at com.taobao.arthas.client.TelnetConsole.process(TelnetConsole.java:306)
        at com.taobao.arthas.client.TelnetConsole.main(TelnetConsole.java:166)
        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:498)
        at com.taobao.arthas.boot.Bootstrap.main(Bootstrap.java:615)
Usage: arthas-client [--help] [-c <value>] [-f <value>] [-w <value>] [-t
       <value>] [-h <value>] [target-ip] [port]

Arthas Telnet Client

EXAMPLES:
  java -jar arthas-client.jar 127.0.0.1 3658
  java -jar arthas-client.jar -c 'dashboard -n 1'
  java -jar arthas-client.jar -f batch.as 127.0.0.1

Options and Arguments:
    --help                        Print usage
 -c,--command <value>             Command to execute, multiple commands
                                  separated by ;
 -f,--batch-file <value>          The batch file to execute
 -w,--width <value>               The terminal width
 -t,--execution-timeout <value>   The timeout (ms) of execute commands or batch
                                  file
 -h,--height <value>              The terminal height
 <target-ip>                      Target ip
 <port>                           The remote server port

root@iZm5eetszs07500os8erolZ:~/data/arthas#

https://www.jianshu.com/p/632abcc9a9eficon-default.png?t=M85Bhttps://www.jianshu.com/p/632abcc9a9ef

参考资料:
Arthas-Web Console官方文档

在 Web Console 复制粘贴快捷键参考

arthas的webconsole操作详细搭建步骤说明