# file name:jmmaster_.Dockerfile# Use caster base imageFROM caster/jmeterMAINTAINER CasterHsu# Ports to be exposed from the container for JMeter MasterEXPOSE 60000# keep container aliveCMD ["tail", "-f", "/dev/null"]
# file name:jmslave_.Dockerfile# Use caster base imageFROM caster/jmeterMAINTAINER CasterHsu# Ports to be exposed from the container for JMeter Slaves/ServerEXPOSE 1099 50000# Application to run on starting the containerENTRYPOINT $JMETER_HOME/bin/jmeter-server# keep container aliveCMD ["tail", "-f", "/dev/null"]
啟動 JMeter Server 後,您可以知道 Server 在容器內部的 IP 地址。以這個範例為例,Slave 的 IP 是 '192.168.80.4'。
獲取容器 IP方式 一
您可以在日誌(log)內容中查找 IP 地址,通常位於 WARN 訊息後。以下是示例內容:
WARN StatusConsoleListener The use of package scanning to locate plugins is deprecated and will be removed in a future release
WARN StatusConsoleListener The use of package scanning to locate plugins is deprecated and will be removed in a future release
WARN StatusConsoleListener The use of package scanning to locate plugins is deprecated and will be removed in a future release
WARN StatusConsoleListener The use of package scanning to locate plugins is deprecated and will be removed in a future release
Created remote object: UnicastServerRef2 [liveRef: [endpoint:[192.168.80.4:46521](local),objID:[-21c30768:18bacbd9455:-7fff, 76839754569490693]]]
Creating summariser <summary>
Created the tree successfully using sample-test.jmx
Starting standalone test @ 2023 Nov 8 02:39:16 UTC (1699411156838)
Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
Warning: Nashorn engine is planned to be removed from a future JDK release
summary + 143 in 00:00:13 = 11.1/s Avg: 57 Min: 45 Max: 172 Err: 0 (0.00%) Active: 5 Started: 5 Finished: 0
summary + 238 in 00:00:17 = 14.1/s Avg: 56 Min: 43 Max: 160 Err: 0 (0.00%) Active: 0 Started: 5 Finished: 5
summary = 381 in 00:00:30 = 12.8/s Avg: 56 Min: 43 Max: 172 Err: 0 (0.00%)
Tidying up ... @ 2023 Nov 8 02:39:46 UTC (1699411186924)
... end of run
分散模式執行: 若要在分散式模式下執行測試,您需要指定 Docker Slave 容器的內部 IP 地址,可以使用 -R 選項指定多個 IP 地址,以逗號分隔。
Creating summariser <summary>
Created the tree successfully using sample-test.jmx
Configuring remote engine: 192.168.80.3
Configuring remote engine: 192.168.80.4
Starting distributed test with remote engines: [192.168.80.3, 192.168.80.4] @ 2023 Nov 8 02:41:03 UTC (1699411263848)
Warning: Nashorn engine is planned to be removed from a future JDK release
Remote engines have been started:[192.168.80.3, 192.168.80.4]
Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
summary + 1 in 00:00:00 = 2.1/s Avg: 91 Min: 91 Max: 91 Err: 0 (0.00%) Active: 2 Started: 2 Finished: 0
summary + 312 in 00:00:34 = 9.2/s Avg: 702 Min: 45 Max: 5547 Err: 10 (3.21%) Active: 0 Started: 10 Finished: 10
summary = 313 in 00:00:34 = 9.1/s Avg: 700 Min: 45 Max: 5547 Err: 10 (3.19%)
Tidying up remote @ 2023 Nov 8 02:41:38 UTC (1699411298753)
... end of run
# Use caster base imageFROM caster/jmeter-base:latestMAINTAINER CasterHsu# 更新 apt 套件管理系統的存儲庫,然後安裝 openssh-server 套件RUN apt-get update && apt-get install -y openssh-server# 將自定義啟動腳本覆制到容器內COPY start.sh /start.sh# 創建 SSH 伺服器需要的目錄RUN mkdir /var/run/sshd# 設定 root 用戶的密碼為 "aa123456"RUN echo 'root:aa123456' | chpasswd# 修改 SSH 伺服器的設定以允許 root 用戶透過密碼進行登入RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config# 修正 SSH 登入的問題,否則在登入後使用者會被踢出RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd# 將 PATH 環境變數添加到 /etc/profile 中RUN echo "export PATH=$PATH" >> /etc/profile# Ports to be exposed from the container for JMeter MasterEXPOSE 60000 22# keep container aliveCMD ["/start.sh"]
增加 SSH 設定實在不再守備範圍,花了一點時間才弄出來,而且還有點粗暴....
遇到的問題有:
sshd_config 設定取代
ssh server 啟動失敗,主因容器尚未完成,就下指令結果導致,改用 start.sh 啟動
連線成功後,user環境變數沒有吃到
ssh 連線指紋變更導致.know_hosts 檔案要修改
首次連接
Theauthenticityofhost'[172.20.160.120]:2222 ([172.20.160.120]:2222)'can't be established.ED25519 key fingerprint is SHA256:ez34LpGqQO5RGB+jzl0/3+l/W+UIshHcXTgALiZASC0.This key is not known by any other namesAre you sure you want to continue connecting (yes/no/[fingerprint])? yPlease type 'yes', 'no' or the fingerprint: yesWarning: Permanently added '[172.20.160.120]:2222' (ED25519) to the list of known hosts.root@172.20.160.120'spassword:Linuxa8ad45f5bdd75.10.16.3-microsoft-standard-WSL2#1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64TheprogramsincludedwiththeDebianGNU/Linuxsystemarefreesoftware;theexactdistributiontermsforeachprogramaredescribedintheindividualfilesin/usr/share/doc/*/copyright.DebianGNU/LinuxcomeswithABSOLUTELYNOWARRANTY,totheextentpermittedbyapplicablelaw.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@WARNING:REMOTEHOSTIDENTIFICATIONHASCHANGED!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ITISPOSSIBLETHATSOMEONEISDOINGSOMETHINGNASTY!Someonecouldbeeavesdroppingonyourightnow (man-in-the-middle attack)!Itisalsopossiblethatahostkeyhasjustbeenchanged.ThefingerprintfortheED25519keysentbytheremotehostisSHA256:ez34LpGqQO5RGB+jzl0/3+l/W+UIshHcXTgALiZASC0.Pleasecontactyoursystemadministrator.AddcorrecthostkeyinC:\\Users\\xxx/.ssh/known_hoststogetridofthismessage.OffendingECDSAkeyinC:\\Users\\xxx/.ssh/known_hosts:45Hostkeyfor [172.20.160.120]:2222 has changed and you have requested strict checking.Hostkeyverificationfailed.