How to Install Siege on Ubuntu 24.04, 22.04 or 20.04

Siege is a powerful benchmarking tool used to test the performance and stability of web servers under load. It allows you to simulate multiple users accessing your website simultaneously, providing valuable insights into how your server handles high traffic. Siege supports basic HTTP/HTTPS protocols and can perform GET, POST, and other request methods. It’s widely used for stress testing, performance tuning, and ensuring web applications can handle peak loads.

To install Siege on Ubuntu 24.04, 22.04, or 20.04, you have two primary options: installing from the Ubuntu default repository using the command-line terminal, or downloading and installing Siege directly from the source for the latest version and additional features. This guide will walk you through both installation methods.

Update Ubuntu Before Siege Installation

Ensuring your Ubuntu system is up-to-date with the latest packages is crucial for maintaining an efficient, secure, and dependable computing environment. When we execute the command sudo apt update, the system’s package lists are refreshed.

Here’s the command to perform this:

sudo apt update && sudo apt upgrade

Select Siege Installation Method

Option 1: Install Siege via Ubuntu Default Repository

Siege is included in Ubuntu’s default repositories as a handy benchmarking tool. This significantly simplifies the installation process, allowing us to use Ubuntu’s built-in package management tool (APT) to carry out the installation.

The command sudo apt install siege triggers the APT system to search for the Siege package in the repositories, handle dependencies, and install Siege on your system. The ‘sudo’ at the beginning is necessary as it allows the command to be executed with root privileges, which are required for system-wide installations.

To install Siege, input the following command:

sudo apt install siege 

Option 2: Install Siege on Ubuntu via source

Compiling Siege from its source code is optimal for individuals who prefer to stay updated with the latest features and improvements. This method entails fetching the most recent source code and manually compiling it, ensuring you have the most up-to-date version of Siege.

Downloading the Latest Siege Source

To begin with, you’ll need to procure the latest source code. The Siege team provides a consistent link for the latest version, simplifying this process. However, it is always a good practice to ensure the link remains valid over time.

To download the latest source code, open your terminal and execute the following command:

wget http://download.joedog.org/siege/siege-latest.tar.gz

Extracting and Preparing the Source

Once the download completes, extracting the archive’s contents is the next step. Execute the following command to achieve this:

tar -xvf siege-latest.tar.gz

This command will decompress the Siege source code into a directory. Navigate to this directory with:

cd siege-*/

It’s worth noting that the exact directory name might vary with different Siege versions. Ensure you’re in the correct directory before proceeding further.

Before diving into the compilation process, it’s recommended to install the zlib package, which aids in the compression and decompression of data:

sudo apt install zlib1g-dev

Compile and Install Siege Binary

Now, you’ll initiate the compilation and installation process within the Siege source directory. The sequence of commands below will configure the build settings, compile the source code, and subsequently install Siege on your Ubuntu system:

./configure --with-zlib
make
sudo make install

These commands configure the build options, compile the source code, and install Siege on your Debian system.

Verifying Siege Installation

After the installation, it’s essential to verify that Siege has been correctly installed. Additionally, checking the installed version can provide insights into its compatibility with specific features or plugins and inform you if future updates are necessary.

To ascertain the installed version of Siege on your system, run the following:

siege --version

Configure Siege on Ubuntu

Correctly configuring Siege is essential for it to function optimally and fully leverage its capabilities. This process involves modifying the Siege configuration file .siegerc, which is located in the home directory.

Locating the Siege Configuration File

The siegerc file is a key asset, serving as the control center for Siege’s operation. It comprises a myriad of parameters that dictate the tool’s behavior. These parameters include the number of simulated users, the delay between requests, and the logging level.

Let’s start by exploring the existing siegerc file. You can accomplish this by running the cat command:

cat /etc/siege/siegerc

Configure Siege Configuration File

You’ll need to open the file using a text editor to alter the Siege configuration to align with your specific use case. In this guide, we’ll employ Nano for its user-friendliness and simplicity.

The command below allows you to open the siegerc file in the nano text editor:

sudo nano /etc/siege/siegerc

