1

I am trying to set up HAproxy load balancer and sticky session on Redhat Enterprise 7.7. installing the HAproxy in two node web server using Apache to be "Web-Load-balance" and two node app server using java+jboss to be "App-Load-Balance".

Note: The web servers(Two Node) has installing Apache and HAProxy in the same servers Note: The App servers(Two Node) has installing Java+Jboss and HAProxy in the same servers

I'll share with you below the 4 test cases as vendor had got a result as:

Case 1:- Testing status (OK) no issue

  1. Web1 = ON
  2. Web2 = ON
  3. App1 = ON
  4. App2 = OFF

Case 2:- Testing status (OK) no issue

  1. Web1 = ON
  2. Web2 = ON
  3. App1 = OFF
  4. App2 = ON

Case 3:- Testing status "App-Load-Balance" server unable to maintained session ID (JBOSS)

  1. Web1 = ON
  2. Web2 = ON
  3. App1 = ON
  4. App2 = ON

Case 4:- Testing status "App-Load-Balance" server unable to maintained session ID (JBOSS)

  1. Web1 = ON
  2. Web2 = OFF
  3. App1 = ON
  4. App2 = ON

i will share the HAproxy configuer for both Web-load-balancer and App-load-balancer i don't mind that if I edit it complete and retype the code configuration from beginning.

The HAproxy code for two node Web servers as:

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global

    log         127.0.0.1 local2
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon
    stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
defaults
    mode                    http
    log                     global
   # option                  httplog
    option                  dontlognull
    #option http-server-close
    #option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000

#------------------- Haproxy LB  -----------------------
frontend ft_http
        bind *:880
        mode http
        default_backend bk_http
frontend ft_https
        bind *:8443
        mode tcp
        default_backend bk_https


backend bk_http
        mode http
        balance roundrobin
        server Web1_SRV 10.10.10.121:80 check 
        server Web2_SRV 10.10.10.122:80 check 
backend bk_https
        mode tcp
        balance roundrobin

        server Web1_SRV 10.10.10.121:443 check
        server Web2_SRV 10.10.10.122:443 check

peers Mypeer

        peer LB1 10.10.10.121:1024 
        peer LB2 10.10.10.122:1024 
#------------------ Haproxy LB --------------------------

#------------------- HAproxy Status Page -----------------

listen stats
bind *:1978
stats enable
stats hide-version
stats realm Haproxy\ Statistics
stats uri /showus
stats auth admin:admin

The code for Keepalived as web1:

#---------------------------------------------------------
# Start Keepalived1 - 
#----------------------------------------------------------
vrrp_script chk_haproxy {
                script "pidof haproxy"
                interval 2
}
vrrp_instance VI_1 {
                interface eth0
                state MASTER
                virtual_router_id 40
                priority 150
                vrrp_unicast_bind 10.10.10.121 #Internal IP of this node
                vrrp_unicast_peer 10.10.10.122 #Internal IP of Backup node
                virtual_ipaddress {
                                10.10.10.120
                }
                track_script {
                                chk_haproxy
                }
}
#----------------------------------------------------------
#  End Keepalived1  - WEB1
#---------------------------------------------------------

The code for Keepalived as web2:

#----------------------------------------------------------
# Start Keepalived2
#----------------------------------------------------------
vrrp_script chk_haproxy {
                script "pidof haproxy"
                interval 2
}
vrrp_instance VI_1 {
                interface eth0
                state MASTER
                virtual_router_id 40
                priority 100
                vrrp_unicast_bind 10.10.10.122 #Internal IP of this node
                vrrp_unicast_peer 10.10.10.121 #Internal IP of Backup node
                virtual_ipaddress {
                                10.10.10.120
                }
                track_script {
                                chk_haproxy
                }
}
#----------------------------------------------------------
#  End Keepalived2  -WEB2
#---------------------------------------------------------

The HAproxy code for two node APP servers as:

#---------------------------------------------------------------------
global
    log         127.0.0.1 local2
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon
    stats socket /var/lib/haproxy/stats
#-------------------------------------------------------------
defaults
    mode                    tcp
    log                     global
    option                  tcplog
    option                  dontlognull
    #option http-server-close
    #option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    #timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    #timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000

#--------------------   Start ----------------------------------
frontend haproxy_inbound
        bind *:8888
        unique-id-format %{+X}o\ %ci:%cp
        unique-id-header X-Unique-ID
        option tcp-smart-accept
        option splice-request
        option splice-response
        default_backend LB
backend LB
        option tcp-smart-connect
        option splice-request
        option splice-response
        balance hdr(X-Unique-ID)
        server APP1_SRV 10.10.24.111:8109 maxconn 10 weight 1 check
        server APP2_SRV 10.10.24.112:8109 maxconn 10 weight 1 check

peers Mypeer
                peer LB1 10.10.24.111:1024 
                peer LB2 10.10.24.112:1024 

#----------- Start HAPRoxy Status page -----------------------
listen stats
bind *:1978
mode http
stats enable
stats hide-version
stats realm Haproxy\ Statistics
stats uri /showus
stats auth admin:admin
#---------- End HAPRoxy Status page ----------------

The code Keepalived for APP1 as:

#----------------------------------------------------------
# Start Keepalived1 -
#----------------------------------------------------------
vrrp_script chk_haproxy {
                script "pidof haproxy"
                interval 2
}
vrrp_instance VI_1 {
                interface eth0
                state MASTER
                virtual_router_id 51
                priority 150
                vrrp_unicast_bind 10.10.24.111 #Internal IP of this node
                vrrp_unicast_peer 10.10.24.112 #Internal IP of Backup node
                virtual_ipaddress {
                                10.10.24.110
                }
                track_script {
                                chk_haproxy
                }
}
#----------------------------------------------------------
#  End Keepalived1  - APP1
#---------------------------------------------------------

The code Keepalived for APP2 as:

#----------------------------------------------------------
# Start Keepalived2 - 
#----------------------------------------------------------
vrrp_script chk_haproxy {
                script "pidof haproxy"
                interval 2
}
vrrp_instance VI_1 {
                interface eth0
                state MASTER
                virtual_router_id 51
                priority 100
                vrrp_unicast_bind 10.10.24.112 #Internal IP of this node
                vrrp_unicast_peer 10.10.24.111 #Internal IP of Backup node
                virtual_ipaddress {
                                10.10.24.110
                }
                track_script {
                                chk_haproxy
                }
}
#----------------------------------------------------------
#  End Keepalived2  - APP2
#----------------------------------------------------------

**

The goal from HAproxy to provide us load balancing and Sticky session.

**

Thank you.

Hasanain
  • 11
  • 2

0 Answers0