一:分布式原理
准备多台相同局域网的Linux服务器,一台做为Master(调度机)-发送脚本、收集压测结果,其它的做为
Slave(压测机)-生成压力模拟用户向服务器发送请求,并把结果传给Master。
二.搭建环境
1)Master(调度机)和Slave(压测机)分别上传jmeter工具,上传成功后jmeter/bin目录下执行chmod +x ./* (对所有文件进行赋权,是指可以在linux下运行)
2)Master(调度机)和Slave(压测机)分别进入jmeter中bin目录,修改jmeter.properties,remote_hosts=调度机IP:1099,压测机IP:1099,…并保存,本次压测是2台Slave机器;(server_port默认是1099,也可以根据实际情况修改);修改jmeter.properties,server.rmi.ssl.disable=true,httpclient.timeout=1000,并保存;
3)俩台机器分别运行./jmeter-server
4)Master(调度机)重新开启一个窗口,bin目录下执行命令
./jmeter.sh -n -t X.jmx -r -l /保存文件路径/XXXX.jtl (注:-r是执行全部俩台机器)
[root@VM-333-22-centos bin]# ./jmeter.sh -n -t xxx.jmx -r -l /jmeter/xxx.jtl
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in[jar:file:/jmeter/apache-jmeter-5.1.1/lib/log4j-slf4j-impl-2.11.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in[jar:file:/jmeter/apache-jmeter-5.1.1/lib/ext/jmeter-plugins-dubbo-2.7.1-jar-with-dependencies.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type[org.apache.logging.slf4j.Log4jLoggerFactory]
Creating summariser <summary>
Created the tree successfully using xxx.jmx
Configuring remote engine: xx.x.xxx.xx:1099
Configuring remote engine: xx.x.xxx.xx:1099
Starting remote engines
Starting the test @ Mon May 09 16:01:04 CST 2022(1652083264324)
Remote engines have been started
Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
Tidying up remote @ Mon May 09 16:01:09 CST 2022(1652083269532)
说明调用成功了
搭建环境过程中遇到的问题及解决办法:
1)启动./jmeter-server返回:[JMeter]…java.rmi.RemoteException: Cannot start. localhost.localdomain is a loopback address xxxxxx
解决办法:
编辑jmeter-server文件,设置固定的代理服务器主机IP
打开Linux中的jmeter-server:
cd /opt/apache-jmeter-4.0/bin
vi jmeter-server
编辑jmeter-server,取消RMI_HOST_DEF的注释项,固定设置当前Linux主机查询到的IP:
# One way to fix this is to define RMI_HOST_DEF belowRMI_HOST_DEF=-Djava.rmi.server.hostname=192.168.248.130(当前机器ip)
保存后直接以命令 jmeter-server 或 ./jmeter-server 启动
2)调度机和压测机均启动./jmeter-server后,执行命令报错
Error in NonGUIDriver java.lang.RuntimeException: Following remote engines could not be configured:[xx.xx.xxx.xxx:1099]
解决方法:关闭压力机防火墙,命令:service iptables stop,然后service iptables status查看是否关闭成功(重启防火墙:service iptables start)
关闭防火墙后重新调用即可,如还不成,查询是否开启问题机器1099是否开启或被占用
查看端口号
netstat -ntlp //查看当前所有tcp端口·
netstat -ntulp |grep 1099 //查看所有1099端口使用情况·
开发端口命令:
命令一:firewall-cmd --zone=public --add-port=1099/tcp --permanent
命令二:nc -lp 1099 &(打开1099端口,即telnet),netstat -an | grep 1099 (查看是否打开1099端口)
版权归原作者 guozhen1994 所有, 如有侵权,请联系我们删除。