You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在K8集群的服务器/Pod中安装JMeter Server Agent

在K8s集群的Pod或宿主机安装PerfMon Server Agent的步骤

一、宿主机安装方式

  • 登录目标宿主机:可通过kubectl node-shell <node-name>(需提前安装node-shell插件)或直接SSH登录节点
  • 下载并解压Server Agent:
    # 替换为对应版本的压缩包下载路径
    wget <Server-Agent-Zip-URL>
    unzip ServerAgent-*.zip
    
  • 启动Agent:进入解压后的目录,执行启动命令(可指定UDP/TCP端口,默认4444)
    cd ServerAgent-*
    ./startAgent.sh --udp-port 4444 --tcp-port 4444
    
  • 验证端口:确保宿主机的4444端口已开放,可通过nc -zv <宿主机IP> 4444测试连通性

二、Pod内安装方式

1. 临时安装(仅用于调试,Pod重启后失效)

  • 进入目标Pod:
    kubectl exec -it <pod-name> -- /bin/bash
    
  • 安装依赖工具(根据Pod基础镜像选择命令):
    # Debian/Ubuntu系
    apt update && apt install -y unzip wget
    # CentOS/RHEL系
    yum install -y unzip wget
    
  • 下载解压并后台启动Agent:
    wget <Server-Agent-Zip-URL>
    unzip ServerAgent-*.zip
    cd ServerAgent-*
    nohup ./startAgent.sh --udp-port 4444 --tcp-port 4444 > agent.log 2>&1 &
    
  • 验证:在Pod内执行netstat -tulnp | grep 4444(若缺少netstat,先安装net-tools)

2. 持久化安装(推荐,Pod重启后保留配置)

通过自定义镜像内置Agent,避免重启丢失:

  • 编写Dockerfile(基于原有业务镜像):
    FROM your-business-image:tag
    
    # 安装依赖
    RUN apt update && apt install -y unzip wget supervisor && rm -rf /var/lib/apt/lists/*
    
    # 下载并解压Server Agent
    RUN wget <Server-Agent-Zip-URL> && \
        unzip ServerAgent-*.zip && \
        rm ServerAgent-*.zip
    
    # 配置supervisor管理多进程(同时运行业务和Agent)
    RUN echo "[supervisord]" > /etc/supervisor/conf.d/supervisord.conf && \
        echo "nodaemon=true" >> /etc/supervisor/conf.d/supervisord.conf && \
        echo "[program:perfmon-agent]" >> /etc/supervisor/conf.d/supervisord.conf && \
        echo "command=/ServerAgent-*/startAgent.sh --udp-port 4444 --tcp-port 4444" >> /etc/supervisor/conf.d/supervisord.conf && \
        echo "[program:business-app]" >> /etc/supervisor/conf.d/supervisord.conf && \
        echo "command=/path/to/your/business/start-script.sh" >> /etc/supervisor/conf.d/supervisord.conf
    
    CMD ["/usr/bin/supervisord"]
    
  • 构建并推送自定义镜像:
    docker build -t your-custom-image:tag .
    docker push your-custom-image:tag
    
  • 修改Deployment YAML,替换为自定义镜像并暴露端口:
    spec:
      containers:
      - name: app-container
        image: your-custom-image:tag
        ports:
        - containerPort: 4444
          name: perfmon-port
    
  • 应用配置:
    kubectl apply -f your-deployment.yaml
    

注意事项

  • 端口连通性:确保JMeter所在机器能访问宿主机/Pod的4444端口,K8s环境可通过Service、NodePort或Ingress暴露端口
  • 权限:Agent需足够权限采集系统指标,Pod内可通过securityContext配置root权限或添加CAP_SYS_ADMIN等能力
  • 版本兼容:Server Agent版本需与JMeter PerfMon插件版本匹配

内容的提问来源于stack exchange,提问作者user3537441

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 16:32:52