分布式压测web平台(利用javaweb+jenkins+jmeter实现分布式压测的自动化...

分布式压测web平台(利用javaweb+jenkins+jmeter实现分布式压测的自动化...

2023年7月13日发(作者:)

分布式压测web平台(利⽤javaweb+jenkins+jmeter实现分布式压测的⾃动化)web平台测试报告:分布式压测:因为⼀台机器的性能和带宽有限,不可能满⾜⼤并发量的压测需求,所以需要多台机器同时对服务器压测,如下图前提条件:2台以上linux(linux是最⽅便的,windows和mac也可以)平台包含功能:上传jmx脚本到服务器、查看已上传脚本、选择参与压测的机器、填写测试脚本的名称、触发jenkins执⾏测试、实时展⽰测试结果和测试⽇志、记录测试时间、中⽌测试功能、查看报告jenkins包含功能(两个job):job1:带参数构建(接收压测机器和压测脚本两个参数)、远程启动压测机器、执⾏具体测试命令(shell脚本)job2:远程关闭压测机器(可以在job1构建后⾃动执⾏)详细介绍:⼀、在控制机和执⾏机上配置jmeter分布压测环境1、下载包,分别放到控制机和执⾏机,解压2、配置执⾏机(Agent),修改/apache-jmeter/bin/ties,将remote_hosts参数设置为本机ip并设置端⼝号remote_hosts=10.10.10.11:1099将e参数设置为true,并且取消注释e=true3、配置控制机(Controller)Controller机上需要安装JDK、Jmeter打开bin/ties,将remote_hosts参数需要把所有的代理机的IP地址和端⼝号都加⼊进来(包括控制机),⽤逗号隔开remote_hosts=10.10.20.140:1099,10.10.10.11:1099,10.10.10.14:1099将e参数设置为true,并且取消注释e=true4、给jmeter-server、jmeter赋予可执⾏权限chmod 777 /apache-jmeter/bin/jmeter-serverchmod 777 /apache-jmeter/bin/jmeter

5、给linux下载daemonize插件,⽤于后台运⾏jmeter-server服务sudo yum install daemonize如果遇到下载失败,尝试1//⾃带源rpm软件太少,安装第三⽅软件需要epel-release⽀持,安装epel-releasesudo yum -y install epel-release更新yum源命令:yum -y update寻找包命令:yum search daemonize安装:yum install daemonize.x86_64

⼆、将linux服务器添加到jenkins和job1、添加到jenkins,jenkins-Manage Jenkins-Configure System-SSH Servers,添加完成后,点击Test Configuration测试⼀下是否连通 2、添加到job,并设置远程执⾏的命令Confugure-Build-Send files or execute commands over SHH

命令:daemonize -E BUILD_ID=dontKillMe -o -c /data/test/apache-jmeter/performanceTest /data/test/apache-jmeter/performanceTest/start_jmeter_t_jmeter_脚本内容#!/bin/bashpath="/data/test/apache-jmeter"chmod 777 $path/bin/jmeter-serverchmod 777 $path/bin/jmeterchmod 777 $path/bin/ $path/bin./jmeter-server -me=`ifconfig | grep "inet 10.10" | awk '{print $2}'`3、给job添加构建参数Confugure-General-This project is parameterized 添加⾃定义变量

4、配置本地执⾏的命令sh ${path_performanceTest}/ ${jmxName} ${server}脚本内容#!/bin/bashpath_re="/data/test/tomcat/apache-tomcat-9.0.20/webapps/ROOT/re/performanceTest"path_jmeter="/data/test/apache-jmeter"rm -rf $path_re/resultrm -rf $path_re/ -rf $path_re/ $path_jmeter/bin./jmeter -n -t $path_jmeter/performanceTest/$1 -R $2 -l $path_re/ -j $path_re/ -e -o $path_re/result# ./jmeter -n -t $path_jmeter/performanceTest/${jmxName} -R ${server} -l $path_re/ -j $path_re/ -e -o$path_re/result三、再新建⼀个job:performanceTest_stop,⽤于远程控制机停⽌jmeter服务1、设置为在performanceTest构建完成后⾃动触发performanceTest_stop构建2、分别远程到每台linux,执⾏停⽌命令ps -ef | grep jmeter | grep -v grep | cut -c 9-15 | xargs kill -s 9四、在linux上搭建tomcat环境,⽤于展⽰测试报告1、下载Core下的zip包,解压到linux的⽬录2、到bin⽬录下给和赋予chmod 777权限,或者给全部sh⽂件赋予最⾼权限chmod 777 *.sh注意:如果访问不成功,如果我们想在本机中检测是否已经成功部署,那么我们必须关掉Linux中的防⽕墙或者开放8080端⼝,我在这⾥采⽤开放端⼝的⽅法。4、⽤指令sh 停⽌tomcat的运⾏,继续进⾏后续操作5、查看防⽕墙是否开启:systemctl status firewalld未开启:Active: inactive (dead)已开启:Active: active (running)开启防⽕墙:systemctl start firewalld关闭防⽕墙:systemctl stop firewalld执⾏开机禁⽤防⽕墙⾃启命令 : systemctl disable e开放端⼝号:firewall-cmd --permanent --zone=public --add-port=8080/tcp(只能在防⽕墙开启的情况下开放端⼝)五、java web项⽬(前端页⾯和后端接⼝写在⼀起的web项⽬)html代码:<%@ page contentType="text/html" pageEncoding="utf-8" %> 分布式压测平台 <%--计时器--%>

<%--计时器--%>

选择测试服务器(总并发量=脚本设置的并发量X服务器数量):

压测结果 压测⽇志
        
    
css代码:/*设置所有元素间的空隙为0*/* { margin: 0; padding: 0;}body { /*background-color: #444444;*/ /*background-image: url("/");*/ background-image: url("../css/image/");}.time {.time { background-color: #FFE14A; position: absolute; margin: auto; left: 0; right: 0; height: 100px; width: 100px; border-radius: 50px;}.myTime { background-color: #FFFACD; color: #3B3B3B; /*绝对定位,元素可以放置到页⾯上的任何位置*/ position: absolute; margin: auto; left: 0; top: 10px; right: 0; /*bottom:0;*/ width: 80px; height: 80px; border-radius: 40px; border: 8px solid #3B3B3B; text-align: center;}.logStyle { background-color: black; background-attachment: local; color: limegreen; float: left; font-size: 12px; width: 55%; height: 550px; overflow: scroll;}.jmeterLogStyle { background-color: black; background-attachment: local; color: limegreen; float: right; font-size: 12px; width: 44.5%; height: 550px; overflow: scroll;}.titleText { background-color: black; color: palevioletred; height: 20px;}.ant-btn { line-height: 1.499; position: relative; display: inline-block; font-weight: 400; font-weight: 400; white-space: nowrap; text-align: center; background-image: none; -webkit-box-shadow: 0 2px 0 rgba(0, 0, 0, 0.015); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.015); cursor: pointer; -webkit-transition: all .3s cubic-bezier(.645, .045, .355, 1); transition: all .3s cubic-bezier(.645, .045, .355, 1); -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; -ms-touch-action: manipulation; touch-action: manipulation; height: 26px; padding: 0 15px; font-size: 14px; border-radius: 4px; color: rgba(0, 0, 0, 0.65); background-color: #fff; border: 1px solid #d9d9d9;}.ant-btn-green { color: #3B3B3B; background-color: #FFE14A; border-color: #FFE14A; text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.12); -webkit-box-shadow: 0 2px 0 rgba(0, 0, 0, 0.045); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.045);}.checkboxStyle { color: white;}js代码:let get1;let n = 0;let timer = null; = function () { getResult(); getLog(); //每3秒⾃动执⾏⼀次 get1 = setInterval("judgeToResult('viewTestResult')", 3000);};//计时器function startTime(str) { switch (str) { case "start": //开始计时 clearInterval(timer); // setInterval() ⽅法可按照指定的周期(以毫秒计)来调⽤函数或计算表达式。 timer = setInterval(function () { n++; let m = (n / 3600); let s = (n / 60 % 60); let M = (n % 60); let msg = toDub(m) + ":" + toDub(s) + ":" + toDub(M); $("#myTime").val(msg) }, 1000 / 60); }, 1000 / 60); break; case "stop": //暂停并且清空计时器 clearInterval(timer); break; case "reTime": //重置 $("#myTime").val("00:00:00"); n = 0; break; default: }}//补零function toDub(n) { return n < 10 ? "0" + n : "" + n;}//停⽌jenkins buildfunction stopJenkinsBuild() { let r = confirm("确定要停⽌测试?"); if (r) { $.ajax({ type: "post",//请求⽅式 url: "./StartTest",//发送请求地址 data: { type: "stopBuild" }, success: function (data) { (data); }, error: function () { alert("停⽌测试异常") } }); } else { ("继续测试"); }}//查看报告是否⽣成function judgeToResult(str) { switch (str) { case 'gotoReport': $.ajax({ type: "post",//请求⽅式 url: "./LogCat",//发送请求地址 data: { type: "resultExist" }, success: function (data) { if (data === "报告存在") { = "10.10.10.115:8080/re/performanceTest/result/"; } else { alert("测试完成后才会⽣成报告"); } }, error: function () { ("查看报告是否⽣成异常") } }); break; case 'viewTestResult': $.ajax({ $.ajax({ type: "post",//请求⽅式 url: "./StartTest",//发送请求地址 data: { type: "BuildResult" }, success: function (data) { $("#viewTestStatus").html(data); if (data === '测试结束,请查看报告。。。') { startTime("stop");//暂停计时 (data); } else { startTime("start");//开始计时 getResult(); getLog(); // 20秒后只执⾏⼀次 setTimeout('getResult()', 10000); setTimeout('getLog()', 10000); } }, error: function () { ("查看测试状态异常") } }); break; default: }}//封装⼀个判断字符串为空的⽅法function isNullStr(str) { return str === null || str === undefined || str === '';}//请求jenkinsLog,并填充到元素function getResult() { $.ajax({ type: "post",//请求⽅式 url: "./StartTest",//发送请求地址 data: { type: "logCat" }, success: function (data) { $("#resText").html(data); }, error: function () { ("请求jenkinsLog异常") } }); //设置滚动条到最底部 let objDiv = mentById("resText"); Top = Height;}//请求jmeterLog,并填充到元素中function getLog() { $.ajax({ type: "post",//请求⽅式 url: "./LogCat",//发送请求地址 data: { type: "jmeterLog" }, success: function (data) { success: function (data) { $("#jmeterLog").html(data); }, error: function () { ("请求jmeterLog异常") } }); //设置滚动条到最底部 let objDiv = mentById("jmeterLog"); Top = Height;}//请求所有测试脚本名称function getAllJmx() { $.ajax({ type: "post",//请求⽅式 url: "./LogCat",//发送请求地址 data: { type: "getAllJmx" }, success: function (data) { $("#viewAllJmx").html(data); }, error: function () { alert("请求所有测试脚本名称异常") } });}//提⽰⽂件是否上传成功function uploadResult(result) { if (result === "success") { $("#uploadResule").html("⽂件上传成功"); } else if (result === "fail") { $("#uploadResule").html("请上传jxm格式的脚本⽂件"); } else { $("#uploadResule").html("⽂件上传异常"); }}//获取选择的服务器值,发送给后端function startTest() { let jmxName = mentById("inputJmxName").value;//获取输⼊的jmx脚本名 let obj = mentsByName("selevtServer"); //选择所有name=selevtServer的对象,返回数组 //循环检测它是不是被选中 let str = ""; for (let i = 0; i < ; i++) { if (obj[i].checked) str += obj[i].value + ","; //如果选中,将value添加到变量str中 } let testInfo = "确认测试信息nn脚本:" + jmxName + "n服务器:" + str; // alert(isNullStr(str) ? "没有选择压测服务器" : testInfo && isNullStr(jmxName) ? "没有输⼊脚本名" : testInfo && f("jmx") === -1 ? "脚本名输⼊错误 let r = confirm(isNullStr(str) ? "没有选择压测服务器" : testInfo && isNullStr(jmxName) ? "没有输⼊脚本名" : testInfo && f("jmx") === -1 ? "脚本名 if (r) { if (isNullStr(str) || isNullStr(jmxName) || f("jmx") === -1) { ('没有选择压测服务器or脚本名错误'); } else { $.ajax({ type: "post", url: "./StartTest", data: { type: 'build', ip: str, jmxName: jmxName jmxName: jmxName }, success: function (data) { if (data === '') { ('开始测试'); startTime("reTime");//重置计时器 } else { alert(data); } }, error: function () { alert("执⾏测试异常") } }); } } else { ("取消测试"); }}//⽤jQuery设置全选、取消全选 功能$("document").ready(function () { $("#selectAll").click(function () { $("[name='selevtServer']").attr("checked", 'true');//全选 }); $("#selectAllClear").click(function () { $("[name='selevtServer']").removeAttr("checked");//取消全选 });});后端接⼝的代码⽐较多就不贴了。

发布者:admin,转转请注明出处:http://www.yc00.com/news/1689200218a220018.html

相关推荐

发表回复

评论列表(0条)

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信