Installing and Configuring Apache JMeter on Ubuntu
1. Install Java Environment (Prerequisite)
JMeter is a Java-based tool, so a Java Development Kit (JDK) is required. Use OpenJDK (recommended for Ubuntu) for simplicity:
sudo apt update
sudo apt install openjdk-11-jdk # Use openjdk-8-jdk for legacy JMeter versions (e.g., 3.x)
Verify installation:
java -version
You should see output like openjdk version "11.0.xx" (confirm the version matches JMeter’s compatibility—most recent JMeter versions support Java 11+).
2. Download and Extract JMeter
Download the latest stable JMeter release from the official Apache website. For example (replace 5.6.3 with the latest version):
wget https://dlcdn.apache.org//jmeter/binaries/apache-jmeter-5.6.3.tgz
Extract the tarball to a directory (e.g., /opt for system-wide access):
sudo tar -xzf apache-jmeter-5.6.3.tgz -C /opt
Rename the extracted folder for consistency (optional but recommended):
sudo mv /opt/apache-jmeter-5.6.3 /opt/jmeter
3. Configure Environment Variables
To run JMeter from any terminal, add its bin directory to your PATH and set the JMETER_HOME variable. Edit the global profile file:
sudo nano /etc/profile
Add the following lines at the end (adjust paths if you used a different installation directory):
export JMETER_HOME=/opt/jmeter
export PATH=$JMETER_HOME/bin:$PATH
Save the file (Ctrl+O, Enter, Ctrl+X) and apply changes:
source /etc/profile
Verify JMeter is accessible:
jmeter -v
You should see JMeter’s version, Java version, and other system info.
4. Run JMeter in GUI Mode (Optional for Test Creation)
To use the graphical interface (for building test plans), execute:
jmeter
This opens the JMeter GUI, where you can add threads, HTTP requests, listeners (e.g., “View Results Tree”), and other components. Save your test plan as a .jmx file (e.g., my_test_plan.jmx).
5. Run JMeter in Non-GUI Mode (For Performance Testing)
For load testing, use non-GUI mode to minimize resource usage. Replace with the path to your .jmx file and with the desired results file:
jmeter -n -t -l
Example:
jmeter -n -t /opt/jmeter/my_test_plan.jmx -l /opt/jmeter/results.jtl
After the test completes, analyze results using JMeter’s GUI:
jmeter -g /opt/jmeter/results.jtl -o /opt/jmeter/report
This generates an HTML report in the /opt/jmeter/report directory.
6. Optional: Install Plugins for Enhanced Functionality
To extend JMeter’s capabilities (e.g., WebSocket support, advanced reporting), install the JMeter Plugins Manager:
- Download the plugin JAR from the official site.
- Copy it to the
lib/extdirectory:sudo cp jmeter-plugins-manager-1.7.jar /opt/jmeter/lib/ext/ - Restart JMeter, and the Plugins Manager will appear under the “Options” menu. Use it to install additional plugins (e.g., “WebSocket Sampler”).
Troubleshooting Common Issues
- Java Errors: Ensure Java is installed correctly and
JAVA_HOMEis set (runecho $JAVA_HOMEto verify). - Missing Dependencies: If you encounter
NoClassDefFoundError(e.g., for WebSocket plugins), install the required JARs (e.g.,jetty-http,websocket-common) in thelib/extdirectory. - Permission Denied: Run JMeter with
sudoor ensure thebindirectory has execute permissions (sudo chmod +x /opt/jmeter/bin/jmeter).
以上就是关于“Ubuntu JMeter如何安装配置”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm