1、先编写一个基础dockerFile 命名:jmbase
-
# Use Java 8 slim JRE
-
FROM openjdk:8-jre-slim
-
# JMeter version
-
ARG JMETER_VERSION=5.3
-
# Install few utilities
-
RUN apt-get clean && \
-
apt-get update && \
-
apt-get -qy install \
-
wget \
-
telnet \
-
iputils-ping \
-
unzip
-
# Install JMeter
-
RUN mkdir /jmeter \
-
&& cd /jmeter/ \
-
&& wget https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-$JMETER_VERSION.tgz \
-
&& tar -xzf apache-jmeter-$JMETER_VERSION.tgz \
-
&& rm apache-jmeter-$JMETER_VERSION.tgz
-
-
WORKDIR /jmeter/apache-jmeter-$JMETER_VERSION/bin
-
#从当前文件夹拷贝一份jmeter.properties文件,注意开启:server.rmi.ssl.disable=true
-
COPY jmeter.properties .
-
# ADD all the plugins
-
ADD jmeter-plugins/lib /jmeter/apache-jmeter-$JMETER_VERSION/lib
-
# ADD the sample test
-
ADD sample-test sample-test
-
# Set JMeter Home
-
ENV JMETER_HOME /jmeter/apache-jmeter-$JMETER_VERSION/
-
# Add JMeter to the Path
-
ENV PATH $JMETER_HOME/bin:$PATH
构建基础镜像:
docker build -t jmbase -f ./jmbase .
2.构建jmeter的slave机器镜像
dockerfile文件如下 jmslave
-
# 使用jmbase基本映像
-
FROM jmbase
-
# Ports to be exposed from the container for JMeter Slaves/Server
-
# 从JMeter Slaves/Server的容器中要公开的端口
-
EXPOSE 1099 50000
-
# Application to run on starting the container
-
# 启动容器 运行应用程序
-
ENTRYPOINT $JMETER_HOME/bin/jmeter-server \
-
-Dserver.rmi.localport=50000 \
-
-Dserver_port=1099
构建镜像
docker build -t jmslave -f ./jmslave .
3.暴露端口jmeter中master:60000
dockerfile文件如下:
-
# Use jmbase base image
-
FROM jmbase
-
# Ports to be exposed from the container for JMeter Master
-
EXPOSE 60000
构建镜像
docker build -t jmmaster -f ./jmmaster .
4.运行jmeter客户端,得到IP地址:
-
docker run -dit --name slave01 jmslave
-
docker run -dit --name slave02 jmslave
-
docker run -dit --name slave03 jmslave
-
docker run -dit --name master jmmaster
-
docker ps
-
#查看启动的容器
docker inspect --format '{{ .Name }} => {{ .NetworkSettings.IPAddress }}' $(sudo docker ps -a -q)
需要从主机复制任何文件到docker容器 - 你可以发出以下命令。例如:我把测试复制到我的JMeter主容器中。这个命令将把我的本地jmeter测试(docker-test.jmx)复制到主容器的这个路径中:
-
/jmeter/apache-jmeter-3.3/bin/docker-test.jmx
-
sudo docker exec -i master sh -c 'cat > /jmeter/apache-jmeter-3.3/bin/docker-test.jmx' < docker-test.jmx
#注意 /jmeter/apache-jmeter-3.3/bin/docker-test.jmx 为docker内部的命令
用下面的命令进入容器内部,我们可以看到文件是否被成功复制了:
docker exec -it master /bin/bash
让我们在主服务器上运行测试,看看它是否工作正常[不是在分布式模式下]。Docker容器将能够运行JMeter测试,因为它拥有运行JMeter测试的所有软件和依赖:
-n -t baid.jmx -l result2.jtl
现在我们已经准备好使用docker容器在分布式中运行我们的测试。我们只需要添加-R[slave01,slave02,slave03]
-
jmeter -n -t sample-test/sample-test.jmx -R172.17.0.5,172.17.0.6,172.17.0.7
-
Creating summariser <summary>
-
Created the tree successfully using sample-test/sample-test.jmx
-
Configuring remote engine: 172.17.0.5
-
Configuring remote engine: 172.17.0.6
-
Configuring remote engine: 172.17.0.7
-
Starting remote engines
-
Starting the test @ Thu Dec 21 17:01:48 UTC 2022 (1513875708955)
-
Remote engines have been started
-
Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445
-
summary + 4 in 00:00:11 = 0.4/s Avg: 182 Min: 98 Max: 232 Err: 0 (0.00%) Active: 15 Started: 15 Finished: 0
-
summary + 1021 in 00:00:20 = 51.5/s Avg: 111 Min: 85 Max: 283 Err: 0 (0.00%) Active: 0 Started: 15 Finished: 15
-
summary = 1025 in 00:00:30 = 33.7/s Avg: 111 Min: 85 Max: 283 Err: 0 (0.00%)
-
Tidying up remote @ Thu Dec 21 17:02:20 UTC 2017 (1513875740196)
-
... end of run
感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:
这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!有需要的小伙伴可以点击下方小卡片领取