Haproxy configuration setting to redirect request from 1 server to another

462 views
Skip to first unread message

Shivam Arora

unread,
Oct 5, 2021, 3:42:58 PM10/5/21
to Repo and Gerrit Discussion
Hi All,

I am trying to achieve a scenario in which if the Gerrit Master server is unavailable, then HA proxy should redirect the request which is coming to Master Server (which is down)should be directed to the replica (which is available at that time) as failover server.

Thanks,
Shivam

Björn Pedersen

unread,
Oct 6, 2021, 4:05:09 AM10/6/21
to Repo and Gerrit Discussion

Shivam Arora

unread,
Oct 7, 2021, 4:49:26 AM10/7/21
to Repo and Gerrit Discussion
Hi ,

Thanks for the suggestion. What we are trying to achieve is that we already have HAproxy and Gerrit server setup in place. So, we want to make the changes in the HAproxy in such a way it should perform round-robin. If the Production Gerrit server goes down then we can redirect the traffic from HAproxy to the Slave server automatically. Please suggest how can we achieve that we have made the below changes:

global
    log 127.0.0.1 local2 debug
    #daemon
    pidfile /var/run/haproxy.pid
    maxconn 16000
    #group gerrit

defaults
    #mode tcp
    retries 3
    timeout connect 5000ms
    timeout client 500000ms
    timeout server 500000ms


frontend ssh-in
    log 127.0.0.1 local2 debug
    bind *:29418 transparent
    mode tcp
    default_backend gerrit-ssh-servers
    option tcplog
option redispatch
balance roundrobin
    log-format "%ci:%cp [%t] %ft %b/%s %Tw/%Tc/%Tt %B %ts %ac/%fc/%bc/%sc/%rc %sq/%bq %bi:%bp"
email-alert mailers mymailers
   
frontend https
    log 127.0.0.1 local2 debug
    bind *:443 transparent
    option tcplog
    log-format "%ci:%cp [%t] %ft %b/%s %Tw/%Tc/%Tt %B %ts %ac/%fc/%bc/%sc/%rc %sq/%bq %bi:%bp"
    #mode http
    option forwardfor except 127.0.0.1
balance roundrobin
    #maxconn 5000
    # NOTE: users should connect over ssh to
    # <ip>:<ssh_port>, which should be the same as the
    # sshd.advertisedAddress parameter in the
    # 'gerrit.config' files
    default_backend gerrit-https-servers
email-alert mailers mymailers
    
backend gerrit-ssh-servers
    log 127.0.0.1 local2 debug
    option redispatch
balance roundrobin
    server gerritM1 XX.XXX.XX.XXX:29418 check 60s
    server gerritM2 XX.XXX.XX.XXX:29418 check
email-alert mailers mymailers
  
    source 0.0.0.0 usesrc clientip

backend gerrit-https-servers
    log 127.0.0.1 local2 debug
    option redispatch
balance roundrobin
    server gerritM1 XX.XXX.XX.XXX:443 check 60s
    server gerritM2 9XX.XXX.XX.XXX:443 check
    source 0.0.0.0 usesrc clientip
    email-alert mailers mymailers
    
#    http-request cache-use mycache if { path_beg /gerrit/plugins/events-log/  }
#    http-response cache-store mycache

listen status
    bind 0.0.0.0:1080
    mode http
    log global
    stats refresh 30s
    stats uri /haproxy?stats
    stats realm Private lands
    stats auth admin:password
    stats hide-version
Reply all
Reply to author
Forward
0 new messages