Skip to content

Commit f5385ad

Browse files
[Update] Using HAProxy for Load Balancing (#7136)
* Update index.md Made grammatical and clarity fixes. * Copy edits --------- Co-authored-by: Nathan Melehan <[email protected]>
1 parent 7304933 commit f5385ad

File tree

1 file changed

+25
-25
lines changed
  • docs/guides/uptime/loadbalancing/how-to-use-haproxy-for-load-balancing

1 file changed

+25
-25
lines changed

docs/guides/uptime/loadbalancing/how-to-use-haproxy-for-load-balancing/index.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ aliases: ['/uptime/loadbalancing/how-to-use-haproxy-for-load-balancing/']
2020

2121
## What is HAProxy?
2222

23-
HAProxy (High Availability Proxy) is a TCP/HTTP load balancer and proxy server that allows a webserver to spread incoming requests across multiple endpoints. This is useful in cases where too many concurrent connections over-saturate the capability of a single server. Instead of a client connecting to a single server which processes all of the requests, the client will connect to an HAProxy instance, which will use a reverse proxy to forward the request to one of the available endpoints, based on a load-balancing algorithm.
23+
HAProxy (High Availability Proxy) is a TCP/HTTP load balancer and proxy server that allows a webserver to spread incoming requests across multiple endpoints. This is useful in cases where too many concurrent connections over-saturate the capability of a single server. Instead of a client connecting to a single server that processes all of the requests, the client will connect to an HAProxy instance, which will use a reverse proxy to forward the request to one of the available endpoints, based on a load-balancing algorithm.
2424

25-
This guide will describe the installation and configuration of HAProxy for load-balancing HTTP requests, but the configuration can be adapted for most load-balancing scenarios. The setup is simplified from a typical production setup and will use a single HAProxy node with two web server nodes which will service the requests forwarded from the HAProxy node.
25+
This guide will describe the installation and configuration of HAProxy for load-balancing HTTP requests, but the configuration can be adapted for most load-balancing scenarios. The setup is simplified from a typical production setup and will use a single HAProxy node with two web server nodes to service the requests forwarded from the HAProxy node.
2626

2727
## Before You Begin
2828

29-
1. This guide will use `sudo` wherever possible. Complete the sections of our [Securing Your Server](/docs/products/compute/compute-instances/guides/set-up-and-secure/) guide to create a standard user account, harden SSH access and remove unnecessary network services.
29+
1. This guide will use `sudo` for commands that require administrative privileges. To get started, follow the steps in our [Securing Your Server](/docs/products/compute/compute-instances/guides/set-up-and-secure/) guide to set up a standard user account, secure SSH access, and remove any unnecessary network services.
3030

3131
2. Update your system:
3232

3333
sudo apt-get update && sudo apt-get upgrade
3434

35-
3. This guide uses private IP addresses in the example configurations. Refer to our [Linux Static IP Configuration](/docs/products/compute/compute-instances/guides/manual-network-configuration/) guide to add private IP addresses and internally network your Linodes.
35+
3. This guide uses private IP addresses in the example configurations. To set up private IPs and enable internal networking between Linodes, follow the steps in our [Linux Static IP Configuration](/docs/products/compute/compute-instances/guides/manual-network-configuration/) guide.
3636

3737
{{< note >}}
38-
This guide is written for a non-root user. Commands that require elevated privileges are prefixed with `sudo`. If you’re not familiar with the `sudo` command, see the [Users and Groups](/docs/guides/linux-users-and-groups/) guide.
38+
This guide is written for a non-root user. Commands requiring administrative privileges are prefixed with `sudo`. Refer to our [Users and Groups](/docs/guides/linux-users-and-groups/) guide for more information on how to use `sudo`.
3939
{{< /note >}}
4040

4141
## Installation
@@ -52,7 +52,7 @@ HAProxy is included in the package management systems of most Linux distribution
5252

5353
## Initial Configuration
5454

55-
1. Review the default configuration file at `/etc/haproxy/haproxy.cfg`, which is created automatically during installation. This file defines a standard setup without any load balancing:
55+
1. Review the default configuration file located at `/etc/haproxy/haproxy.cfg`, which is generated automatically during installation. This file provides a basic setup without any load balancing configured:
5656

5757
{{< file "/etc/haproxy/haproxy.cfg" aconf >}}
5858
global
@@ -96,23 +96,23 @@ defaults
9696
{{< /file >}}
9797

9898

99-
The `global` section defines system level parameters such as file locations and the user and group under which HAProxy is executed. In most cases you will not need to change anything in this section. The user **haproxy** and group **haproxy** are both created during installation.
99+
The `global` section defines system-level parameters, such as file locations and the user and group that HAProxy runs under. Generally, no changes are needed in this section. During installation, both the **haproxy** user and **haproxy** group are created automatically.
100100

101-
The `defaults` section defines additional logging parameters and options related to timeouts and errors. By default, both normal and error messages will be logged.
101+
The `defaults` section specifies additional logging parameters and options for handling timeouts and errors. By default, it logs both standard and error messages.
102102

103-
2. If you wish to disable normal operation messages from being logged you can add the following after `option dontlognull`:
103+
2. To stop logging regular operation messages, add the following line after `option dontlognull`:
104104

105105
option dontlog-normal
106106

107-
3. You can also choose to have the error logs in a separate log file:
107+
3. A separate log file for error messages can be configured using the following command:
108108

109109
option log-separate-errors
110110

111111
## Configure Load Balancing
112112

113-
When you configure load balancing using HAProxy, there are two types of nodes which need to be defined: frontend and backend. The frontend is the node by which HAProxy listens for connections. Backend nodes are those by which HAProxy can forward requests. A third node type, the stats node, can be used to monitor the load balancer and the other two nodes.
113+
When configuring load balancing with HAProxy, two types of nodes need to be defined: frontend and backend. The frontend node listens for incoming connections, while backend nodes handle the requests forwarded by HAProxy. A third node type, the stats node, can be set up to monitor the load balancer and the other two nodes.
114114

115-
1. Open `/etc/haproxy/haproxy.cfg` in a text editor and append the configuration for the front end:
115+
1. Open `/etc/haproxy/haproxy.cfg` in a text editor and add the following configuration for the frontend node:
116116

117117
{{< file "/etc/haproxy/haproxy.cfg" aconf >}}
118118
frontend haproxynode
@@ -124,10 +124,10 @@ frontend haproxynode
124124

125125

126126
{{< note respectIndent=false >}}
127-
Throughout this guide, replace `203.0.113.2` with the IP address of your frontend node. 192.168.1.3 and 192.168.1.4 will be used as the IP addresses for the backend nodes.
127+
Throughout this guide, replace `203.0.113.2` with the IP address of the frontend node. 192.168.1.3 and 192.168.1.4 will be used as the IP addresses for the backend nodes.
128128
{{< /note >}}
129129

130-
This configuration block specifies a frontend node named **haproxynode**, which is bound to all network interfaces on port 80. It will listen for HTTP connections (it is possible to use TCP mode for other purposes) and it will use the back end **backendnodes**.
130+
This configuration block specifies a frontend node named **haproxynode**, which is bound to all network interfaces on port 80. It will listen for HTTP connections (TCP mode can be used for other purposes) and direct traffic to the back end group, **backendnodes**.
131131

132132
2. Add the back end configuration:
133133

@@ -146,12 +146,12 @@ backend backendnodes
146146

147147
This defines **backendnodes** and specifies several configuration options:
148148

149-
- The `balance` setting specifies the load-balancing strategy. In this case, the `roundrobin` strategy is used. This strategy uses each server in turn but allows for weights to be assigned to each server: servers with higher weights are used more frequently.
150-
Other strategies include `static-rr`, which is similar to `roundrobin` but does not allow weights to be adjusted on the fly; and `leastconn`, which will forward requests to the server with the lowest number of connections.
151-
- The `forwardfor` option ensures the forwarded request includes the actual client IP address.
152-
- The first `http-request` line allows the forwarded request to include the port of the client HTTP request. The second adds the proto-header containing https if `ssl_fc`, a HAProxy system variable, returns true. This will be the case if the connection was first made via an SSL/TLS transport layer.
153-
- `Option httpchk` defines the check HAProxy uses to test if a web server is still valid for forwarding requests. If the server does not respond to the defined request it will not be used for load balancing until it passes the test.
154-
- The `server` lines define the actual server nodes and their IP addresses, to which IP addresses will be forwarded. The servers defined here are **node1** and **node2**, each of which will use the health check you have defined.
149+
- The `balance` setting specifies the load-balancing strategy. In this example, the `roundrobin` strategy is used, which cycles through each server in turn. This strategy allows for assigning weights to servers, so those with higher weights receive more traffic.
150+
Other strategies include `static-rr`, which works like `roundrobin` but does not support dynamic weight adjustments, and `leastconn`, which routes requests to the server with the fewest active connections.
151+
- The `forwardfor` option ensures that the client's IP address is included in the forwarded request.
152+
- The first `http-request` line includes the client's original port in the forwarded request. The second `http-request` line adds the `proto` header with https if `ssl_fc`, a HAProxy system variable, is true. This happens when the initial connection is made over SSL/TLS.
153+
- `Option httpchk` specifies the health check HAProxy uses to determine if a web server is available for forwarding requests. If the server does not respond to the defined check, it will be excluded from load balancing until it passes the test.
154+
- The `server` lines define the server nodes and the IP addresses where requests will be forwarded. In this example, the servers are **node1** and **node2**, and each will use the defined health check.
155155

156156
3. Add the optional stats node to the configuration:
157157

@@ -166,9 +166,9 @@ listen stats
166166
{{< /file >}}
167167

168168

169-
The HAProxy stats node will listen on port 32700 for connections and is configured to hide the version of HAProxy as well as to require a password login. Replace `password` with a more secure password. In addition, it is recommended to disable stats login in production.
169+
The HAProxy stats node is set to listen for connections on port 32700. It is configured to hide the HAProxy version and requires a password login. Replace `password` with a more secure password. It is recommended to disable stats login in production environments.
170170

171-
4. Here is the complete configuration file after modifications:
171+
4. Below is the complete configuration file after applying the modifications:
172172

173173
{{< file "/etc/haproxy/haproxy.cfg" aconf >}}
174174
global
@@ -235,10 +235,10 @@ listen stats
235235

236236
## Running and Monitoring
237237

238-
1. Restart the HAProxy service so that the new configuration can take effect:
238+
1. Restart the HAProxy service to apply the new configuration:
239239

240240
sudo service haproxy restart
241241

242-
Now, any incoming requests to the HAProxy node at IP address 203.0.113.2 will be forwarded to an internally networked node with an IP address of either 192.168.1.3 or 192.168.1.4. These backend nodes will serve the HTTP requests. If at any time either of these nodes fails the health check, they will not be used to serve any requests until they pass the test.
242+
Now, any incoming requests to the HAProxy node at IP address 203.0.113.2 will be forwarded to one of the backend nodes at 192.168.1.3 or 192.168.1.4, which will handle the HTTP requests. If either backend node fails the health check, it will be temporarily removed from service until it passes the test.
243243

244-
In order to view statistics and monitor the health of the nodes, navigate to the IP address or domain name of the frontend node in a web browser at the assigned port, e.g., http://203.0.113.2:32700. This will display statistics such as the number of times a request was forwarded to a particular node as well the number of current and previous sessions handled by the frontend node.
244+
To view statistics and monitor node health, open a web browser and navigate to the frontend node's IP address or domain using the designated port, e.g., http://203.0.113.2:32700. This page displays statistics such as the number of requests each backend node has handled and the current and previous sessions handled by the frontend node.

0 commit comments

Comments
 (0)