linux使用jmeter进行压测

1.准备好服务器,这里默认服务器用的系统镜像为contos7.9.2009   
2.准备好jmeter的测试计划文件   .jmx    这里默认测试计划的jmx文件在 /nas目录下

3.安装JDK与jmeter进行测试

#创建JDK与jmeter目录,并复制安装文件
mkdir /jmeter
mkdir /jmeter/java
mkdir /jmeter/jmeter

cp /nas/jdk-8u201-linux-x64.tar.gz /jmeter/java
cp /nas/apache-jmeter-5.6.2.zip /jmeter/jmeter

#安装JDK
cd /jmeter/java
tar -xf jdk-8u201-linux-x64.tar.gz
ln -s jdk1.8.0_201/ jdk
cp /etc/profile /etc/profile_bak_$(date "+%Y%m%d-%H%M%S")
echo -e 'export JAVA_HOME=/jmeter/java/jdk\nexport JRE_HOME=${JAVA_HOME}/jre\nexport CLASSPATH=".:$JAVA_HOME/lib:$CLASSPATH"\nexport PATH="$JAVA_HOME/bin:$PATH"\n' >>  /etc/profile
source /etc/profile
java -version
#此处输出java版本号即为安装成功


#安装jmeter
yum install -y unzip
cd /jmeter/jmeter
unzip apache-jmeter-5.6.2.zip
echo -e 'export JMETER_HOME=/jmeter/jmeter/apache-jmeter-5.6.2\nexport CLASSPATH=$JMETER_HOME/lib/ext/ApacheJMeter_core.jar:$JMETER_HOME/lib/jorphan.jar:$JMETER_HOME/lib/logkit-2.0.jar:$CLASSPATH\nexport PATH=$JMETER_HOME/bin:$PATH:$HOME/bin' >> /etc/profile
source /etc/profile
jmeter -v
#此处输出jmeter版本号即为安装成功


#添加jmeter参数
#添加响应/请求内容(可选),观测响应/请求数据,注意:需要拿到响应请求内容的话,输出格式(jmeter.save.saveservice.output_format)必须是xml,CSV的格式没有
#echo -e '\njmeter.save.saveservice.output_format=xml\njmeter.save.saveservice.data_type=true\njmeter.save.saveservice.label=true\njmeter.save.saveservice.response_code=true\njmeter.save.saveservice.response_data=true\njmeter.save.saveservice.response_message=true\njmeter.save.saveservice.successful=true\njmeter.save.saveservice.connect_time=true\njmeter.save.saveservice.samplerData=true\njmeter.save.saveservice.responseHeaders=true\njmeter.save.saveservice.requestHeaders=true\njmeter.save.saveservice.url=true\njmeter.save.saveservice.thread_counts=true\njmeter.save.saveservice.idle_time=true\n' >> /jmeter/jmeter/apache-jmeter-5.6.2/bin/user.properties

#执行测试计划
cd /nas
rm -rf jmeter*
#开始进行压测并生成压测结果与压测报告 
#jtl格式的结果可以导入到windows的jmeter客户端查看,./jmeterReportResult 文件夹对应的是HTML版本的压测报告
jmeter -n -t 测试计划.jmx -l jmeterResult.jtl -e -o ./jmeterReportResult

你可能感兴趣的:(jmeter)