Installing Java Environment
JMeter is a Java-based tool, so installing a compatible JDK is mandatory. For CentOS, use the following commands to install OpenJDK 8 (a recommended version for JMeter stability):
sudo yum install -y java-1.8.0-openjdk-devel
Verify the installation with:
java -version
This should display the installed Java version (e.g., “openjdk version 1.8.0_xxx”). Configure environment variables by editing ~/.bash_profile or /etc/profile to include:
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
export PATH=$PATH:$JAVA_HOME/bin
Run source ~/.bash_profile to apply changes.
Downloading and Installing JMeter
Download the latest JMeter binary package from the official Apache website (e.g., apache-jmeter-5.4.3.tgz). Upload it to your CentOS server and extract it to a directory like /opt:
wget https://dlcdn.apache.org//jmeter/binaries/apache-jmeter-5.4.3.tgz
tar -xzf apache-jmeter-5.4.3.tgz -C /opt/
Create a symbolic link for easy access:
sudo ln -s /opt/apache-jmeter-5.4.3 /opt/jmeter
Configure environment variables by adding the following to ~/.bash_profile:
export JMETER_HOME=/opt/jmeter
export PATH=$PATH:$JMETER_HOME/bin
Run source ~/.bash_profile to enable the jmeter command globally.
Starting JMeter
Launch JMeter in GUI mode (for script development) using:
jmeter
For non-GUI mode (recommended for load testing to save resources), use:
jmeter -n
To start the JMeter server (required for distributed testing), run:
jmeter-server
Note: Disable SSL for distributed testing by editing jmeter.properties and setting server.rmi.ssl.disable=true.
Creating a Basic Test Plan for Web Applications
A test plan defines the simulation scenario. Follow these steps to create one:
example.com).80 for HTTP, 443 for HTTPS).http or https./login for login requests).GET, POST).username=admin&password=123456 for POST).Executing the Test Plan
Run the test plan in non-GUI mode for accurate results (GUI mode consumes significant memory during load testing). Use the following command:
jmeter -n -t /path/to/your/test_plan.jmx -l /path/to/results.jtl
-n: Non-GUI mode.-t: Path to the test plan file (.jmx).-l: Path to save results (.jtl format, a CSV file with raw data).-R parameter to specify remote servers (e.g., -R192.168.1.101:1099,192.168.1.102:1099).Analyzing Results
After the test completes, analyze the .jtl file using JMeter’s listeners or export it to a report:
jmeter -g /path/to/results.jtl -o /path/to/report
Open the index.html file in the report directory to view metrics like:
Best Practices for Effective Testing
top (Linux) or Windows Task Manager to monitor CPU, memory, and disk usage on the server during testing. This helps identify bottlenecks (e.g., high CPU usage due to inefficient code).