Docker swarm环境下部署JMETER集群-分布式压测

Docker swarm环境下部署JMETER集群-分布式压测

  • Docker compose yuml文件编写
    • 若需要加入已经存在的网络
    • 使用的镜像介绍
    • 部署集群
    • 查看服务部署情况
    • 执行分布式压测

Docker compose yuml文件编写

本文默认你已经使用docker swarm搭建好了docker集群环境

version: "3.9"
services:
  jmeter-master:
    image: zhangyx1619/jmeter-master:orcaljdk17-jmeter5.5-graphs-plugins-release
    volumes:
      - jmeter-master:/usr/local/jmeter/apache-jmeter-5.5/work_space/
    networks:
      - swarmnet
    hostname: jmeter-master
    deploy:
      labels:
        - com.service.name=jmeter-master
      mode: global
      placement:
        constraints:# 指定部署容器的docker节点
          - node.labels.index==node14
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
      update_config:
        parallelism: 1
        delay: 1s
        failure_action: rollback

  jmeter-slave01:
    image: zhangyx1619/jmeter-slave:orcaljdk17-jmeter5.5-graphs-plugins-release
    volumes:
      - jmeter-slave01:/usr/local/jmeter/apache-jmeter-5.5/
    networks:
      - swarmnet
    hostname: jmeter-slave01
    deploy:
      mode: global
      placement:
        constraints: # 指定部署容器的docker节点
          - node.hostname==host-10-0-105-38
      labels:
        - com.service.name=jmeter-slave01
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
      update_config:
        parallelism: 1
        delay: 1s
        failure_action: rollback
  jmeter-slave02:
    image: zhangyx1619/jmeter-slave:orcaljdk17-jmeter5.5-graphs-plugins-release
    volumes:
      - jmeter-slave02:/usr/local/jmeter/apache-jmeter-5.5/
    networks:
      - swarmnet
    hostname: jmeter-slave02
    deploy:
      mode: global
      placement:
        constraints:
          - node.hostname==host-10-0-105-138
      labels:
        - com.service.name=jmeter-slave02
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
      update_config:
        parallelism: 1
        delay: 1s
        failure_action: rollback
  jmeter-slave03:
    image: zhangyx1619/jmeter-slave:orcaljdk17-jmeter5.5-graphs-plugins-release
    volumes:
      - jmeter-slave03:/usr/local/jmeter/apache-jmeter-5.5/
    networks:
      - swarmnet
    hostname: jmeter-slave03
    deploy:
      mode: global
      placement:
        constraints:
          - node.hostname==host-10-0-168-91
      labels:
        - com.service.name=jmeter-slave03
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
      update_config:
        parallelism: 1
        delay: 1s
        failure_action: rollback
networks:
  swarmnet:
    name: swarmnet
    external: true

volumes:
  jmeter-master:
  jmeter-slave01:
  jmeter-slave02:
  jmeter-slave03:


若需要加入已经存在的网络

若需要将服务加入已经存在的网络则将networks:部分替换为

networks:
  swarmnet:
    name: swarmnet
    external: true

使用的镜像介绍

1.zhangyx1619/jmeter-master:orcaljdk17-jmeter5.5-graphs-plugins-release
jmeter主节点
2.zhangyx1619/jmeter-master:orcaljdk17-jmeter5.5-graphs-plugins-release
jmeter从节点
镜像含有jmeter-plugins-manager ,jmeter-plugins-perfmon,mysql-connector-java,jmeter-plugins-graphs-basic插件,并自带了压测脚本例子 helloword.jmx

部署集群

在docker swarm主节点执行

 docker stack deploy -c Docker compose yuml文件 jmeter

在这里插入图片描述

查看服务部署情况

docker stack services jmeter

在这里插入图片描述

执行分布式压测

在jmeter-master所在节点执行命令

docker exec -it jmeter-master容器id或者名称 jmeter  -n -t /usr/local/jmeter/apache-jmeter-5.5/work_space/helloWord.jmx -r -l /usr/local/jmeter/apache-jmeter-5.5/work_space/result.jtl -e -o /usr/local/jmeter/apache-jmeter-5.5/work_space/html/ 

jmeter命令options

  1. -n 以非图形化方式执行
  2. -t 指定需要执行压测脚本
  3. -r 启动所有jmeter节点执行压测任务
  4. -l 指定输出压测结果的文件
  5. -e 将压测结果导出成html
  6. -o 指定html输出路径
    脚本执行效果(下图为使用jenkins流水线执行效果)
    Docker swarm环境下部署JMETER集群-分布式压测_第1张图片

html压测报告(下图为使用nginx映射html,浏览器访问效果)
Docker swarm环境下部署JMETER集群-分布式压测_第2张图片

你可能感兴趣的:(微服务,分布式压测,docker,jmeter,分布式,压力测试)