此次分享使用的jmeter版本是:5.1
背景
在某项目的高可用测试过程中,有个case,要求针对某些节点频繁断开与重启的过程中,接口的调用是否正常;
但是手动来启动与关闭服务,非常的麻烦,可能还达不到预想的结果,手动执行毕竟还是没有机器快。
于是乎,就想到了jmeter可否执行linux命令呢?
下载及安装
下载相应的jar包,分别存入jmeter相应的目录,如下:
Copy the ApacheJMeter_ssh-1.2.0.jar to $JMETER_HOME/lib/ext directoryCopy the jsch-0.1.55.jar to $JMETER_HOME/lib directory
![af564f347e0385a0ec73897268248d54.png](https://i-blog.csdnimg.cn/blog_migrate/aab0a0a8e55b5d6109e9618d69dc7b11.jpeg)
用法:
本次分享只使用到了:SSH Command
UsageUsing the plugin is simple (assuming familiarity with SSH and JMeter):SSH Command1.Create a new Test Plan2.Add a Thread Group3.Add a Sampler > SSH Command4.Specify the host to connect to, port, username and password (unencrypted) or a key file, and a command to execute (such as date)5.Add a Listener > View Results Tree6.Run the testSSH SFTP1.Create a new Test Plan2.Add a Thread Group3.Add a Sampler > SSH SFTP4.Specify the host to connect to, port, username and password (unencrypted) or a key file, and a SFTP command to execute (such as get)5.Specify a source file to download, an output file or to print the content in the test6.Add a Listener > View Results Tree7.Run the test
展示:
下面的内容替换为真实内容即可
![4beb6a9a751550f2d6ab6490e182389b.png](https://i-blog.csdnimg.cn/blog_migrate/870ed79d35571f112f7447732b231ff4.jpeg)
多个命令可以分号间隔,比如:cd /data;ls
![5646294c002c6ffe11ccd6105f05cc54.png](https://i-blog.csdnimg.cn/blog_migrate/98cf9b3c3a8f1ec460843ee1d947b5d6.jpeg)
结果
![b21305ab91339133411d929bfc9567ba.png](https://i-blog.csdnimg.cn/blog_migrate/4c3556ead4a90961c5dddd7b997a77a6.jpeg)