You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
24
24
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.
26
26
27
27
## Before You Begin
28
28
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.
30
30
31
31
2. Update your system:
32
32
33
33
sudo apt-get update && sudo apt-get upgrade
34
34
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.
36
36
37
37
{{< 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`.
39
39
{{< /note >}}
40
40
41
41
## Installation
@@ -52,7 +52,7 @@ HAProxy is included in the package management systems of most Linux distribution
52
52
53
53
## Initial Configuration
54
54
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:
56
56
57
57
{{< file "/etc/haproxy/haproxy.cfg" aconf >}}
58
58
global
@@ -96,23 +96,23 @@ defaults
96
96
{{< /file >}}
97
97
98
98
99
-
The `global` section defines systemlevel 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.
100
100
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.
102
102
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`:
104
104
105
105
option dontlog-normal
106
106
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:
108
108
109
109
option log-separate-errors
110
110
111
111
## Configure Load Balancing
112
112
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.
114
114
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:
116
116
117
117
{{< file "/etc/haproxy/haproxy.cfg" aconf >}}
118
118
frontend haproxynode
@@ -124,10 +124,10 @@ frontend haproxynode
124
124
125
125
126
126
{{< 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.
128
128
{{< /note >}}
129
129
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**.
131
131
132
132
2. Add the back end configuration:
133
133
@@ -146,12 +146,12 @@ backend backendnodes
146
146
147
147
This defines **backendnodes** and specifies several configuration options:
148
148
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.
155
155
156
156
3. Add the optional stats node to the configuration:
157
157
@@ -166,9 +166,9 @@ listen stats
166
166
{{< /file >}}
167
167
168
168
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.
170
170
171
-
4.Here is the complete configuration file after modifications:
171
+
4.Below is the complete configuration file after applying the modifications:
172
172
173
173
{{< file "/etc/haproxy/haproxy.cfg" aconf >}}
174
174
global
@@ -235,10 +235,10 @@ listen stats
235
235
236
236
## Running and Monitoring
237
237
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:
239
239
240
240
sudo service haproxy restart
241
241
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.
243
243
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