Installing Java Environment
JMeter is a Java-based tool, so installing OpenJDK (or Oracle JDK) is mandatory. For Ubuntu, run the following commands to install OpenJDK 11 (a commonly used LTS version):
sudo apt update sudo apt install openjdk-11-jdk
Verify installation with:
java -version
This should display the installed Java version (e.g., openjdk version "11.0.xx"
).
Downloading and Installing JMeter
wget
to fetch the tarball (replace 5.6.2
with the latest version):wget https://dlcdn.apache.org/jmeter/binaries/apache-jmeter-5.6.2.tgz
/opt
(for system-wide access) or /usr/local
:sudo tar -xvzf apache-jmeter-5.6.2.tgz -C /opt
~/.bashrc
(or /etc/profile
for system-wide effect) and add:export JMETER_HOME=/opt/apache-jmeter-5.6.2 export PATH=$JMETER_HOME/bin:$PATH
Reload the file to apply changes:source ~/.bashrc
jmeter -v
You should see JMeter’s version, Java version, and other details.Creating a Basic Test Plan
A test plan defines the load scenario (e.g., number of users, requests). Here’s how to create one via the JMeter GUI (graphical interface):
jmeter
from the terminal (GUI mode).example.com
).80
for HTTP, 443
for HTTPS)./api/login
for a login API)..jmx
file (e.g., my_test_plan.jmx
) using “File” → “Save”.Running JMeter in Non-GUI Mode (Recommended for Load Testing)
The GUI mode is resource-intensive and not suitable for high-load tests. Use the command line instead:
jmeter -n -t /path/to/your_test_plan.jmx -l /path/to/results.jtl
-n
: Non-GUI mode (no GUI window).-t
: Path to the test plan file.-l
: Path to save results (.jtl
file, a CSV-formatted log of all requests).Generating HTML Reports
To visualize results in an easy-to-read HTML format, run the following command after the test completes:
jmeter -e -o /path/to/report/directory
-e
: Generate HTML report after test execution.-o
: Directory to save the report (must be empty or non-existent).index.html
file in a browser to view it.Distributed Load Testing (Optional)
For simulating massive loads (thousands of users), use multiple machines (master-slave setup):
jmeter.properties
(in the bin
directory) and set:server.rmi.ssl.disable=true # Disable SSL for simplicity (not recommended for production) server_port=1099 # Port for RMI communication
jmeter.properties
and add slave IPs to remote_hosts
:remote_hosts=slave1_ip:1099,slave2_ip:1099
jmeter-server
jmeter -n -t /path/to/test_plan.jmx -l /path/to/results.jtl -r
-r
: Start all remote slaves specified in remote_hosts
.Tips for Effective Testing
${username}
) and use CSV Data Set Config to read from a file.top
, htop
, or vmstat
on the target server to track CPU, memory, and disk usage during the test.