jmeter环境搭建

 

1、服务器信息:

主机名 IP地址 CPU/内存/磁盘 挂载树节点 角色 安装工具
bjcs-dev-yaliceshi-01 10.0.254.177 4核/8G/100G Secoo.开发环境.基础服务应用.test-group.yaliceshi-test master python3.7、fabric3、jmeter5.1.1
bjcs-dev-yaliceshi-02 10.0.254.178 4核/8G/100G Secoo.开发环境.基础服务应用.test-group.yaliceshi-test slave jmeter5.1.1
bjcs-dev-yaliceshi-03 10.0.254.180 4核/8G/100G Secoo.开发环境.基础服务应用.test-group.yaliceshi-test slave jmeter5.1.1
bjcs-dev-yaliceshi-04 10.0.254.181 4核/8G/100G Secoo.开发环境.基础服务应用.test-group.yaliceshi-test slave jmeter5.1.1

2、安装python3.7

2.1 切换到root账户

sudo su -

2.2 安装依赖包

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

yum install libffi-devel -y

2.3 下载Python3.7源码、编译安装

wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz tar

-zxvf Python-3.7.0.tgz cd Python-3.7.0

./configure --prefix=/usr/local/python37

make && make install

2.4 建立软链

ln -s /usr/local/python37/bin/python3.7 /usr/bin/python3

ln -s /usr/local/python37/bin/pip3 /usr/bin/pip3

2.5 添加python3到环境变量

vim ~/.bashrc

增加export PATH=$PATH:/usr/local/python37/bin

使用source ~/.bashrc使环境变量生效

2.6 解决pip3  “pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available”问题

2.6.1 原因

系统版本centos6.5,其中openssl的版本为OpenSSL 1.0.1e-fips 11 Feb 2013,而python3.7需要的openssl的版本为1.0.2或者1.1.x,需要对openssl进行升级,并重新编译python3.7.0。yum 安装的openssl 版本都比较低。

2.6.2 升级openssl

2.6.2.1 下载openssl

wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz

tar -zxvf openssl-1.1.1a.tar.gz

cd openssl-1.1.1a

2.6.2.2 编译安装

./config --prefix=/usr/local/openssl no-zlib #不需要zlib

make

make install

2.6.2.3 备份原配置

mv /usr/bin/openssl /usr/bin/openssl.bak

mv /usr/include/openssl/ /usr/include/openssl.bak

2.6.2.4 新版配置

ln -s /usr/local/openssl/include/openssl /usr/include/openssl

ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so

ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl

2.6.2.5 修改系统配置

## 写入openssl库文件的搜索路径

echo "/usr/local/openssl/lib" >> /etc/ld.so.conf

## 使修改后的/etc/ld.so.conf生效 

ldconfig -v

2.6.2.6 查看openssl版本

openssl version

2.6.2.7 重新安装python

./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl

make

make install

3、安装fabric3

pip3 install fabric3

4、批量安装jmeter5.1.1

4.1 java版本调整为1.8.0,默认1.7.0_79

fabfile.py 文件添加方法

@parallel()
def install_java():

    run("sudo su -")
    sudo("echo \ >> /etc/profile")
    sudo("echo JAVA_HOME=/usr/local/jdk1.8.0_131 >> /etc/profile")
    sudo("echo JRE_HOME=${JAVA_HOME}/jre >> /etc/profile")
    sudo("echo CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH >> /etc/profile")
    sudo("echo JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin >> /etc/profile")
    sudo("echo PATH=${JAVA_PATH}:$PATH >> /etc/profile")
    sudo("source /etc/profile")

执行fab install_java

4.2 批量下载安装jmeter

fabfile.py 文件添加方法

@parallel()
def install_jmeter():

    run("sudo su -")
    run("rm -f ./apache-jmeter-5.1.1.tgz")
    run("rm -rf ./apache-jmeter-5.1.1")
    run("wget http://mirrors.tuna.tsinghua.edu.cn/apache//jmeter/binaries/apache-jmeter-5.1.1.tgz")
    run('tar -xvzf apache-jmeter-5.1.1.tgz')
    run("mv -fi /root/apache-jmeter-5.1.1.tgz /home/zhangzhe/apache-jmeter-5.1.1.tgz")
    run("mv -fi /root/apache-jmeter-5.1.1 /home/zhangzhe/apache-jmeter-5.1.1")
    sudo("echo \ >> /etc/profile")
    sudo("echo JMETER_HOME=/home/zhangzhe/apache-jmeter-5.1.1 >> /etc/profile")
    sudo("echo CLASSPATH=/home/zhangzhe/apache-jmeter-5.1.1/lib/ext/ApacheJMeter_core.jar:/home/zhangzhe/apache-jmeter-5.1.1/lib/jorphan.jar:/home/zhangzhe/apache-jmeter-5.1.1/lib/logkit-2.0.jar:$CLASSPATH >> /etc/profile")
    sudo("echo PATH=/home/zhangzhe/apache-jmeter-5.1.1/bin:$PATH:$HOME/bin >> /etc/profile")
    sudo("source /etc/profile")

执行fab install_jmeter

4.3 批量添加jmeter plugin

fabfile.py 文件添加方法

@parallel()
def add_jmeter_plugin_files():
    run("rm -f ./uploadplugin.zip")
    put("uploadplugin.zip", "./uploadplugin.zip")
    run("rm -rf uploadplugin")
    run('unzip ./uploadplugin.zip')
    run("mv -f ./uploadplugin/* /home/zhangzhe/apache-jmeter-5.1.1/lib/ext")
    run("rm -f ./uploadplugin.zip")
    run("rm -rf uploadplugin")

执行fab add_jmeter_plugin_files

4.4 批量修改slave机器jmeter.properties文件

fabfile.py 文件添加方法

@parallel()
def edit_jmeter_slave_properties_files():
    run("echo \ >> /home/zhangzhe/apache-jmeter-5.1.1/bin/jmeter.properties")
    run("echo remote_hosts=localhost:1099 >> /home/zhangzhe/apache-jmeter-5.1.1/bin/jmeter.properties")
    run("echo server_port=1099 >> /home/zhangzhe/apache-jmeter-5.1.1/bin/jmeter.properties")
    run("echo server.rmi.localport=1099 >> /home/zhangzhe/apache-jmeter-5.1.1/bin/jmeter.properties")
    run("echo server.rmi.ssl.disable=true >> /home/zhangzhe/apache-jmeter-5.1.1/bin/jmeter.properties")
    run("echo jmeterengine.force.system.exit=true >> /home/zhangzhe/apache-jmeter-5.1.1/bin/jmeter.properties")

4.5 手动修改master机器jmeter.properties文件

remote_host=10.0.254.178:1099,10.0.254.180:1099,10.0.254.181:1099

server_port=1099

server.rmi.localport=1099

server.rmi.ssl.disable=true

jmeter.save.saveservice.timestamp_format=ms

jmeter.save.saveservice.timestamp_format=yyyy/MM/dd HH:mm:ss

language=zh_CN

sampleresult.default.encoding=UTF-8

4.6 将脚本文件夹批量上传至slave机器

fabfile.py 文件添加方法

@parallel()
def add_jmeter_files():
    filename = "script"
    run("rm -f ./"+filename+".zip")
    run("rm -rf "+filename)
    run("rm -rf ./apache-jmeter-5.1.1/bin/"+filename)
    #run("rm -rf ./apache-jmeter-5.1.1/bin/script/"+filename)
    put(filename+".zip", "./"+filename+".zip")
    run("unzip "+filename+".zip")
    run("mv -fi ./"+filename+" /home/zhangzhe/apache-jmeter-5.1.1/bin/"+filename)
    run("rm -f ./"+filename+".zip")
    run("rm -rf "+filename)

执行fab add_jmeter_files

4.7 批量启动slave机器jmeter-server服务

fabfile.py 文件添加方法

@parallel()
def set_up_jmeter_slave():
    with cd("/home/zhangzhe/apache-jmeter-5.1.1/bin"):
    run("./jmeter-server")

执行fab set_up_jmeter_slave

4.8 master执行测试脚本

sudo su - 

jmeter -n -t script/***/***.jmx -r -l script/***/result/***.jtl -e -o script/***/report/***

posted on 2020-07-21 15:00  python从零到一  阅读(43)  评论(0编辑  收藏  举报