tsung压力测试环境部署详细步骤(内附安装包)

操作系统:

Redhat 6.3、Redhat6.5 、centos7.4(这些版本已验证过)

tsung版本:

tsung-1.6.0

下载地址:

链接: https://pan.baidu.com/s/1LqPsiTKEL3PLvqbDDW2vdA

提取码: y3yr

安装环境要求

已安装GCC、Perl,如未安装请查阅网上资料进行安装

GCC检测命令gcc –v,如无查询结果,正常未安装

Perl检测命令perl -MShell -e "print"module installed "",如打印出来module installed说明已安装

所需安装包

gnuplot-4.2.6-2.el6.x86_64.rpm

gnuplot-common-4.2.6-2.el6.x86_64.rpm

otp_src_17.5.tar.gz

Template-Toolkit-2.26.tar.gz

tsung-1.5.1.tar.gz

注:随着时间的推移,可能你下载的版本会比文档中描述的新

安装过程

新建/home/tsung目录,将所需安装包上传至

erlang安装

#cd /home/tsung

#tar –xzvf otp_src_17.5.tar.gz

#cd /home/tsung/otp_src_17.5

#./configure --prefix=/usr/local/erlang

#make

#make install

tsung安装

#cd /home/tsung

#tar –xzvf tsung-1.5.1.tar.gz

#cd /home/tsung/tsung-1.5.1

# ./configure --prefix=/usr/local/tsung --with-erlang=/usr/local/erlang

#make

#make install

安装perl的Template

#cd /home/tsung

#tar –zxvf Template-Toolkit-2.26.tar.gz

#cd /home/tsung/Template-Toolkit-2.26

#perl Makefile.PL

#make

#make test

#make install

安装gnuplot

首先检查系统中是否安装了此两个工具包

 # rpm -qa gnuplot* 

如未查询到结果,则表示未安装。

安装gnuplot

# rpm–ivh gnuplot-4.2.6-2.el6.x86_64.rpm gnuplot-common-4.2.6-2.el6.x86_64.rpm

使用介绍

/usr/local/tsung/share/doc/tsung/examples/下存放着一些常用脚本模板。

以http_simple.xml为例说明tsung使用方法。

首先,拷贝一份http_simpl.xml的副本,并进行编辑

#cd /usr/local/tsung

#cp /usr/local/tsung/share/doc/tsung/examples/http_simple.xml ./

#vim http_simple.xml

配置文件说明

运行测试脚本

#cd /usr/local/tsung

#./bin/tsung –f  http_simple.xml start

生成结果报告

运行完成后,在/root/.tsung/log下会生成本次运行的日志文件。

生成统计图表

#cd /root/.tsung/log/20150510-1743

# /usr/local/tsung/lib/tsung/bin/tsung_stats.pl

生成的统计图表名为report.html,使用浏览器可以打开进行查看。


问题总结:

(1)如果出现  configure: error: No curses library functions found 提示 ,需要首先安装 ncurses-devel

 error: Failed dependencies:

(2)如果安装erlang时,需要其他依赖时,可以强制忽略依赖进行安装,--force --nodeps 

(3)如果生成报告时,报错:Error while running gnuplot: Inappropriate ioctl for device at /usr/local/lib/tsung/bin/tsung_stats.pl line 167.

需要安装组件:

        yum install libtemplate-perl gnuplot

(4)如果遇到host key verification failed,client需要机器实例名登录,换乘机器实例名即可;

附样例脚本:

<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/opt/tsung/share/tsung/tsung-1.0.dtd">
<tsung loglevel="debug" version="1.0">

  <!-- Client side setup -->
  <clients>
    <client host="localhost" maxusers="3000" use_controller_vm="true"/>
  </clients>
  
  <!-- Server side setup -->
<servers>
  <server host="xxx.xx.10.xxx" port="8181" type="tcp"></server>
</servers>

  <!-- to start os monitoring (cpu, network, memory). Use an erlang
  agent on the remote machine or SNMP. erlang is the default --> 
  <monitoring>
    <monitor host="xxx.xx.xx.xxx" type="snmp"></monitor>
  </monitoring>
  
  <load>
  <!-- several arrival phases can be set: for each phase, you can set
  the mean inter-arrival time between new clients and the phase
  duration -->
   <arrivalphase phase="1" duration="2" unit="minute">
     <users  maxnumber="500" arrivalrate="10" unit="second"></users>
   </arrivalphase>
  </load>

  <options>
   <option type="ts_http" name="user_agent">
    <user_agent probability="80">Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050513 Galeon/1.3.21</user_agent>
    <user_agent probability="20">Mozilla/5.0 (Windows; U; Windows NT 5.2; fr-FR; rv:1.7.8) Gecko/20050511 Firefox/1.0.4</user_agent>
   </option>
  </options>

  <!-- start a session for a http user. the probability is the
  frequency of this type os session. The sum of all session's
  probabilities must be 100 -->

 <sessions>

  <session name="Gethotairline" probability="100" type="ts_http">
   <for from="1" to="1000000" var="i">
    <transaction name="GetBanner">
       <request>
          <http url="/service/flt/getHotAirline?language=CN&amp;source=SITE" method="GET" > 
           <http_header name="Content-Type" value="application/json;charset=UTF-8"/>  
          </http>
       </request> 
    </transaction>
   </for>
  </session>

 </sessions>
</tsung>