频道栏目
首页 > 网络 > 其他 > 正文

k8s 集群容器中集成arthas、netstat即时诊断分析工具-一万小时定律-51CTO博客

2019-08-07 20:45:27           
收藏   我要投稿

背景:k8s 集群中,java应用容器中添加即时工具分析诊断arthas、netstat

1.预先下载好arthas-packaging-3.1.1-bin.zip文件,在Dockerfile同目录下,并且重命名为arthas.zipwget http://repo1.maven.org/maven2/com/taobao/arthas/arthas-packaging/3.1.1/arthas-packaging-3.1.1-bin.zip

mv arthas-packaging-3.1.1-bin.zip arthas.zip

2.netstat工具在alpine下为ospd-netstat,在Dockerfile直接apk add 添加即可

3.以下为Dokcerfile文件(注:需要openjdk,如果是jre的,会缺少dt.jar,tools.jar arthas工具会使用到;需要安装tini工具,因为默认java 应用跑在容器中会是1 pid号,arthas会无法调用)FROM openjdk:8-jdk-alpineCOPY repositories /etc/apk/RUN apk add --no-cache mesa-gl \ttf-freefont \ospd-netstat \curl \tini \jq \ttf-dejavu \tzdata && \ mkdir -p /usr/local/arthas && \rm -rf /var/cache/apk/*

设置环境变量

ENV TZ=Asia/Shanghai

设置时区

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezoneCOPY simhei.ttf /usr/share/fonts/COPY simkaigb2312.ttf /usr/share/fonts/COPY simsun.ttc /usr/share/fonts/simsun.ttcCOPY arthas.zip /tmp/ADD ./health.sh /RUN unzip /tmp/arthas.zip -d /usr/local/arthas && \rm -rf /tmp/arthas.zip

4.镜像打包,并推至私有仓库docker build -t 192.168.3.10:5001/library/javabase:v8.0.22 .docker push 192.168.3.10:5001/library/javabase:v8.0.22

5.问题总结:如果未安装tini工具,并且在启动时,预先执行 ENTRYPOINT ["/sbin/tini", "--"] ,在执行 CMD ["sh","-c","java -Xms1500m -Xmx1500M -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -jar /usr/local/factoring_web/xxxx.jar"]不然会如下报错:

[ERROR] Start arthas failed, exception stack trace: com.sun.tools.attach.AttachNotSupportedException: Unable to get pid of LinuxThreads manager threadat sun.tools.attach.LinuxVirtualMachine.<init>(LinuxVirtualMachine.java:86)at sun.tools.attach.LinuxAttachProvider.attachVirtualMachine(LinuxAttachProvider.java:78)at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:250)at com.taobao.arthas.core.Arthas.attachAgent(Arthas.java:75)at com.taobao.arthas.core.Arthas.<init>(Arthas.java:28)at com.taobao.arthas.core.Arthas.main(Arthas.java:113)[INFO] Attach process 1 success.[INFO] arthas-client connect 127.0.0.1 3658Connect to telnet server error: 127.0.0.1 3658java.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:589)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.main(TelnetConsole.java:268)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:503)

正常执行成功:/usr/local/arthas # java -jar arthas-boot.jar Picked up JAVA_TOOL_OPTIONS: -javaagent:/home/admin/.opt/ArmsAgent/arms-bootstrap-1.7.0-SNAPSHOT.jar -Darms.licenseKey=fqkkah9ke2@1f6f53b91f6e3fd -Darms.appName=test-factoring-web -Darms.agent.env=ACSK8S -Darms.agent.args= 2019-08-06 17:28:47 WARN JDK version=1.8.0_212SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".SLF4J: Defaulting to no-operation (NOP) logger implementationSLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.2019-08-06 17:28:50 WARN arms agent start cost: 3755ms[INFO] arthas-boot version: 3.1.1[INFO] Found existing java process, please choose one and hit RETURN.

[1]: 6 /usr/local/factoring_web/app.jar1[INFO] arthas home: /usr/local/arthas[INFO] Try to attach process 6Picked up JAVA_TOOL_OPTIONS: -javaagent:/home/admin/.opt/ArmsAgent/arms-bootstrap-1.7.0-SNAPSHOT.jar -Darms.licenseKey=fqkkah9ke2@1f6f53b91f6e3fd -Darms.appName=test-factoring-web -Darms.agent.env=ACSK8S -Darms.agent.args= 2019-08-06 17:31:17 WARN JDK version=1.8.0_212SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".SLF4J: Defaulting to no-operation (NOP) logger implementationSLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.2019-08-06 17:31:20 WARN arms agent start cost: 3623ms[INFO] Attach process 6 success.[INFO] arthas-client connect 127.0.0.1 3658,---. ,------. ,--------.,--. ,--. ,---. ,---. / O \ | .--. ''--. .--'| '--' | / O \ ' .-' | .-. || '--'.' | | | .--. || .-. |.-. | | | || |\ \ | | | | | || | | |.-' | --'--'--' '--'--' --'--'--'--'`-----'

wiki https://alibaba.github.io/arthas tutorials https://alibaba.github.io/arthas/arthas-tutorials version 3.1.1 pid 6 time 2019-08-06 17:31:21

$ exit/usr/local/arthas # netstat -tlnpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:3658 0.0.0.0: LISTEN 6/javatcp 0 0 0.0.0.0:80 0.0.0.0: LISTEN 6/javatcp 0 0 127.0.0.1:8563 0.0.0.0:* LISTEN 6/java

6.示例jenkins构建,封装至基础镜像中

cat >./target/Dockerfile <<EOFFROM 192.168.3.10:5001/library/javabase:v8.0.22RUN \mkdir -p /usr/local/ocrADD ./app.jar /usr/local/ocr/WORKDIR /usr/local EXPOSE 80

ENTRYPOINT ["/sbin/tini", "--"]CMD ["sh","-c","java -Xms3000m -Xmx3000m -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -jar /usr/local/ocr/app.jar"]EOF

ssh root@192.168.255.1 "/bin/bash /usr/jenkins_home/deploy_history/scf-test/deploy.sh test ocr && \/usr/bin/kubectl apply -f /usr/jenkins_home/deploy_history/scf-test/test-ocr.yaml && \exit"

参考链接:https://alibaba.github.io/arthas/docker.htmlhttps://github.com/alibaba/arthas/issues/734https://pkgs.alpinelinux.org/packages?name=openjdk8&branch=edge

相关TAG标签 k8s
上一篇:第十二周作业-12469468-51CTO博客
下一篇:CentOS加入AD域-川流信息-51CTO博客
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站