部署一个多机器节点多集群的 jmeter,为了防止单台节点导致试压机器压力不足
CSDN 上已有相关部署文档,但是有些依赖异常导致部署后无法使用,且部分模块版本过低
本次部署 jmeter 版本为最新 5.3 版
两台机器 CentOS(机器 IP 为 example,非真实机器,需要自己修改即可)
CentOS 内核版本应在 4 以上,检查命令:
➜ ~ cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
master 127.0.1.1
slave 127.0.1.2
部署一个多机器节点(本位以两个节点为例)多集群的 jmeter
sudo yum remove docker docker-common docker-selinux docker-engine
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce
$ sudo systemctl start docker
$ sudo systemctl enable docker
➜ ~ docker -v
Docker version 19.03.9
sudo docker run -d --restart=unless-stopped -p 8180:8080 rancher/server
http://127.0.1.1:8180
进入 系统管理→访问控制→local 中设置管理员账号密码。设置成功后重新登录
sudo docker run -e CATTLE_HOST_LABELS='host.ip=127.0.1.1&io.rancher.host.os=linux&io.rancher.host.name=master' --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.2.11 http://127.0.1.1:8180/v1/scripts/2862B95A38DD0CB90DFA:1577750400000:8oKSAkvBHUESvpGuDYDXn0RDPk
sudo docker run -e CATTLE_HOST_LABELS='host.ip=127.0.1.2&io.rancher.host.os=linux' --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.2.11 http://127.0.1.2:8180/v1/scripts/2862B95A38DD0CB90DFA:1577750400000:8oKSAkvBHUESvpGuDYDXn0RDPk
FROM ubuntu
# Install wger & JRE
RUN apt-get clean && \
apt-get -y update && \
apt-get -qy install \
wget \
default-jre-headless \
telnet \
iputils-ping \
unzip \
openssh-client \
vim
# Install jmeter
RUN mkdir /jmeter \
&& cd /jmeter/ \
&& wget https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-5.3.tgz \
&& tar -xzf apache-jmeter-5.3.tgz \
&& rm apache-jmeter-5.3.tgz \
&& mkdir /jmeter-plugins \
&& cd /jmeter-plugins/ \
&& wget https://jmeter-plugins.org/downloads/file/JMeterPlugins-ExtrasLibs-1.4.0.zip \
&& unzip -o JMeterPlugins-ExtrasLibs-1.4.0.zip -d /jmeter/apache-jmeter-5.3/ \
&& wget https://jmeter-plugins.org/files/packages/jpgc-perfmon-2.0.zip \
&& unzip -o jpgc-perfmon-2.0.zip -d /jmeter/apache-jmeter-5.3/ \
&& sed -i "s/#server.rmi.ssl.disable=false/server.rmi.ssl.disable=true/g" /jmeter/apache-jmeter-5.3/bin/jmeter.properties
# Set Jmeter Home
ENV JMETER_HOME /jmeter/apache-jmeter-5.3/
ENV TZ=Asia/Shanghai
# Add Jmeter to the Path
ENV PATH $JMETER_HOME/bin:$PATH
执行构建命令, 为什么叫 stone9903,因为 dockerhub 上注册的账户名是这个。push 上去的时候要带上这个账户名
docker build -t stone9903/jmeter-base .
FROM stone9903/jmeter-base
# Ports to be exposed from the container for JMeter Master
EXPOSE 60000
执行构建命令
docker build -t stone9903/jmeter-master .
FROM stone9903/jmeter-base
# Ports to be exposed from the container for JMeter Slaves/Server
EXPOSE 1099 50000
# Application to run on starting the container
ENTRYPOINT $JMETER_HOME/bin/jmeter-server \
-Dserver.rmi.localport=50000 \
-Dserver_port=1099 \
-Djava.rmi.server.hostname=${HOST_IP}
执行构建命令
docker build -t stone9903/jmeter-slave-ip .
➜ ~ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
stone9903/jmeter-slave-ip latest e80e424087f4 30 hours ago 513MB
stone9903/jmeter-master latest 68f31dc952ec 30 hours ago 513MB
stone9903/jmeter-base latest 0ec278f91ce9 30 hours ago 513MB
docker login 后输入账号密码
docker push stone9903/jmeter-base
docker push stone9903/jmeter-master
docker push stone9903/jmeter-slave-ip
docker-compose.yml
version: '2'
services:
master:
privileged: true
image: stone9903/jmeter-master
environment:
TZ: Asia/Shanghai
stdin_open: true
network_mode: host
volumes:
- /opt/jmeter:/home/jmeter
- /usr/share/zoneinfo/:/usr/share/zoneinfo/
tty: true
ports:
- 60000:60000/tcp
labels:
io.rancher.scheduler.affinity:host_label: io.rancher.host.name=master
io.rancher.container.pull_image: always
注意:此处增加了共享文件夹映射,将宿主机/opt/jmeter 文件夹映射到容器/home/jmeter 中,且下方要增加 privileged: true
另外也增加了节点时区映射,防止容器时间显示的不是东八区区时
添加该映射的目的是为了是宿主机和容器机器能公用一个文件夹,这样方便后续脚本 shell 执行
rancher-compose.yml
version: '2'
services:
master:
scale: 1
start_on_create: true
docker-compose.yml
version: '2'
services:
slave01:
privileged: true
image: stone9903/jmeter-slave-ip
environment:
HOST_IP: 127.0.1.2
TZ: Asia/Shanghai
stdin_open: true
volumes:
- /usr/share/zoneinfo/:/usr/share/zoneinfo/
tty: true
ports:
- 1099:1099/tcp
- 50000:50000/tcp
labels:
io.rancher.scheduler.affinity:host_label: host.ip=127.0.1.2
io.rancher.container.pull_image: always
rancher-compose.yml
version: '2'
services:
slave01:
scale: 1
start_on_create: true
注意,增加多节点的话,只需添加相同的 slave 节点即可,且,注意,上方 slave01 要改成 02。对应 hostip 也要修改
查看部署成功的节点