Basic JMeter - 57. Running JMeter script in Linux system

catalogue

There are two prerequisites for running JMeter script in Linux system:

  1. Configure Java environment in Linux system.
  2. Configure JMeter environment in Linux system. (because JMeter needs Java environment to run)

1. Installing Java environment in Linux system

Environmental description:

  • Linux system: CentOS 7.8
  • Java version: JDK 1.8

Preparation:

  • Download JDK 1.8 installation package: jdk-linux-x64.tar.gz (the package name will be different)
  • Transfer the jdk-linux-x64.tar.gz installation package to the / usr/java / directory of the Linux system.

(1) Unzip the Java installation package

# 1. View the installation package path
[root@localhost ~]# ll /usr/java/
Total consumption 181192
-rw-r--r--. 1 root root 185540433 6 May 22:19 jdk-linux-x64.tar.gz
[root@localhost ~]# 

# 2. Unzip the Java installation package to get jdk1.8.0_131 folder
[root@localhost /]# cd /usr/java/
[root@localhost java]# tar -zxvf jdk-linux-x64.tar.gz
[root@localhost java]# ll
 Total consumption 181192
drwxr-xr-x. 8   10  143       255 3 May 15, 2017 jdk1.8.0_131
-rw-r--r--. 1 root root 185540433 6 May 22:19 jdk-linux-x64.tar.gz

(2) Configuring Java environment variables

In the / etc/profile file, configure the Java environment variables.

The configuration contents are as follows:

# To the bottom of the configuration file
export JAVA_HOME=/usr/java/jdk1.8.0_131
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}

As shown in the figure below:

Tips:

After saving, we also need to make the environment variable just configured take effect. Use the source /etc/profile command to restart the system and load the contents in the / etc/profile file to make it take effect immediately. Of course, you can restart the computer to take effect.

(3) Verify that the Java environment is configured successfully

Execute command: java -version

The following content appears, indicating that the Java environment configuration is successful.

[root@localhost ~]# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

2. Installing JMeter on Linux system

(1) Download JMeter

JMeter download address: http://jmeter.apache.org/download_jmeter.cgi

On this page, click apache-jmeter-5.4.1.tgz to download.

As shown in the figure below:

(2) Transfer JMeter installation package to Linux system

Transfer the apache-jmeter-5.4.1.tgz file into the / usr/local directory of the Linux system.

[root@localhost local]# pwd
/usr/local
[root@localhost local]# ll
 Total consumption 69048
-rw-r--r--. 1 root root 70704620 6 May 23:27 apache-jmeter-5.4.1.tgz
drwxr-xr-x. 2 root root        6 4 November 2018 bin
drwxr-xr-x. 2 root root        6 4 November 2018 etc
drwxr-xr-x. 2 root root        6 4 November 2018 games
drwxr-xr-x. 2 root root        6 4 November 2018 include
drwxr-xr-x. 2 root root        6 4 November 2018 lib
drwxr-xr-x. 2 root root        6 4 November 2018 lib64
drwxr-xr-x. 2 root root        6 4 November 2018 libexec
drwxr-xr-x. 2 root root        6 4 November 2018 sbin
drwxr-xr-x. 5 root root       49 3 September 15:35 share
drwxr-xr-x. 2 root root        6 4 November 2018 src

(3) Unzip the JMeter installation package

# Unzip the installation package
[root@localhost local]# tar -zxvf apache-jmeter-5.4.1.tgz

# Get the unzipped jmeter directory
[root@localhost local]# ll
 Total consumption 69048
drwxr-xr-x. 8 root root      138 1 February 1970 apache-jmeter-5.4.1 (This is)
-rw-r--r--. 1 root root 70704620 6 May 23:27 apache-jmeter-5.4.1.tgz
drwxr-xr-x. 2 root root        6 4 November 2018 bin
drwxr-xr-x. 2 root root        6 4 November 2018 etc
drwxr-xr-x. 2 root root        6 4 November 2018 games
drwxr-xr-x. 2 root root        6 4 November 2018 include
drwxr-xr-x. 2 root root        6 4 November 2018 lib
drwxr-xr-x. 2 root root        6 4 November 2018 lib64
drwxr-xr-x. 2 root root        6 4 November 2018 libexec
drwxr-xr-x. 2 root root        6 4 November 2018 sbin
drwxr-xr-x. 5 root root       49 3 September 15:35 share
drwxr-xr-x. 2 root root        6 4 November 2018 src

(4) Configure JMeter environment variables

In the / etc/profile file, configure the environment variables of JMeter.

The configuration contents are as follows:

