使用Jmeter的SSH插件执行命令行时,出现以下错误:
详细错误信息:
2021-09-02 17:03:43,023 ERROR o.a.j.p.s.s.SSHCommandSampler: Failed to connect to server with credentials root@10.xx.xx.xx:22 pw=****
2021-09-02 17:03:43,023 ERROR o.a.j.p.s.s.AbstractSSHSampler: SSH connexion error
com.jcraft.jsch.JSchException: Session.connect: java.net.SocketException: Connection reset
at com.jcraft.jsch.Session.connect(Session.java:565) ~[jsch-0.1.54.jar:?]
at org.apache.jmeter.protocol.ssh.sampler.AbstractSSHSampler.connect(AbstractSSHSampler.java:72) [ApacheJMeter_ssh-1.1.1-SNAPSHOT.jar:?]
at org.apache.jmeter.protocol.ssh.sampler.SSHCommandSampler.sample(SSHCommandSampler.java:64) [ApacheJMeter_ssh-1.1.1-SNAPSHOT.jar:?]
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:491) [ApacheJMeter_core.jar:3.2 r1790748]
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:425) [ApacheJMeter_core.jar:3.2 r1790748]
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:254) [ApacheJMeter_core.jar:3.2 r1790748]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_131]
仔细看了下: SSH connexion error
com.jcraft.jsch.JSchException: Session.connect: java.net.SocketException: Connection reset
原因: SSH插件连接远程linux机器时 连接重置,经定位发现是系统SSH终端连接数配置过小,查看虚拟机该参数(该参数在/etc/ssh/sshd_config中配置,为MaxStartups),MaxStartups 默认设置是 10:30:100,意思是从第10个连接开始以30%的概率(递增)拒绝新连接,直到连接数达到100为止。
解决方法:
- 修改/etc/ssh/sshd_config中的MaxStartups,将其改为MaxStartups 1000:30:1200;修改/etc/ssh/sshd_config中的MaxSessions,将其修改为1000
- 重启SSH服务
systemctl restart sshd.service
- 查看状态
systemctl status sshd.service
另外,系统的默认连接时间120秒,如果远程终端连接数过多,则会出现超时连接,解决办法如下:
- 修改/etc/ssh/sshd_config中LoginGraceTime 120,将其改为LoginGraceTime 0,其中0表示不限制连接时间。
- 重启SSH服务systemctl restart sshd.service