linux_wiki:load_balancing_haproxy_and_keepalived

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

linux_wiki:load_balancing_haproxy_and_keepalived [2017/07/07 22:54]
billdozor [Network Addressing Setup]
linux_wiki:load_balancing_haproxy_and_keepalived [2019/05/25 23:50]
Line 1: Line 1:
-====== Load Balancing with HAProxy And Keepalived ====== 
- 
-**General Information** 
- 
-Creating a highly available pair of load balancers with HAProxy and Keepalived.  
- 
-**Checklist** 
-  * Number of systems 
-    * 2 servers to be load balancers 
-    * 2 servers for web servers (in the example) 
-  * Distro(s): Enterprise Linux 7 
- 
----- 
- 
-====== Network Addressing Setup ====== 
- 
-Network configuration used in the examples below. 
- 
-Load Balancers 
-  * Server "lb01" -> 10.1.2.1 (eth0) 
-  * Server "lb02" -> 10.1.2.2 (eth0) 
-  * "lb" -> 10.1.2.3 (load balancer virtual IP - floats between servers) 
- 
-Web Servers (used in haproxy example config) 
-  * web01 -> 10.1.2.50 
-  * web02 -> 10.1.2.51 
- 
----- 
- 
-====== Install ====== 
- 
-Install the required packages on the load balancer servers 
-  * KeepAliveD (high availability)<code bash>yum install keepalived</code> 
-  * HA-Proxy (load balancing)<code bash>yum install haproxy</code> 
- 
----- 
- 
-====== Configure ====== 
- 
-Configuring keepalived and haproxy. 
- 
-===== Keepalived ===== 
- 
-Keepalived utlizes a Linux kernel implementation of VRRP. (Virtual Router Redundancy Protocol) 
- 
-Official Site: http://www.keepalived.org/ 
- 
-  * Configure all nodes with these keepalive settings (/etc/keepalived/keepalived.conf). **Example**:<code bash>! Configuration File for keepalived 
- 
-vrrp_script check_haproxy { 
-  script "killall -0 haproxy"  # check the haproxy process 
-  timeout 1 
-  interval 2  # every 2 seconds 
-  weight 2  # add 2 points if OK 
-} 
- 
-vrrp_instance VI_1 { 
-    state BACKUP  # All instances 'BACKUP' to prevent VIP flapping 
-    interface eth0 
-    virtual_router_id 51 
-    priority 100  # All instances same priority to prevent VIP flapping 
-    advert_int 1 
- 
-    authentication { 
-      auth_type PASS 
-      auth_pass PASSWORDHERE 
-    } 
- 
-    virtual_ipaddress { 
-      10.1.2.3 
-    } 
- 
-  track_script { 
-    check_haproxy 
-  } 
-}</code> 
- 
-===== HA-Proxy ===== 
- 
-HAProxy is a TCP/HTTP load balancer. 
- 
-Official Site: http://www.haproxy.org/ 
- 
-  * Configure HA-Proxy (/etc/haproxy/haproxy.cfg) 
-    * Remove all example frontend and backend config sections (leave default section) 
-    * Add New frontend/backend sections **Example**:<code bash>#--------------------------------------------------------------------- 
-# http-in frontend which proxys to the backends 
-#--------------------------------------------------------------------- 
-frontend  http-in *:80 
-    # Log format 
-    option httplog 
- 
-    #-- ACLs - Match HTTP Requests --# 
-    acl url_web       path_beg    -i /mywebsite 
- 
-    #-- Backend Selection based on ACLs --# 
-    use_backend web_pool1    if url_web 
- 
-#--------------------------------------------------------------------- 
-# Backend Configuration 
-#--------------------------------------------------------------------- 
-backend web_pool1 
-    balance  roundrobin 
-    server  web01 10.1.2.50:80 check 
-    server  web02 10.1.2.51:80 check</code> 
- 
-===== Logging ===== 
- 
-Setup logging for HAProxy. 
- 
-  * Create a Rsyslog drop in file for HA-Proxy (/etc/rsyslog.d/haproxy.conf)<code bash>## HA-Proxy Rsyslog Config ## 
- 
-# Load UDP Modules 
-$ModLoad imudp 
- 
-# Run UDP server 
-$UDPServerRun 514 
- 
-# Allow only localhost 
-$AllowedSender UDP, 127.0.0.1 
- 
-# Send local2 haproxy logs to /var/log/haproxy.log 
-local2.none  /var/log/messages 
-local2.*     /var/log/haproxy.log</code> 
-  * Restart rsyslog<code bash>systemctl restart rsyslog</code> 
- 
----- 
- 
-====== Operate ====== 
- 
-Operating the load balancers. 
- 
----- 
- 
-===== Services ===== 
- 
-Start and enable the services on each node. 
- 
-  * HA-Proxy<code bash>systemctl start haproxy 
-systemctl enable haproxy</code> 
-  * Keepalived<code bash>systemctl start keepalived 
-systemctl enable keepalived</code> 
- 
----- 
- 
-===== Reboots ===== 
- 
-Reboot procedure and dependencies. 
- 
-  * Load Balancers (lb01, lb02) can be rebooted 1 at a time to avoid service interruption. 
-  * Determine the inactive system (the system that does NOT have the virtual IP as a secondary address<code bash>ip addr sh</code> 
-    * Reboot the inactive system<code bash>reboot</code> 
-    * Once the inactive system is up, verify keepalived and haproxy are running<code bash>systemctl status keepalived haproxy</code> 
-  * Stop keepalived on the active system in order to force a fail over<code bash>systemctl stop keepalived</code> 
-    * Reboot the system with keepalived stopped<code bash>reboot</code> 
- 
----- 
  
  • linux_wiki/load_balancing_haproxy_and_keepalived.txt
  • Last modified: 2019/05/25 23:50
  • (external edit)