# To the bottom of the configuration file
export JMETER_HOME=/usr/local/apache-jmeter-5.4.1
export PATH=$PATH:${JMETER_HOME}/bin

As shown in the figure below:

Tips:

After saving, we also need to make the environment variable just configured take effect. Use the source /etc/profile command to restart the system and load the contents in the / etc/profile file to make it take effect immediately. Of course, you can restart the computer to take effect.

(5) Verify that the JMeter environment is configured successfully

Execute command: jmeter -v

The following content appears, indicating that JMeter environment configuration is successful.

[root@localhost ~]# jmeter -v
    _    ____   _    ____ _   _ _____       _ __  __ _____ _____ _____ ____
   / \  |  _ \ / \  / ___| | | | ____|     | |  \/  | ____|_   _| ____|  _ \
  / _ \ | |_) / _ \| |   | |_| |  _|    _  | | |\/| |  _|   | | |  _| | |_) |
 / ___ \|  __/ ___ \ |___|  _  | |___  | |_| | |  | | |___  | | | |___|  _ <
/_/   \_\_| /_/   \_\____|_| |_|_____|  \___/|_|  |_|_____| |_| |_____|_| \_\ 5.4.1

Copyright (c) 1999-2021 The Apache Software Foundation

3. Execute JMeter script in Linux system

Put the JMeter script into the / usr/local/apache-jmeter-5.4.1/bin directory. (the script may not add listeners)

Then enter / usr/local/apache-jmeter-5.4.1/bin directory and execute the following command:

jmeter -n -t CLI_test.jmx -l result.jtl

Parameter interpretation:

  • -n: non gui mode means non graphical mode.
  • -t: Specify the JMX script path, test plan. Followed by the path and script name of the JMeter script to run.
  • -l: Specify the path to the result file. Followed by the output result file path and result file name.
    1) If no result file path is specified, it will be created automatically, and a. csv file or. jtl file can be generated.
    2) If only the script name is written, it is found or created in the current directory by default.
  • -e: Generate test report after setting test.
  • -o: Specify the test report generation folder. The folder must be empty or does not exist.

The operation results are as follows:

[root@localhost bin]# jmeter -n -t CLI_test.jmx -l result.jtl
Creating summariser <summary>
Created the tree successfully using CLI_test.jmx
Starting standalone test @ Sun Jun 06 11:47:20 CST 2021 (1622951240796)
Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
summary +    101 in 00:02:09 =    0.8/s Avg: 64563 Min: 63303 Max: 64680 Err:   101 (100.00%) Active: 100 Started: 100 Finished: 0
summary +     99 in 00:00:00 =  322.5/s Avg: 63416 Min: 63276 Max: 63535 Err:    99 (100.00%) Active: 0 Started: 100 Finished: 100
summary =    200 in 00:02:09 =    1.5/s Avg: 63995 Min: 63276 Max: 64680 Err:   200 (100.00%)
Tidying up ...    @ Sun Jun 06 11:49:32 CST 2021 (1622951372015)
... end of run

Supplementary notes:

Because we have configured the JMeter environment variable, we can execute JMeter commands in any directory.

As shown below, execute the JMeter test script in the / root directory of Linux and run the same.

[root@localhost ~]# jmeter -n -t /usr/local/apache-jmeter-5.4.1/bin/CLI_test.jmx -l result.jtl
Creating summariser <summary>
Created the tree successfully using /usr/local/apache-jmeter-5.4.1/bin/CLI_test.jmx
Starting standalone test @ Sun Jun 06 11:50:28 CST 2021 (1622951428991)
Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
summary +      1 in 00:01:04 =    0.0/s Avg: 63262 Min: 63262 Max: 63262 Err:     1 (100.00%) Active: 100 Started: 100 Finished: 0
summary +    199 in 00:01:04 =    3.1/s Avg: 63236 Min: 63011 Max: 63459 Err:   199 (100.00%) Active: 0 Started: 100 Finished: 100
summary =    200 in 00:02:07 =    1.6/s Avg: 63236 Min: 63011 Max: 63459 Err:   200 (100.00%)
Tidying up ...    @ Sun Jun 06 11:52:37 CST 2021 (1622951557443)
... end of run

But note:

  • If the command is not executed in the current directory where the JMeter script is located, you need to fill in the full path of the script file.
  • There is also the jmeter.log file and result file generated by running the script, if the generation path is not specified. Will be generated in the current directory where the JMeter command is executed. (note this)

Tip: executing JMeter script in Windows system is basically the same as executing JMeter script in Linux system. So I won't explain it here.

Posted by kelesis on Sat, 06 Nov 2021 20:54:22 -0700