基於JMeter5.1.1+Nginx1.12.2
JMeter發起壓測
Nginx做爲文件服務器 php
1、目錄結構:html
Dockerfile文件:java
FROM ubuntu:18.04
# 基礎鏡像
MAINTAINER yangjianliang <526861348@qq.com>
# 做者
RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
# 設置apt源爲阿里雲源
RUN apt-get clean && \
apt-get update && \
apt-get upgrade -y
# 檢查軟件包並升級
RUN apt-get install -y \
build-essential \
libtool \
libpcre3 \
libpcre3-dev \
zlib1g-dev \
openssl \
libssl-dev \
make && \
apt-get update && \
ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
apt-get install -y \
tzdata && \
rm -rf /var/lib/apt/lists/*
# 安裝依耐
ADD nginx-1.12.2.tar.gz /usr/local
RUN cd /usr/local/nginx-1.12.2 && \
./configure --with-http_ssl_module --with-http_gzip_static_module && \
make && \
make install
# 安裝Nginx
ADD jdk-8u201-linux-x64.tar.gz /usr/local/java
ENV JAVA_HOME=/usr/local/java/jdk1.8.0_201
ENV JRE_HOME=/usr/local/java/jdk1.8.0_201/jre
ENV PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
# 安裝Java
ADD apache-jmeter-5.1.1.tgz /usr/local/jmeter
ENV JMETER_HOME=/usr/local/jmeter/apache-jmeter-5.1.1
ENV JMETER_PATH=${JMETER_HOME}/bin:${PATH}
ENV PATH=${JMETER_HOME}/bin:${PATH}
# 安裝JMeter
COPY nginx-app.conf /usr/local/nginx/conf
# 複製nginx配置文件
RUN sed -i '$a sampleresult.default.encoding=UTF-8' /usr/local/jmeter/apache-jmeter-5.1.1/bin/jmeter.properties
RUN sed -i '159s/256/512/g' /usr/local/jmeter/apache-jmeter-5.1.1/bin/jmeter
# 修改JMeter配置文件
COPY baidu.jmx /home
# 複製JMeter腳本
EXPOSE 80
# 暴露80端口
CMD /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx-app.conf
# 啓動nginx並加載配置文件
linux
nginx-app.conf文件:nginx
user root;
worker_processes auto;
#error_log logs/error.log;
error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
charset utf-8,gbk;
#access_log logs/host.access.log main;
location / {
root /home;
# 目錄文件服務器根目錄
autoindex on;
# 容許nginx在瀏覽器以文件夾形式訪問
autoindex_exact_size off;
# 顯示文件大小
autoindex_localtime on;
# 顯示文件時間
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
daemon off;
docker
2、打包:apache
docker build -t jmeter-nginx .ubuntu
等待一下子瀏覽器
3、運行:bash
docker run -it -p 80:80 jmeter-nginx:latest /bin/bash
# 啓動容器暴露80端口並進入容器內部
jmeter -JN=10 -JT=5 -n -t /home/baidu.jmx -l /home/baidu.jtl -e -o /home/report
# 執行壓測命令
jmeter -J線程數變量名=值1 -J持續時間變量名=值2 -n -t jmx腳本 -l jtl文件 -e -o 測試報告目錄
傳遞參數的運行命令
大寫的J
N爲線程數
T爲持續時間(單位爲秒)
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx-app.conf
# 手動啓動nginx
訪問:
第二次運行:
再次發起壓測時,可修改線程數與持續時間,並修改jtl文件名與Dashboard Report測試報告文件名,jmx腳本不須要修改
jmeter -JN=20 -JT=10 -n -t /home/baidu.jmx -l /home/baidu_2.jtl -e -o /home/report_2