Haproxy LBR Troubleshooting

I just completed this task and failed… Can someone please explain why?

Here is the final haproxy.cfg

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

Example configuration for a possible web application. See the

full configuration options online.

http://haproxy.1wt.eu/download/1.4/doc/configuration.txt

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

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

Global settings

#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
# # 1) configure syslog to accept network log events. This is done
# by adding the ‘-r’ option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2

chroot      /var/lib/haproxy
pidfile     /var/run/haproxy.pid
maxconn     4000
user        haproxy
group       haproxy
daemon

# turn on stats unix socket
stats socket /var/lib/haproxy/stats

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

common defaults that all the ‘listen’ and ‘backend’ sections will

use if not designated in their block

#---------------------------------------------------------------------
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

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

main frontend which proxys to the backends

#---------------------------------------------------------------------
frontend main *:5000
acl url_static path_beg -i /static /images /javascript /stylesheets
acl url_static path_end -i .jpg .gif .png .css .js

use_backend static          if url_static
default_backend             app

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

static backend for serving up images, stylesheets and such

#---------------------------------------------------------------------
backend static
balance roundrobin
server static 127.0.0.1:4331 check

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

round robin balancing between the various backends

#---------------------------------------------------------------------
backend app
balance roundrobin
server app1 127.0.0.1:5001 check
server app2 127.0.0.1:5002 check
server app3 127.0.0.1:5003 check
server app4 127.0.0.1:5004 check

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

main frontend which proxys to the backends

#---------------------------------------------------------------------
frontend app_on_http_port_80 *:80
default_backend app_backend
#---------------------------------------------------------------------

round robin balancing between the various backends

#---------------------------------------------------------------------
backend app_backend
balance roundrobin
server stapp01 172.16.238.10:80 check
server stapp02 172.16.238.11:80 check
server stapp03 172.16.238.12:80 check

HAProxy was also successfully started:

And listening on port 80 - confirmed with

ss -nltp

@aina_dipupo

What is your email address or KKE username ?

haproxy -c -f /path/to/haproxy.cfg this command help you check your config is ok or not , and tell you where is likely the problem to be.
Hope it helps !

4 Likes

Hi @aina_dipupo,

HAProxy may have started but that doesn’t confirm that it’s configured properly, or that all required dependencies are, for this specific task. For example, all of your app_backend hosts route to port 80 but I don’t recall those app servers ever being configured to run on port 80 on Kode Kloud.

You can easily validate these types of tasks by using curl against every service in the chain (sometimes apache + nginx + haproxy) to determine exactly where the problem is. For example, if you can’t successfully ‘curl 172.16.238.10:80’ you’ll know your haproxy configuration is invalid.

Generally speaking, I always work backwards for these types of tasks - I verify that apache is running, and fix it if it isn’t, before looking at the nginx and/or haproxy config.

Hope this helps,
Peter

1 Like

hi,
not sure if I follow you. I am unable to find any typo in this section?
please advise.


@peterwhite @Inderpreet @akshayyw @Salim

thanks guys for pointing out to typo hint. fixed my issue.

2 Likes

What solved your issue? Did you use this command for checking syntax errors in the file?

haproxy -c -f haproxy.cfg
1 Like
  1. haproxy -c -f /etc/haproxy/haproxy.cfg
  2. timeout checking 10s —> timeout check 10s
  3. systemctl start haproxy.service
1 Like

Hi Akshay,
The status of the haproxy service was refering to timeout section of client, connect and server. there was the typo of client in the configuration section. I just corrected the same.
Again restarted the haproxy services. The services was up and running.
I didn’t try below steps given by you.
Thanks
Swaroop

1 Like

In haproxy.cfg file add below content after global and default section:
frontend http_front
bind *:80
stats uri /haproxy?stats
default_backend http_back

backend http_back
balance roundrobin
server stapp01 172.16.238.10:8080 check <<— Check the port of app server on which httpd is configrured and add that here, in my case it was 8080
server stapp02 172.16.238.11:8080 check
server stapp03 172.16.238.12:8080 check

Hi @Inderpreet, @peterwhite and other geeks…

Although i am able to get the desired output page, my task status says Failed.

Could any of you please guide me did i really do it wrong.

The below snip gave the output page as expected.
HAproxy_success

The task status says failed as per below snip.
HAproxy_failed
All App servers were listening for httpd on 8082 and i configured same for app servers in haproxy file and port 80 for lbr server.

Seeking your guidance.

Thanks,
Yogendra

Today i troubleshooted the issue its just a simple misspelled issue, clearly understand the error in cmd service haproxy status you will find the issue.

What is the clue?

Can you please tell!

What was the command to enter into haproxy …???

  1. haproxy -c -f /etc/haproxy/haproxy.cfg
  2. timeout checking 10s —> timeout check 10s
  3. systemctl start haproxy.service

No its not working …i have donee…

I juts finished this task, I think they just want you to make sure that HAPROXY is running, nothing more is needed at this stage, I finished the lab and I passed.

I can see that the error is not the same for all us. But is similar. I also finished this task successfully.

Main command to find the error:

haproxy -c -f /etc/haproxy/haproxy.cfg

Next, you resolve the error and check again the haproxy.cfg

Finally, start haproxy.

Exactly! The only task you have to perform in the “Haproxy LBR Troubleshooting” activity is to check for a typo in the config file /etc/haproxy/haproxy.cfg. The command “haproxy -c -f /etc/haproxy/haproxy.cfg” will show information about where to find the typo in the config file, then you go and correct it using your preferred text editor, in my case “vi”.

Note that the error will change anytime you choose to try the activity later, for example the error can be a typo in the timeout parameters in the config file, for instance “timeout checking” instead of “timeout check” or a keyword that has been commented like #backend app, in which case the output of “haproxy -c -f /etc/haproxy/haproxy.cfg” will say something like: backend app cannot be found. So you edit the config file by finding and uncommenting “#backend app” to “backend app”. Then check the validity of the config file again with “haproxy -c -f /etc/haproxy/haproxy.cfg”, restart the service and check the status of the service to see if its running(Active).

1 Like

I was too stuck, but reading your suggestions on checking the error message, and the logs from
haproxy -c -f haproxy.cfg
I was able to troubleshoot it.
Thank you people!