1. Tsung安装部署
初始化yum源,将shopex-lnmp源加入到系统中
yum install wget -y
cd /etc/yum.repos.d/
wget http://mirrors.shopex.cn/shopex/shopex-lnmp/shopex-lnmp.repo
首先安装tsung,安装的机器IP为192.168.10.228
yum install tsung
yum install erlang
1.1. 录制脚本
Tsung通过在本机开启代理服务8090端口,来进行数据的录制
tsung-recorder start
如果你8090端口被占用了,你可以指定其它的端口,命令如下
tsung-recorder -L 8888 start
执行成功后会显示
➜ tsung-recorder start
Starting Tsung recorder on port 8090
~/.tsung
➜ "Record file: /root/.tsung/tsung_recorder20170123-1536.xml"
~/.tsung
当前Tsung服务器已经启动了代理服务器,那么则需要对访问WEB服务器的浏览器进行http代理设置
代理的地址为:Tsung服务器[192.168.10.228]
代理端口为:默认为[8090]或者为指定的端口
设置好代理后,访问web服务器,访问的页面会通过代理服务器记录到tsung_recorder20170123-1536.xml
文件中。需要录制的页面结束后关闭Tsung代理服务。
~/.tsung
➜ tsung-recorder stop
[OK]
1.2. 配置脚本
<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/local/Cellar/tsung/1.5.1/share/tsung/tsung-1.0.dtd">
<!-- loglevel:工具写日志的标识,级别默认是"info",长时间运行建议调整为error -->
<!-- dumptraffic:运行的调试信息dump文件,如需要看脚本是否正确可以设置为"true",级别默认是"false",长时间运行建议调整为false -->
<tsung loglevel="info" version="1.0">
<!-- Client side setup -->
<!-- 集群Client设置 -->
<!-- host必须是主机名,不能是IP地址 -->
<!-- weight: 节点上面用户的比例,一般设置为1即可 -->
<!-- maxusers: 一般设置为800,3000即可,根据机器配置来设置大小 超过这个数目 会自动开启更多的节点-->
<!-- cpu: 根据机器硬件配置来设置,如果是4核CPU,最佳设置为3,以此类推 -->
<clients>
<client host="tsung" use_controller_vm="true" maxusers="1000000" />
</clients>
<!-- Server side setup -->
<!-- host: 填别名,需要先去host文件配置 -->
<!-- port: 填可用对外端口,一般80 -->
<!-- type: 协议类型,tsung支持tcp/udp,根据自己的需要 -->
<!-- weight 设置权重,整数型 -->
<servers>
<server host="web1" port="80" type="tcp" weight="1"></server>
<server host="web2" port="80" type="tcp" weight="1"></server>
<server host="web3" port="80" type="tcp" weight="1"></server>
</servers>
<!-- 监控(cpu, network, memory). 使用erlang或SNMP,erlang是默认值 但是要保证监控的机器和server可以互相访问,装有erlang,否则用snmp -->
<monitoring>
<monitor host="web1" type="erlang"></monitor>
<monitor host="web2" type="erlang"></monitor>
<monitor host="web3" type="erlang"></monitor>
<monitor host="memcached" type="erlang"></monitor>
<monitor host="mysql1" type="erlang">
</monitor>
<monitor host="mysqlSlave" type="erlang">
</monitor>
<monitor host="redis" type="erlang"></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 -->
<!-- phase:阶段,填数字即可,系统会按顺序执行,可以设置多个阶段组合场景 -->
<!-- duration:持续时段,填数字即可,单位是unit="minute"设置,是分钟 也可设置小时,天,详细情况参考API -->
<!-- arrivalrate:虚拟用户数,填写数字即可,一般最大800,如过机器配置好,可自己调试最佳参数
有效单位unit="second" 是秒,每秒虚拟300个虚拟用户,实际执行情况可能超过,也可能达不到,需要根据调试得到最佳参数 -->
<!-- interarrival: 时间间隔默认是2秒产生一个用户 这个选项可以和arrivalrate互相调换 -->
<!-- maxnumber: 这个是设置最大用户数,所产生的总用户数不会超过这个 -->
<arrivalphase phase="1" duration="300" unit="second">
<users arrivalrate="650" 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='index' probability='50' type='ts_http'>
<transaction name="index">
<request><http url='/index.php' version='1.1' method='GET'></http></request>
</transaction>
</session>
<!-- 专题页 -->
<session name='topics' probability='10' type='ts_http'>
<transaction name="topics">
<request><http url='/index.php/topics.html?cat_id=1' version='1.1' method='GET'></http></request>
</transaction>
</session>
<!-- 详情页 -->
<session name='item' probability='20' type='ts_http'>
<transaction name="item">
<request><http url='/index.php/item.html?item_id=39' version='1.1' method='GET'></http></request>
</transaction>
</session>
<!-- 店铺首页 -->
<session name='shopeindex' probability='9' type='ts_http'>
<transaction name="shopeindex">
<request><http url='/index.php/shopcenter?shop_id=3' version='1.1' method='GET'></http></request>
</transaction>
</session>
<!-- 搜索列表页 -->
<session name='search' probability='10' type='ts_http'>
<transaction name="search">
<request><http url='/index.php/list.html?cat_id=33' version='1.1' method='GET'></http></request>
</transaction>
</session>
<!--创建订单-->
<session name='order' probability='1' type='ts_http'>
<transaction name="order">
<request>
<http url='/index.php/trade-create.html' version='1.1' contents='addr_id=4&payment_type=online&shipping[3][shipping_type]=express&use_points=0&mode=&md5_cart_info=ecb97fc0c7897d25f8a7abec47d5e245&invoice%5Bneed_invoice%5D=0&invoice%5Binvoice_type%5D=normal&invoice%5Binvoice_content%5D=&invoice%5Binvoice_vat%5D%5Bcompany_name%5D=&invoice%5Binvoice_vat%5D%5Bregistration_number%5D=&invoice%5Binvoice_vat%5D%5Bcompany_address%5D=&invoice%5Binvoice_vat%5D%5Bcompany_phone%5D=&invoice%5Binvoice_vat%5D%5Bbankname%5D=&invoice%5Binvoice_vat%5D%5Bbankaccount%5D=&invoice[invoice_title]=individual' content_type='application/x-www-form-urlencoded; charset=UTF-8' method='POST'>
<!--设置cookie 用于登录使用的sessioin_id-->
<http_header name="Cookie" value="S%5BSIGN%5D%5BREMEMBER%5D=0; collect=a%3A2%3A%7Bs%3A4%3A%22item%22%3Ba%3A14%3A%7Bi%3A0%3Bi%3A98%3Bi%3A1%3Bi%3A81%3Bi%3A2%3Bi%3A80%3Bi%3A3%3Bi%3A51%3Bi%3A4%3Bi%3A126%3Bi%3A5%3Bi%3A125%3Bi%3A6%3Bi%3A97%3Bi%3A7%3Bi%3A95%3Bi%3A8%3Bi%3A94%3Bi%3A9%3Bi%3A90%3Bi%3A10%3Bi%3A128%3Bi%3A11%3Bi%3A131%3Bi%3A12%3Bi%3A123%3Bi%3A13%3Bi%3A79%3B%7Ds%3A4%3A%22shop%22%3Ba%3A4%3A%7Bi%3A0%3Bi%3A4%3Bi%3A1%3Bi%3A3%3Bi%3A2%3Bi%3A2%3Bi%3A3%3Bi%3A1%3B%7D%7D; s=72abaa2094abee1f723e74b74554c2a86fe2de1f; UNAME=demo; CARTNUMBER=1; CARTVARIETY=1" />
</http>
</request>
</transaction>
</session>
</sessions>
</tsung>
host名称不能全为数字
监控(cpu, network, memory). 使用erlang
监控
- 需要在Tsung服务器和被监控的服务中都需要安装
erlang
,并且保证安装的erlang
版本一致。 保证Tsung服务器和被监控服务器之间SSH免登
#Tsung服务器生成和被监控服务器生成公钥和密钥,在各服务器执行命令 ssh-keygen #如果需要Tsung对192.168.10.229服务器实现免登,那么可以执行命令 ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.10.229