HAProxy install and config in same application server

Hi All,
I have two Application servers and installed below services as:

  • HAProxy
  • Keepalived
  • JAVA
    -JBOSS

I want to make some configuration for HAProxy which is installed in App1 and App2
Source Web Servers [10.10.10.13 && 10.10.10.14] >>> connect to Load balance IP (10.31.24.230:8888) >>> connect to App Servers [ 10.31.24.231:8109 && 10.31.24.232:8109]

Load balance: 10.31.24.230:8888 listener port
App1 and App2 listener port on 8109: 10.31.24.231 && 10.31.24.232

thanks.

Hi Ali,

As I recall you already have a working configuration. Can you post it (without any sensitive information, like addresses accessible from the Internet)? Or is this a new installation?

Hi Sandmann,

Thank you very much,

first, I apologize for missing body,
Actually I am looking for Sticky Session setup …!!!
as I post in previous there are two Web Server talking to App server through HAProxy using virtual IP address.
I just i need the basic setup of Sticky session if I able to create it, I don’t know if this setup have to create it on HAProxy only or in both HAProxy and Application server which using jboss service???

I try to share with you full information but in fact there is a vendor who owner for this project and me i am responsible for infrastructure system like Servers, Networking, Storage and so on.
if I can understand the Sticky Session setup and concept it will help me to build my setup.

Thank you & Regards,

Hi,

I would like to share with you the current HAProxy code for Web and App system

Code Web Server:

#--------------------------------------------------------

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 dontlognull
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 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 10.100.3.131:80 check
server Web2 10.100.3.132:80 check
backend bk_https
mode tcp
balance roundrobin
server Web1 10.100.3.131:443 check
server Web2 10.100.3.132:443 check
peers Mypeer
peer HA1 10.100.3.131:1024
peer HA2 10.100.3.132:1024

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

Code Application Server:

#---------------------------------------------------------------------

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 tcp
log global
option tcplog
option dontlognull
option redispatch
retries 3
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout check 10s
maxconn 3000

#---------- Start -----------------------------
frontend haproxy_inbound
bind *:8888
mode tcp
default_backend LB
backend LB
balance roundrobin
mode tcp
server APP1 10.31.24.231:8109 check
server APP2 10.31.24.232:8109 check

peers Mypeer
peer LB1 10.31.24.231:1024
peer LB2 10.31.24.232:1024
#--------------- HAProxy Status Page---------
listen stats
bind *:1978
mode http
stats enable
stats hide-version
stats realm Haproxy\ Statistics
stats uri /stats
stats auth admin:admin
#-------------End --------------------------

Keepalived Code in all Server with different priority for node MASTER and node BACKUP


Start Keepalived1

#--------------------------------------------------
vrrp_script chk_haproxy {
script “pidof haproxy”
interval 2
}
vrrp_instance VI_1 {
interface eth0
state MASTER
virtual_router_id 10
priority 150
vrrp_unicast_bind 10.100.3.131 #Internal IP of this node
vrrp_unicast_peer 10.100.3.132 #Internal IP of Backup node
virtual_ipaddress {
10.100.3.130
}
track_script {
chk_haproxy
}
}
#----------------------------------------------------

End Keepalived1

#----------------------------------------------------

Hi Ali,

If I get it right, you need to establish sticky sessions toward your app servers. In that case, you’ll need to adjust the following:

And add cookies that will ensure the stickiness. It should be something like this:

cookie SRVNAME insert
server APP1 10.31.24.231:8109 cookie a1 check
server APP2 10.31.24.232:8109 cookie a2 check

This will end up adding a cookie called “a1” or “a2”, with the server’s name in it after HAProxy restart, and new sessions should stick to one app server, or another.

Hi Sandmann,

Thank you very much,
I will share this with our vendor and waiting for their feedback/confirm back.
is there any other parameter we can use/test for sticky sessions to study it??
can i keep this post open for couple of days for testing the code purposes?

Thank you again…

Hi Ali,

For testing, I’d suggest the logs of the JBoss application, you should see the source addresses appear in the access logs, thus verifying the sessions stick to where they should. Other than that, you can add the “debug” option in the “global” section of your HAProxy configuration, so the logs will be more verbose.

Hi Sandmann,

Thank you very much,
noted, if any i will update you.

Regards,

Hello Sandmann,

i need to complete my configure to add Sticky session
so, as you see in my code above i have two frontend type ( http and tcp) if i want to add the sticky session for both what i have to add/edit my code in Frontend and Backend parameter??

Thank you

Hi Ali,

Did you try the http-only solution I posted, does it work?

Hi Sandmann,
I try to use http only but the vendor they have this project to work for both mode http and tcp.
I mean they try to test and have this scenario like:

if the request come from internet pass to our web server then pass to app

in the web server i shared with you code i am using http for port 880 and tcp for port 8443
in the app server i shared with you code i am using tcp only
in the app server they are trying to use application session ID (JSESSIONID)

I don’t mind having our code from the beginning.

Many thanks,

Hi Ali,

To create tcp sticky sessions, you could try to add the following to the tcp configuration:

stick-table type ip size 1m expire 1h
stick on src

This should stick incoming sessions based on source IP address. Note that this will not balance sessions that come from the same source address.

Please let me know if the above settings are working for you.

Hi Sandmann,
i will try to add below code after mode tcp line,

  • stick-table type ip size 1m expire 1h
  • stick on src

not balance= Weight >> we no need the Weight load balance … we are looking for load balance it have sticky session if any source IP address have a request/transaction and this source IP have disconnection and reconnect to the our application must be have at least same session with same destination to complete open transaction job.

I will try this and let you know for updating.

Many you very much.

Dear All,
please close this post and if any update i will open a new one.

thank you