站长资源服务器
docker环境下分布式运行jmeter的教程详解
简介1.构建jmeter的基础镜像dockerfile文件如下:# Use Java 8 slim JREFROM openjdk:8-jre-slimMAINTAINER QJP# JMeter versionARG JMETER_VERSION=5.1.1# Install few util
1.构建jmeter的基础镜像
dockerfile文件如下:
# Use Java 8 slim JRE FROM openjdk:8-jre-slim MAINTAINER QJP # JMeter version ARG JMETER_VERSION=5.1.1 # 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 .
打包上传
docker tag jmbase dockername/jmbase docker push dockername/jmbase
2.构建jmeter的master机器镜像
dockerfile文件如下
# 使用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 jmmaster .
打包上传
docker tag jmmaster dockername/jmmaster docker push dockername/jmmaster
3.构建jmeter客户端镜像
dock而file文件如下
# Use jmbase base image FROM qjpdsg/jmbase MAINTAINER QJP # Ports to be exposed from the container for JMeter Master EXPOSE 60000
构建镜像
docker build -t jmslave .
打包上传
docker tag jmmaster dockername/jmslave docker push dockername/jmslave
4.运行jmeter客服端,得到IP地址:
启动客户端容器:
docker run -dit --name slave01 jmserver /bin/bash docker run -dit --name slave02 jmserver /bin/bash docker run -dit --name slave03 jmserver /bin/bash
得到客户端ip
docker inspect --format '{{ .Name }} => {{ .NetworkSettings.IPAddress }}' $( docker ps -a -q)
将ip地址配置到jmeter的master机器的jmeter.properties里面:注意客户端的server_port需要和master的server_port保持一致
如:
设置地址 :
remote_hosts=172.17.0.2:1099,172.17.0.3:1099
拷贝到jmmaster容器里面:
docker cp ./jmeter.properties jmmaster:/jmeter/apache-jmeter-5.1.1/bin/
5.开始分布式测试:
进入到客户端容器里面,运行jmeterserver服务:
docker exec -it slave10 /bin/bash jmeter-server
进入到master容器里面,进行分布式测试:
jmeter -n -t mywh.jmx -R172.17.0.2,172.17.0.3