
在项目在部署平台上运行的时候,作为开发想要监控平台上运行项目的情况,可以使用Rancher管理端平台
但是网页上使用WebSocket去查看运行命令行,我个人感觉是有点卡的、操作效果不太好并且无法进行相关的文件操作
因此想要将这些操作都在windows上终端中显示出来

在Rancher UI平台获取API 端点<SERVER_URL> 创建长期的API 密钥<BEARER_TOKEN>
rancher login https://<SERVER_URL> --token <BEARER_TOKEN>在Rancher UI平台下载KubeConfig.yaml放入kubectl的文件缓存.kube文件夹下
rancher namespacesrancher kubectl get po -n myprojectkubectl exec -it mypod1-7c8848-8z8848 -n myproject /bin/bashkubectl exec -it mypod1-7c8848-8z8848 -n myproject -- /bin/bashkubectl cp -n myproject mypod1-7c8848-8z8848:/app.jar ./app.jarkubectl logs -f -n myproject mypod1-7c8848-8z8848kubectl logs -f --tail 5 -n myproject mypod1-7c8848-8z8848kubectl logs --since=30m -n <namespace> <pod-name> > logs.txt推荐使用IDEA Arthas插件 参考文档:爱上Java诊断利器Arthas之Arthas idea plugin 的前世今生
Arthas 向控制台输出内容使用的默认编码,可以通过指定 file.encoding 设置默认编码。
java -Dfile.encoding=UTF-8 -jar arthas-boot.jar如果要使用Ognl表达式来实现相关的操作 就需要获取获取classloader的hash 值
sc -d com.xxx.xxx.xxxServiceImpl根据唯一类名下的常量名获取
getstatic com.xxx.xxx.xxxServiceImpl xxxTemplatePrefix -x 3Ognl表达式获取
ognl -x 3 '@com.xxx.xxxServiceImpl@xxxTemplatePrefix ' -c 38848be2Ognl表达式替换静态常量
ognl -x 3 '#field=@com.xxx.impl.xxxServiceImpl@class.getDeclaredField("xxxTemplatePrefix "),#field.setAccessible(true),#field.set(null,"设置的值")' 有三种方式
第一种自主配置 (要额外配置代码 算了)
第二种 watch 支持在spring mvc场景 通过watch 间接的获取spring context
监听方法需要调用经过激活
watch com.xxx.xxxController createXxx '{params,returnObj,throwExp}' -n 5 -x 3 在yaml文件时,这种基本上参照properties的形式 所以在查找yml文件的环境变量的时候 需要转换成一行的形式
举例:查找数据库地址环境变量
vmtool -x 3 --action getInstances --className org.springframework.core.env.ConfigurableEnvironment --express 'instances[0].getProperty("spring.datasource.url") ' -c 38848be2获取这个getUsername方法的反编译结果
jad --source-only com.xxx.impl.xxxServiceImpl getUsername原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。