1.構(gòu)建jmeter的基礎(chǔ)鏡像
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
#從當(dāng)前文件夾拷貝一份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
構(gòu)建鏡像
打包上傳
docker tag jmbase dockername/jmbase
docker push dockername/jmbase
2.構(gòu)建jmeter的master機(jī)器鏡像
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
# 啟動(dòng)容器 運(yùn)行應(yīng)用程序
ENTRYPOINT $JMETER_HOME/bin/jmeter-server \
-Dserver.rmi.localport=50000 \
-Dserver_port=1099
構(gòu)建鏡像
docker build -t jmmaster .
打包上傳
docker tag jmmaster dockername/jmmaster
docker push dockername/jmmaster
3.構(gòu)建jmeter客戶端鏡像
dock而file文件如下
# Use jmbase base image
FROM qjpdsg/jmbase
MAINTAINER QJP
# Ports to be exposed from the container for JMeter Master
EXPOSE 60000
構(gòu)建鏡像
docker build -t jmslave .
打包上傳
docker tag jmmaster dockername/jmslave
docker push dockername/jmslave
4.運(yùn)行jmeter客服端,得到IP地址:
啟動(dòng)客戶端容器:
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地址配置到j(luò)meter的master機(jī)器的jmeter.properties里面:注意客戶端的server_port需要和master的server_port保持一致
如:
設(shè)置地址 :
remote_hosts=172.17.0.2:1099,172.17.0.3:1099
拷貝到j(luò)mmaster容器里面:
docker cp ./jmeter.properties jmmaster:/jmeter/apache-jmeter-5.1.1/bin/
5.開始分布式測試:
進(jìn)入到客戶端容器里面,運(yùn)行jmeterserver服務(wù):
docker exec -it slave10 /bin/bash
jmeter-server
進(jìn)入到master容器里面,進(jìn)行分布式測試:
jmeter -n -t mywh.jmx -R172.17.0.2,172.17.0.3
到此這篇關(guān)于docker環(huán)境下分布式運(yùn)行jmeter的文章就介紹到這了,更多相關(guān)docker下分布式運(yùn)行jmeter內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!