JMETER:linux进行分布式压力测试

来源:互联网 发布:淘宝大悲咒水晶杯真假 编辑:程序博客网 时间:2024/05/21 22:57

http://blog.csdn.net/wuhenyan/article/details/53117556

1. 下载jmeter tgz文件   http://jmeter.apache.org/download_jmeter.cgi


2. 登录linux服务器,创建jmeter目录,rz上传jmeter


3. tar xvf + jmeter tgz文件名


4. 添加jmeter环境变量    vi /etc/profile

增加:JMETER=/data/soft/jmeter/apache-jmeter-3.0   //自己的安装路径
CLASSPATH=$CLASSPATH:$JMETER/lib/ext/ApacheJMeter_core.jar:$JMETER/lib/jorphan.jar:$JMETER/lib/logkit-2.0.jar
PATH=$PATH:$JMETER/bin

5. source /etc/profile

6. jmeter -v查看是否设置成功

7. 在jmeter目录创建testplan testresult子目录

8. rz上传jmx脚本到testplan下

脚本使用beanshell:(可以将返回输出到jmeter.log)

prev.setDataEncoding("UTF-8");
String response_data = prev.getResponseDataAsString();
log.error("response_data----------------:"+response_data);

9. 若有host进入/etc/hosts 加入自己的host配置(此过程可以写成shell脚本,每次只需执行脚本即可)

hosts文件的作用相当如DNS,提供IP地址到hostname的对应,Linux系统在向DNS服务器发出域名解析请求之前会查询/etc/hosts文件,如果里面有相应的记录,就会使用hosts里面的记录

//查看当前host hostname (实际与执行脚本使用的host无关,该命令返回的host是系统启动时就一直不变的,若要修改,需要修改以后重启服务器才会永久生效)

vim /etc/sysconfig/network  系统网络配置文件   --需要重启生效,永久性修改。hostname是Linux系统下的一个内核参数,它保存在/proc/sys/kernel/hostname下,但是它的值是Linux启动时从rc.sysinit读取的。而/etc/rc.d/rc.sysinit中HOSTNAME的取值来自与/etc/sysconfig/network下的HOSTNAME

/etc/init.d/network restart  修改网络配置文件后重启网络


10. jmeter -n -t testplan/comic.jmx -l testResult/result1.jtl执行脚本并生成聚合报告(在jmeter目录下能够看到jmeter.log或者在testplan目录下,自行寻找,通过日志可以看到出错的地方)

-n表示以nogui方式运行测试计划

-t表示测试计划,后面跟测试计划名称

-l表示测试结果,后面跟测试结果文件名称


11. sz导出聚合报告,在windows下打开可查看结果


分布式配置:

1、同上面步骤,在新的服务器上配置jmeter及环境变量

2、在控制机上修改bin/jmeter.properties,添加从机的IP及端口(使用-r启动所有从机)1099是默认的rmi通信端口

# Remote Hosts - comma delimited

remote_hosts=192.168.5.95:1099,192.168.5.103:1099

3、开启执行脚本机器上的server服务,bin/jmeter-server

4、在控制机执行分布式命令

jmeter -n -t testplan/comic.jmx -R 10.15.243.53,10.15.230.78 -l testResult/result1.jtl    指定从机IP

jmeter -n -t testplan/comic.jmx -r -l testResult/result1.jtl  启动所有从机执行脚本

注:若有host同样也需要修改从机的host文件,否则会出现error


http://jmeter.apache.org/usermanual/get-started.html#non_gui

1.4.4 Non-GUI Mode (Command Line mode)¶

For load testing, you must run JMeter in this mode (Without the GUI) to get the optimal results from it. To do so, use the following command options:

-n
This specifies JMeter is to run in non-gui mode
-t
[name of JMX file that contains the Test Plan].
-l
[name of JTL file to log sample results to].
-j
[name of JMeter run log file].
-r
Run the test in the servers specified by the JMeter property "remote_hosts"
-R
[list of remote servers] Run the test in the specified remote servers
-g
[path to CSV file] generate report dashboard only
-e
generate report dashboard after load test
-o
output folder where to generate the report dashboard after load test. Folder must not exist or be empty

The script also lets you specify the optional firewall/proxy server information:

-H
[proxy server hostname or ip address]
-P
[proxy server port]
Example
jmeter -n -t my_test.jmx -l log.jtl -H my.proxy.server -P 8000

If the property jmeterengine.stopfail.system.exit is set to true (default is false), then JMeter will invoke System.exit(1) if it cannot stop all threads. Normally this is not necessary.



原创粉丝点击