众所周知,Jmeter在GUI模式下的效能比非GUI下的要差一些,在无环境的机器中进行测试应该如何快速启动呢
在Linux中有两种方式快速起动,第一种下载安装包直接启动jmeter.sh 脚本,第二种使用docker启动
我们先看第一种,在Linux中直接下载Jmeter启动包,先进入官网复制jmeter下载地址
在Linux中使用 wget命令下载包
ssh@test:~/Test$ wget https://dlcdn.apache.org//jmeter/binaries/apache-jmeter-5.5.tgz
--2022-09-12 05:53:14-- https://dlcdn.apache.org//jmeter/binaries/apache-jmeter-5.5.tgz
Resolving dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
Connecting to dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 85476161 (82M) [application/x-gzip]
Saving to: ‘apache-jmeter-5.5.tgz’
apache-jmeter-5.5.tgz 100%[================================================================>] 81.52M 5.29MB/s in 16s
2022-09-12 05:53:30 (5.11 MB/s) - ‘apache-jmeter-5.5.tgz’ saved [85476161/85476161]
ssh@test:~/Test$ ls
apache-jmeter-5.5.tgz
解压该文件
ssh@test:~/Test$ tar -xvf apache-jmeter-5.5.tgz
进入解压后的问题件,找到bin目录查看是否有jmetet.sh文件
之后进入jmx脚本存在目录,执行以下命令(该命令是启动jmeter.sh脚本,同时传入 -n -t -l 等参数)
执行日志中error为100% 为了方便测试随便用了一个脚本,由于地址不通所以全部报错
当我们看到... end of run 的时候代表脚本已经执行完毕,我们可以在执行命令时,定义的 -o 目录下查看详细测试报告
ssh@test:~/Test$ ./apache-jmeter-5.5/bin/jmeter.sh -n -t test.jmx -l result/result.jtl -e -o result/html
Creating summariser <summary>
Created the tree successfully using test.jmx
Starting standalone test @ September 12, 2022 6:05:17 AM UTC (1662962717490)
Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
summary = 287617 in 00:00:10 = 28292.1/s Avg: 0 Min: 0 Max: 117 Err: 287617 (100.00%)
Tidying up ... @ September 12, 2022 6:05:28 AM UTC (1662962728206)
... end of run
将我们指定目录下的html下载到本地,解压后目录结构为
这时候我们打开index.html就可以查看详细报告了
接着第二种方式,使用docker执行jmx脚本
首先docker环境是必要的,这里就不再赘述了,使用docker search jmeter 查看仓库中已有的镜像
root@test ~
# docker search jmeter
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
justb4/jmeter Lightweight Docker image for running the Apa… 98 [OK]
cirit/jmeter Jmeter 2.13 + Debian OS + Java Server JRE 8 30 [OK]
egaillardon/jmeter Docker image for Apache JMeter (no more upda… 13 [OK]
egaillardon/jmeter-plugins Docker image for Apache JMeter and JMeter pl… 10 [OK]
pedrocesarti/jmeter-docker Apache Jmeter™ is an open source tool that h… 7 [OK]
vmarrazzo/jmeter Lightweight Docker image for Apache JMeter a… 6
eroadltd/jmeter 4
smithmicro/jmeter JMeter Docker Image for Distributed Testing … 4 [OK]
floodio/jmeter JMeter on Flood IO 4
famiko/jmeter-base Install jmeter on openjdk:8-alpine 2 [OK]
kubernautslabs/jmeter_slave 1
octoperf/jmeter-standard OpenJDK + SSH + JMeter + OctoPerf Plugin 1
grafana/jmeter-to-k6 1
kaarol/jmeter-master Jmeter master image 1 [OK]
kaarol/jmeter-slave jmeter slave base image 0 [OK]
3ram/jmeter Jmeter with Mysql library 0
keptn/jmeter-service 0
gsengun/jmeter JMeter 3.x image with a few Plugins, MSSQL a… 0 [OK]
cloudssky/jmeter-slave 0
decho/jmeter-slave 0
kubernautslabs/jmeter-operator 0
cloudssky/jmeter-master 0
jmeterscripts/jmeter-agent 0
zheji01/jmeter-konakart jmeter 4.0 0
shadowpic/jmeter-slave 0
接着我们使用docker pull 一个符合自己的镜像,下载成功以后使用docker images 查看本地镜像
root@test ~
# docker pull justb4/jmeter
Using default tag: latest
latest: Pulling from justb4/jmeter
1b7ca6aea1dd: Pull complete
0c9f7f0acdce: Pull complete
0a0aa5d7f9c8: Pull complete
4f4fb700ef54: Pull complete
Digest: sha256:ba68e5f66e7dee5d71328cfe71eec3ad508437d759a5a481bea9092ea89592ee
Status: Downloaded newer image for justb4/jmeter:latest
docker.io/justb4/jmeter:latest
root@test ~
# docker images | grep jmeter
justb4/jmeter latest 7fae0b97a533 3 months ago 246MB
然后我们直接docker run 启动,这里简单说一下启动参数
--net=host 这个参数代表不需要给容器内的服务做映射了
-i 标准输入保持打开状态
-v 目录挂载让容器内外该目录下的文件保持一致
-w 让命令在指定路径执行,如果目录不存在则创建一个新的
-n -t -l -o -e 这几个是jmeter的启动参数了,不多赘述了
root@qa-perf-test-068 /home/developer/Test
# docker run --net=host -i -v /home/developer/Test:/home/developer/Test -w /home/developer/Test justb4/jmeter -n -t test.jmx -l result/result.jtl -e -o result/html
START Running Jmeter on Mon Sep 12 08:32:04 CEST 2022
JVM_ARGS=-Xmn1390m -Xms5560m -Xmx5560m
jmeter args=-n -t test.jmx -l result/result.jtl -e -o result/html
jmeter ALL ARGS=-Dlog4j2.formatMsgNoLookups=true -n -t test.jmx -l result/result.jtl -e -o result/html
Sep 12, 2022 8:32:06 AM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.
Creating summariser <summary>
Created the tree successfully using test.jmx
Starting standalone test @ Mon Sep 12 08:32:06 CEST 2022 (1662964326558)
Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
summary = 217948 in 00:00:10 = 21474.8/s Avg: 1 Min: 0 Max: 371 Err: 217948 (100.00%)
Tidying up ... @ Mon Sep 12 08:32:17 CEST 2022 (1662964337098)
... end of run
END Running Jmeter on Mon Sep 12 08:32:30 CEST 2022
执行完毕以后,我们查看挂载目录下的Test文件夹,找到html下载到本地与方法一 一致下载后在本地可直接查看jmeter执行详情