1、先编写一个基础dockerFile 命名:jmbase
# Use Java 8 slim JRE
FROM openjdk:8-jre-slim
MAINTAINER QJP
# 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 qjpdsg/jmbase
MAINTAINER TestAutomationGuru
# 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镜像
dockerfile文件如下# Use jmbase base image
FROM qjpdsg/jmbase
MAINTAINER QJP
# 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 master jmmaster
需要从主机复制任何文件到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容器将能够运行JMeter测试,因为它拥有运行JMeter测试的所有软件和依赖: -n -t baid.jmx -l result2.jtl 现在我们已经准备好使用docker容器在分布式中运行我们的测试。我们只需要添加-R[slave01,slave02,slave03]标签:JMETER,jmeter,压测,apache,test,docker,Jmeter,JMeter From: https://www.cnblogs.com/josonhuang/p/17075743.html生成报告方便直观看结果 jmeter -n -t baidu.jmx -l result2.jtl -R172.17.0.6,172.17.0.7 docker container cp slave01:/jmeter/apache-jmeter-5.1.1/bin/result.jtl ./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 2017 (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
tips:(以上针对于master和slave是一台机器)如果不同:
1.Master和Slave是同一台机器
remote_hosts=127.0.0.1:1099 server.rmi.ssl.disable=true (关闭RMI)
- 修改jmeter.properties
2.Master和Slave不是同一台
Master:10.86.16.218remote_hosts=10.86.16.81:1099,10.86.17.82:1099 server.rmi.ssl.disable=true (关闭RMI)
- 修改jmeter.properties (用默认端口1099)
java.rmi.server.hostname=10.86.16.218 Slave1:10.86.16.81 Slave2:10.86.17.82
- 在system.proerties的最后加一行
server.rmi.ssl.disable=true
- 修改jmeter.properties
以Slave1举例,其他Slave也要这么配 java.rmi.server.hostname=10.86.16.81
- 在system.properties的最后加一行