• Arthas实操-Web Console


    一、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)

    1. ssh root@47.105.*.74
    2. #输入登录密码

    2、下载并启动math-game

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

    3.2 下载并启动 arthas

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

    1. ssh root@47.105.*.74
    2. #输入登录密码

    2、下载并启动arthas

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

    运行结果:

    1. root@iZm5eetszs07500os8erolZ:~/data/arthas# java -jar arthas-boot.jar
    2. [INFO] arthas-boot version: 3.6.5
    3. [INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
    4. * [1]: 24865 demo-0.0.1-SNAPSHOT.jar
    5. [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
    

    参数说明:

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

    运行结果:

    1. root@iZm5eetszs07500os8erolZ:~/data/arthas# java -jar arthas-boot.jar --target-ip 0.0.0.0 --http-port 8563 25771
    2. [INFO] arthas-boot version: 3.6.5
    3. [INFO] arthas home: /root/.arthas/lib/3.6.5/arthas
    4. [INFO] Try to attach process 25771
    5. [INFO] Attach process 25771 success.
    6. [INFO] arthas-client connect 0.0.0.0 3658
    7. ,---. ,------. ,--------.,--. ,--. ,---. ,---.
    8. / O \ | .--. ''--. .--'| '--' | / O \ ' .-'
    9. | .-. || '--'.' | | | .--. || .-. |`. `-.
    10. | | | || |\ \ | | | | | || | | |.-' |
    11. `--' `--'`--' '--' `--' `--' `--'`--' `--'`-----'
    12. wiki https://arthas.aliyun.com/doc
    13. tutorials https://arthas.aliyun.com/doc/arthas-tutorials.html
    14. version 3.6.5
    15. main_class
    16. pid 25771
    17. time 2022-08-31 16:01:23
    18. [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就可以了。

    错误场景:

    1. root@iZm5eetszs07500os8erolZ:~/data/arthas# java -jar arthas-boot.jar --target-ip 47.105.xxx.74 --http-port 8563 25771
    2. [INFO] arthas-boot version: 3.6.5
    3. [INFO] arthas home: /root/.arthas/lib/3.6.5/arthas
    4. [INFO] Try to attach process 25771
    5. [INFO] Attach process 25771 success.
    6. [INFO] arthas-client connect 47.105.146.74 3658
    7. Connect to telnet server error: 47.105.xxx.74 3658
    8. java.net.ConnectException: Connection refused (Connection refused)
    9. at java.net.PlainSocketImpl.socketConnect(Native Method)
    10. at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    11. at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    12. at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    13. at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    14. at java.net.Socket.connect(Socket.java:607)
    15. at org.apache.commons.net.SocketClient.connect(SocketClient.java:188)
    16. at org.apache.commons.net.SocketClient.connect(SocketClient.java:209)
    17. at com.taobao.arthas.client.TelnetConsole.process(TelnetConsole.java:306)
    18. at com.taobao.arthas.client.TelnetConsole.main(TelnetConsole.java:166)
    19. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    20. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    21. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    22. at java.lang.reflect.Method.invoke(Method.java:498)
    23. at com.taobao.arthas.boot.Bootstrap.main(Bootstrap.java:615)
    24. Usage: arthas-client [--help] [-c <value>] [-f <value>] [-w <value>] [-t
    25. <value>] [-h <value>] [target-ip] [port]
    26. Arthas Telnet Client
    27. EXAMPLES:
    28. java -jar arthas-client.jar 127.0.0.1 3658
    29. java -jar arthas-client.jar -c 'dashboard -n 1'
    30. java -jar arthas-client.jar -f batch.as 127.0.0.1
    31. Options and Arguments:
    32. --help Print usage
    33. -c,--command <value> Command to execute, multiple commands
    34. separated by ;
    35. -f,--batch-file <value> The batch file to execute
    36. -w,--width <value> The terminal width
    37. -t,--execution-timeout <value> The timeout (ms) of execute commands or batch
    38. file
    39. -h,--height <value> The terminal height
    40. <target-ip> Target ip
    41. <port> The remote server port
    42. 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操作详细搭建步骤说明

  • 相关阅读:
    pyqt5的组合式部件制作(一)
    SAGI GAMES 创始人曾嵘:瞄准休闲游戏,将“创意”转化为“商业”
    ctf web基础php
    阿里测开面试大全(一)附答案完整版
    el-table多选表格 实现默认选中 删除选中列表取消勾选等联动效果
    Netlogo 之Extension 之 Table 扩展实现Map 键值对功能
    《确保安全:PostgreSQL安全配置与最佳实践》
    Spring5 框架学习笔记
    【Unity】3D贪吃蛇游戏制作/WebGL本地测试及项目部署
    TPU编程竞赛系列|基于TPU平台的人车目标检测初赛收官!
  • 原文地址:https://blog.csdn.net/a772304419/article/details/126856774