为Docker中的Java应用安装ARMS Agent后,ARMS即可开始监控Java应用,且ARMS将自动适配该应用运行的环境,不需要针对Tomcat、Jetty或Spring Boot等应用单独配置运行环境。本文介绍如何为Docker中的Java应用安装Agent。
前提条件
- 您已在Docker中部署Java应用。
- 检查您的JDK版本。ARMS应用监控支持的JDK版本如下:
- JDK 1.7.0+
- JDK 1.8.0_25+
说明
- Kubernetes集群应用部署建议:JDK 1.8.0_191+。
- 如果JDK版本为1.8.0_25或者1.8.0_31,可能会出现无法安装探针的情况,请升级至1.8.X最新版本。
- JDK 11.0.8+
- JDK 17
说明 JDK 1.8及以下版本、JDK 11和JDK 17版本对应的探针安装包不同,请根据不同的JDK版本下载对应的探针安装包或调整应用监控组件ack-onepilot的配置。
背景信息
步骤一:获取License Key
步骤二:集成已有镜像
参考以下Dockerfile示例修改您的Dockerfile文件。
###################################
## ###
## ARMS APM DEMO Docker ###
## For Java ###
## withAgent V0.1 ###
## ###
###################################
# 将{original-docker-image:tag}替换为您的镜像地址。
FROM {original-docker-image:tag}
WORKDIR /root/
# 根据所在地域替换Agent的下载地址。
RUN wget "http://arms-apm-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
RUN unzip ArmsAgent.zip -d /root/
# 按照步骤一的说明获取License Key。
# {AppName}为自定义ARMS监控应用名称,不可包含中文字符。
# 若所有镜像都接入同一个应用监控任务,配置此处的arms_licenseKey和arms_appName即可。
ENV arms_licenseKey={LicenseKey}
ENV arms_appName={AppName}
ENV JAVA_TOOL_OPTIONS ${JAVA_TOOL_OPTIONS} '-javaagent:/root/ArmsAgent/arms-bootstrap-1.7.0-SNAPSHOT.jar -Darms.licenseKey='${arms_licenseKey}' -Darms.appName='${arms_appName}
### for check the args
RUN env | grep JAVA_TOOL_OPTIONS
### 可在下方添加自定义Dockerfile逻辑。
### ......
请按照以下说明替换上述配置文件中的示例值。
- 将
{original-docker-image:tag}
替换为您的镜像地址。若您没有自定义镜像,可使用系统镜像。 - 根据所在地域替换Agent的下载地址。
说明 请使用公网地址,如无法下载则使用VPC地址。查看各地域对应的Agent(JDK 8及以下版本)安装包下载命令
地域 公网地址 VPC地址 华东1(杭州) wget "http://arms-apm-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-cn-hangzhou.oss-cn-hangzhou-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
华东2(上海) wget "http://arms-apm-cn-shanghai.oss-cn-shanghai.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-cn-shanghai.oss-cn-shanghai-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
华北1(青岛) wget "http://arms-apm-cn-qingdao.oss-cn-qingdao.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-cn-qingdao.oss-cn-qingdao-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
华北2(北京) wget "http://arms-apm-cn-beijing.oss-cn-beijing.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-cn-beijing.oss-cn-beijing-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
华北3(张家口) wget "http://arms-apm-cn-zhangjiakou.oss-cn-zhangjiakou.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-cn-zhangjiakou.oss-cn-zhangjiakou-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
华北5(呼和浩特) wget "http://arms-apm-cn-huhehaote.oss-cn-huhehaote.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-cn-huhehaote.oss-cn-huhehaote-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
华北6(乌兰察布) wget "http://arms-apm-cn-wulanchabu.oss-cn-wulanchabu.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-cn-wulanchabu.oss-cn-wulanchabu-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
华南1(深圳) wget "http://arms-apm-cn-shenzhen.oss-cn-shenzhen.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-cn-shenzhen.oss-cn-shenzhen-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
华南2(河源) wget "http://arms-apm-cn-heyuan.oss-cn-heyuan.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-cn-heyuan.oss-cn-heyuan-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
华南3(广州) wget "http://arms-apm-cn-guangzhou.oss-cn-guangzhou.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-cn-guangzhou.oss-cn-guangzhou-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
西南1(成都) wget "http://arms-apm-cn-chengdu.oss-cn-chengdu.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-cn-chengdu.oss-cn-chengdu-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
中国(香港) wget "http://arms-apm-cn-hongkong.oss-cn-hongkong.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-cn-hongkong.oss-cn-hongkong-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
新加坡 wget "http://arms-apm-ap-southeast-1.oss-ap-southeast-1.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-ap-southeast-1.oss-ap-southeast-1-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
亚太东南2(悉尼) wget "http://arms-apm-ap-southeast-2.oss-ap-southeast-2.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-ap-southeast-2.oss-ap-southeast-2-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
亚太东南3(吉隆坡) wget "http://arms-apm-ap-southeast-3.oss-ap-southeast-3.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-ap-southeast-3.oss-ap-southeast-3-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
亚太东南5(雅加达) wget "http://arms-apm-ap-southeast-5.oss-ap-southeast-5.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-ap-southeast-5.oss-ap-southeast-5-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
亚太东北1(东京) wget "http://arms-apm-ap-northeast-1.oss-ap-northeast-1.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-ap-northeast-1.oss-ap-northeast-1-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
欧洲中部1(法兰克福) wget "http://arms-apm-eu-central-1.oss-eu-central-1.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-eu-central-1.oss-eu-central-1-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
欧洲西部1(伦敦) wget "http://arms-apm-eu-west-1.oss-eu-west-1.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-eu-west-1.oss-eu-west-1-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
美国东部1(弗吉尼亚) wget "http://arms-apm-us-east-1.oss-us-east-1.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-us-east-1.oss-us-east-1-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
美国西部1(硅谷) wget "http://arms-apm-us-west-1.oss-us-west-1.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zipwget "http://arms-apm-us-west-1.oss-us-west-1-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-us-west-1.oss-us-west-1-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
亚太南部1(孟买) wget "http://arms-apm-ap-south-1.oss-ap-south-1.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-ap-south-1.oss-ap-south-1-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
华东1金融云 无 wget "http://arms-apm-cn-hangzhou-finance.oss-cn-hzjbp-b-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
华东2金融云 无 wget "http://arms-apm-cn-shanghai-finance-1.oss-cn-shanghai-finance-1-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
华南1金融云 无 wget "http://arms-apm-cn-shenzhen-finance-1.oss-cn-shenzhen-finance-1-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
政务云 wget "http://arms-apm-cn-north-2-gov-1.oss-cn-north-2-gov-1.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
wget "http://arms-apm-cn-north-2-gov-1.oss-cn-north-2-gov-1-internal.aliyuncs.com/ArmsAgent.zip" -O ArmsAgent.zip
- 将
{LicenseKey}
替换成您的License Key。将{AppName}
替换成您的应用名称(应用名不可包含中文字符)。
步骤三:构建并启动新镜像
结果验证
约一分钟后,若您的应用名称出现在应用列表页面中且有数据上报,则说明接入成功。
卸载Agent
当您不需要再监控Docker集群中的Java应用时,请按照以下步骤卸载Agent。
- 删除按照步骤二:集成已有镜像的说明添加的Dockerfile内容。
- 运行
docker build
命令来构建镜像。 - 运行
docker run
命令来启动镜像。