Commit 2bb41360 authored by Mohamad Bashar Desoki's avatar Mohamad Bashar Desoki

Add Readme.md

parent e2d9ba2c
...@@ -9,7 +9,9 @@ ...@@ -9,7 +9,9 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="ad904d3c-917a-41ec-8997-0c459fd2925c" name="Changes" comment="add haproxy cfg" /> <list default="true" id="ad904d3c-917a-41ec-8997-0c459fd2925c" name="Changes" comment="add haproxy cfg1">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
...@@ -91,7 +93,15 @@ ...@@ -91,7 +93,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1740310829735</updated> <updated>1740310829735</updated>
</task> </task>
<option name="localTasksCounter" value="3" /> <task id="LOCAL-00003" summary="add haproxy cfg1">
<option name="closed" value="true" />
<created>1740310859230</created>
<option name="number" value="00003" />
<option name="presentableId" value="LOCAL-00003" />
<option name="project" value="LOCAL" />
<updated>1740310859230</updated>
</task>
<option name="localTasksCounter" value="4" />
<servers /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
...@@ -108,6 +118,7 @@ ...@@ -108,6 +118,7 @@
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value="simple web app" /> <MESSAGE value="simple web app" />
<MESSAGE value="add haproxy cfg" /> <MESSAGE value="add haproxy cfg" />
<option name="LAST_COMMIT_MESSAGE" value="add haproxy cfg" /> <MESSAGE value="add haproxy cfg1" />
<option name="LAST_COMMIT_MESSAGE" value="add haproxy cfg1" />
</component> </component>
</project> </project>
\ No newline at end of file
# Simple Web Server for HAProxy Lab
This project provides a basic web server implementation written in Java. It is designed to be used as a practical example for lab exercises involving HAPROXY, a popular open-source load balancer and proxy server.
## Table of Contents
1. [Introduction](#introduction)
2. [Features](#features)
3. [Getting Started](#getting-started)
* [Running the Web Server](#running-the-web-server)
4. [HAProxy Configuration](#haproxy-configuration)
5. [Usage Examples with HAProxy](#usage-examples-with-haproxy)
## Introduction
The Simple Web Server is intended to be deployed as part of a HAProxy proxy lab setup. This server can serve a simple HTML page and respond to status check requests, making it an excellent candidate for load balancing experiments using HAProxy.
## Features
- Serves a static HTML page.
- Allows configuration of the server name via command-line arguments.
- Responsive to health checks for load balancing applications (using `/status` endpoint).
## Getting Started
### Running the Web Server
To run a server instance, you need to specify `PORT_NUMBER` and `SERVER_NAME`:
```sh
java -jar SimpleWebServer.jar [PORT_NUMBER] [SERVER_NAME]
```
Or build and run using Maven:
```sh
mvn exec:java -Dexec.mainClass=org.ds.Main -Dexec.args="[PORT_NUMBER] [SERVER_NAME]"
```
Replace `[PORT_NUMBER]` with an actual port number (e.g., `8080`) and `[SERVER_NAME]` with your desired server name (e.g., `Server1`).
## HAProxy Configuration
Here is a sample HAPROXY configuration for load balancing across instances of the Simple Web Server:
```conf
frontend http_front
bind *:80
default_backend servers
backend servers
balance roundrobin
server srv1 127.0.0.1:8081 check
server srv2 127.0.0.1:8082 check
```
In this example:
- Instances of the Simple Web Server are run on `127.0.0.1` with ports `8081` and `8082`.
- The HAPROXY frontend listens on port 80 for incoming HTTP requests.
- Requests are distributed to the instances using a round-robin algorithm.
## Usage Examples with HAProxy
For your lab setup:
1. Start two Simple Web Server instances:
```sh
java -jar SimpleWebServer.jar 8081 Server1 &
java -jar SimpleWebServer.jar 8082 Server2 &
```
2. Configure and start HAPROXY using the sample configuration provided above.
3. Access any of the server instances through your browser at `http://localhost`. You should see requests distributed between `Server1` and `Server2`.
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Distributed Search</title> <title>Simple Web APP</title>
<meta http-equiv="cache-control" content="no-cache"/> <meta http-equiv="cache-control" content="no-cache"/>
</head> </head>
<body style="background: #e6f3ff;"> <body style="background: #e6f3ff;">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment