1

我有以下 docker-compose 文件

version: '3.7'
services:
  tomcat:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: tomcat
    ports:
      - "8080:8080"
      - "9910:9910"
    healthcheck:
      test: ["CMD", "/healthcheck.sh"]
      interval: 1m
      timeout: 10s
      retries: 3
      start_period: 1m
    environment:
      JAVA_OPTS: "-Xms1g -Xmx1g -Dcom.sun.management.jmxremote
                   -Dcom.sun.management.jmxremote.port=9910
                   -Dcom.sun.management.jmxremote.rmi.port=9910
                   -Dcom.sun.management.jmxremote.ssl=false
                   -Dcom.sun.management.jmxremote.authenticate=false
                   -Djava.rmi.server.hostname=localhost"
  jmxtrans:
    build:
      context: .
      dockerfile: Dockerfile.jmxtrans
    container_name: jmxtrans
    environment:
      JMX_HOST: localhost
      JMX_PORT: 9910
      STATSD_HOST: dashboard
      STATSD_PORT: 8125
    links:
      - tomcat
      - dashboard

  dashboard:
    image: kamon/grafana_graphite
    container_name: dashboard
    ports:
      - "80:80"
      - "81:81"
      - "8125:8125/udp"
      - "8126:8126"

  master:
    build:
      context: .
      dockerfile: JMeter/apache-jmeter-master/Dockerfile
    container_name: master
    tty: true
    ports:
      - "60000"

  slave:
    build:
      context: .
      dockerfile: JMeter/apache-jmeter-slave/Dockerfile
    tty: true
    ports:
      - "50000"
      - "1099"

我的从属 Jmeter docker 文件如下所示:

FROM basejmeter:latest

# Ports to be exposed from the container for JMeter Slaves/Server
EXPOSE 1099 50000

# Application to run on starting the container
# to avoid key store error rmi_keystore.jks not found added Jserver.rmi.ssl.disable=true

ENTRYPOINT $JMETER_HOME/bin/jmeter-server \
                        -Dserver.rmi.localport=50000 \
                        -Dserver_port=1099 \
                        -Jserver.rmi.ssl.disable=true

我的主人看起来像这样

FROM basejmeter:latest

# Ports to be exposed from the container for JMeter Master
EXPOSE 60000

现在我编写了这个小 shell 脚本,用于使用非 GUI 命令行测试 Jmeter。但出于某种原因,我的 jmeter 输出 xml 显示

rm="非 HTTP 响应消息:连接到 localhost:8080 [localhost/127.0.0.1] 失败:连接被拒绝(连接被拒绝)"

任何人都知道什么是什么以及为什么我会收到此错误?但是 grafana、jmxtrans 和 tomcat 工作得很好。

Shellscript 看起来像这样,这是修改后的脚本来解决这里的问题:

docker build -t basejmeter -f JMeter/Dockerfile .
docker-compose build --no-cache && docker-compose up -d --scale slave=5

get_slave_IP=$(docker inspect -f '{{.Name}} {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq) | grep slave | awk -F' ' '{print $2}' | tr '\n' ',' | sed 's/.$//')
get_master_IP=$(docker inspect -f '{{.Name}} {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq) | grep master | awk -F' ' '{print $2}' | tr '\n' ',' | sed 's/.$//')
get_master_port_details=$(docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $(docker ps  -f "name=master" -aq))
get_master_port=$(echo "${get_master_port_details%/*}" | tr -d [:blank:])

working_dir=$(docker exec -it -w /jmeter/apache-jmeter-5.1.1/ master pwd | tr -d '\r')

for file_name_with_path in ./JMeter/JMXTest/*.jmx
do
    echo $file_name_with_path
    file_name=$(basename $file_name_with_path)
    file_name="${file_name##*/}"
    name="${file_name%.*}"
    echo $file_name
    echo $name
    eval "docker cp ${file_name_with_path} master:${working_dir}/"
    eval "docker exec -it master /bin/bash -c 'mkdir -p $working_dir/$name &&
                                                                             cd $working_dir/$name &&
                                                                             $working_dir/bin/jmeter -n -t \
                                                                             $working_dir/$file_name -R$get_slave_IP \
                                                                             -j ./$name.log \
                                                                             -l ./$name.xml \
                                                                             -Jjmeter.save.saveservice.output_format=xml \
                                                                             -Jjmeter.save.saveservice.response_data=true \
                                                                             -Jjmeter.save.saveservice.samplerData=true \
                                                                             -Jserver.rmi.ssl.disable=true \
                                                                             -JnumberOfThreads=1 \
                                                                             -Djava.rmi.server.hostname=${get_master_IP} \
                                                                             -Dclient.rmi.localport=60000' "

    eval "docker cp master:$working_dir/$name ./JMeter/Results/"
done

脚本和 evrything 有效,唯一的问题是 JMeter 把我扔到公共汽车下说无法通过 localhost 连接。我尝试了普通的docker,将slave扩展到5,然后尝试使用主容器连接它们。它工作正常,但由于某种原因,docker-compose 向我展示了其他方式。任何帮助!

4

0 回答 0