This file is a treasure trove of configurable options, but we’ll focus on some of the more commonly used parameters:

  • verbose: Determines whether the detailed output is displayed (true) or not (false).
  • csv: Indicates whether the output should be in CSV format (true) or not (false).
  • concurrent: Specifies the number of simulated users for the load test.
  • time: Determines the duration of the load test.
  • delay: Sets the time delay between each user’s request.
  • internet: Simulates user behavior by hitting random URLs on a website (true) or not (false).
  • benchmark: Allows Siege to run as a benchmark tool (true) or not (false).

As an example, if you want to set up a scenario where 25 users are simulated, each user sends a request every second, and the testing lasts for 1 hour, you would modify the relevant parameters as follows:

verbose = false
csv = true
concurrent = 25
time = 1H
delay = 1S
internet = false
benchmark = false

Once you’ve made your desired changes, save and exit by pressing Ctrl+X, followed by Y to confirm saving the changes, and then hit Enter.

HTTP Load Test with Siege on Ubuntu

Now that we’ve installed and configured Siege let’s explore some practical examples to give you a concrete idea of how this tool works. In these demonstrations, we’ll put your web server under a stress test, simulating a flood of requests, unlike a DDoS attack.

This can be highly valuable for understanding how your website would handle heavy traffic. However, obtain the necessary permissions and use these tools responsibly. They should ideally only be used on your servers.

BenchMark Load Test Website with Siege

First, apply Siege to test a website using the default number of simulated users (also known as “workers”), which is 25. We’ll also set the duration of the stress test to be one minute. This is achieved by using the -t 1m flag, as shown in the command below:

siege https://www.example.com -t 1m

Once you execute this command, Siege will start the stress test, simulating 25 concurrent users sending requests to your site for 1 minute. After the test concludes, Siege will present a detailed report of the results.

Remember that running the test for more meaningful and accurate insights is usually best for 5 to 15 minutes. The 1-minute duration was merely for demonstration purposes.

To increase the number of workers, you can employ the -c flag followed by the desired number. For example, to simulate 100 workers, use the -c 100 flag:

siege https://www.example.com -c 100 -t 2m

Stress Testing Multiple Websites with Siege

If you’re a system administrator or manage multiple domains, you’ll be pleased to know that Siege can handle multiple websites simultaneously. This is achievable through a configuration file /etc/siege/urls.txt, which Siege can use to determine which websites to stress test.

To configure this file, open it using nano:

sudo nano /etc/siege/urls.txt

Then, insert the URLs of the websites you want to stress test:

https://www.example.com
https://www.example2.com
http://192.168.50.1

To save these changes and exit, press Ctrl+O, Enter, and then Ctrl+X.

Finally, to initiate the stress test across the specified websites, execute the following command:

siege -f /etc/siege/urls.txt

Additional Siege Commands on Ubuntu

Siege is not only about bombarding your servers with requests; it’s a versatile tool that provides many options, allowing you to customize your testing approach. From controlling the number of concurrent users to adjusting the delay between each request, Siege’s command options let you model various scenarios.

This section will familiarize you with additional Siege commands that can empower you to conduct more nuanced and granular testing.

Controlling Delay Between Requests with Siege

With Siege, you can introduce a delay between each user’s requests to simulate more realistic user behavior. This ensures that requests aren’t sent continuously without breaks.

For instance, in the command below:

siege https://www.example.com -c 50 -d 5

Siege is instructed to stress test the specified website with 50 concurrent users, introducing a 5-second delay between each user’s request.

Customizing HTTP Method and Headers with Siege

Siege allows you to customize your stress test’s HTTP method and headers. For example, you may wish to send a POST request with custom headers. The -H flag allows you to set custom headers, while the –method option enables you to set the HTTP method. Here’s how you can use these options:

siege --method="POST" -H "Content-Type: application/json" https://www.example.com

In the above command, we’re using the POST method and setting the Content-Type header to application/json for our requests.

Logging Results with Siege

You may want to log your stress test results for further analysis or record-keeping. Siege can write the test results to a log file with the -l option:

siege -l https://www.example.com

This command tells Siege to log the stress test results. By default, Siege writes the logs to a file named siege.log in your home directory.

Closing Thoughts

With Siege successfully installed on your Ubuntu system, you can effectively benchmark and stress test your web servers. Whether you opt for the convenience of the Ubuntu default repository or the flexibility of installing directly from the source, Siege provides a reliable toolset for ensuring your web applications perform optimally under load. Regularly update Siege to take advantage of new features and improvements, and use it to maintain the stability and performance of your web servers.

Leave a Comment