fabiolb / fabio

Consul Load-Balancing made simple
https://fabiolb.net
MIT License
7.27k stars 616 forks source link

Fabio config help with TCP #485

Open satishviswanathan opened 6 years ago

satishviswanathan commented 6 years ago

I'm new to Fabio and trying to set with following configuration but getting warning "syntax error: 'route add' invalid"

This is the command I've used in windows.

fabio-1.5.8-go1.10-windows_amd64.exe -registry.consul.addr 10.208.x.xx:8500 -proxy.addr :2302;proto=tcp Fabi log Fabio-log.txt

aaronhurt commented 6 years ago

What do you have in your KV at /fabio/config? The attached log looks like it is reading your command line parameters correctly. That only leaves the contents of the keystore unknown.

satishviswanathan commented 6 years ago

Are you referring to the KV store in consul? attaching the consul KV

aaronhurt commented 6 years ago

Yes, but what is inside the /fabio/config path.

satishviswanathan commented 6 years ago

I'm sorry would you be able to guide me where to find this?

aaronhurt commented 6 years ago

Navigate to fabio/config in your key store. Something like: http://10.208.6.98:8500/ui/#/dc1/kv/fabio/config/edit

satishviswanathan commented 6 years ago

When I access the url I'm getting this error.

consul-error

aaronhurt commented 6 years ago

Sorry, that was just an example ... you're actual path might be different depending on your datacenter name. Really I was just wanting to know if you had anything in your consul KV store under fabio/config. That's the default path for additional configuration and what I see being used in the log segment you attached.

            "Addr": "10.208.6.98:8500",
            "Scheme": "http",
            "Token": "",
            "KVPath": "/fabio/config",
            "NoRouteHTMLPath": "/fabio/noroute.html",
aaronhurt commented 6 years ago

Ohh, I think I may see the issue ... can you try leaving registry.consul.tagprefix as the default value? Also the default consul address is localhost (127.0.0.1) ... so you shouldn't need to pass registry.consul.addr as it looks like you have consul and fabio running on the same host.

satishviswanathan commented 6 years ago

Currently I was trying to get it working on my dev box which is Windows operating system and I have both Consul and Fabio running on the same box but I'm using my machine IP instead of localhost (127.0.0.1)

aaronhurt commented 6 years ago

You should be able to start consul agent -dev and fabio on the same machine without any other options and get a working example. The addition of proto=tcp is also telling fabio to run as a TCP load balancer vs an HTTP load balancer.

aaronhurt commented 6 years ago

Literally...

Window 1:

consul agent -dev

Window 2:

fabio
satishviswanathan commented 6 years ago

You are right we can start consul agent -dev but that will use localhost right, but I want to use my machine IP

satishviswanathan commented 6 years ago

Am I missing any configuration here, any help is highly appreciated

@magiconair

aaronhurt commented 6 years ago

@satishviswanathan I think you need to start with a known clean state and then add as you progress. The errors you are seeing don't make sense with a clean configuration.

satishviswanathan commented 6 years ago

I've now started clean

  1. Running consul as localhost
  2. Registered health check
  3. Registered TCP services
  4. Tried running Fabio with 2 different options with following results.

fabio-1.5.8-go1.10-windows_amd64.exe -proxy.addr :2302;proto=tcp Fabio-log1.txt

fabio-1.5.8-go1.10-windows_amd64.exe -proxy.addr :2302;proto=tcp -registry.consul.tagprefix urlprefix-:2302 Fabio-log2.txt

aaronhurt commented 6 years ago

Ahh, okay so ... what do your service registrations look like? What is your urlprefix tag on the service?

satishviswanathan commented 6 years ago

Thank you for your support.

This is the config I've used for service registration. Register-Service.txt

magiconair commented 6 years ago

You don’t need to set the registry.consul.urlprefix option. That is only necessary if the tags do not start with ‘urlprefix-‘

magiconair commented 6 years ago

Other than that this looks fine. Probably a good idea to print out the bad line as well. I’ll make a change.

satishviswanathan commented 6 years ago

When I remove the option registry.consul.urlprefix I get the following error.

syntax error: 'route add' invalid

magiconair commented 6 years ago

Yeah. I don’t know. I’ll update the error reporting. If you are comfortable building fabio from source you can do that as well.

https://github.com/fabiolb/fabio/blob/master/route/parse_new.go#L85

Then run ‘make’ or ‘go build’ to build fabio

satishviswanathan commented 6 years ago

Thank you. I added the log and identified that while registering the consul service I had a "space" in the name. eg: "Service Check 1" which was causing the issue.

Now when i start fabio i can see the routes getting added. But when i access from my client application I'm getting the following error.

-registry.consul.addr 10.203.xxx.xx:8500 -proxy.addr :2302;proto=tcp

[WARN] No route for 10.203.xxx.xx:2302/v1/kv/orleans/Order_Cluster1?recurse
magiconair commented 6 years ago

Try urlprefix-:2302 proto=tcp as tag when you register the service. Otherwise this is an HTTP service.

satishviswanathan commented 6 years ago

My consul service registration is having urlprefix

{
   "ID": "ServiceCheck1",
  "Name": "ServiceCheck1",
  "Notes": "serviceService 1",
  "Address": "10.208.x.xx",
  "Port": 11111,
  "Tags": ["urlprefix-:2302 proto=tcp"],
  "EnableTagOverride": false,
  "Check":{
    "DeregisterCriticalServiceAfter": "90m",
    "TCP": "10.208.x.xx:11111",
    "Interval": "10s"
  }
}

while running fabio do I need to get this same option too?

satishviswanathan commented 6 years ago
2018/04/20 10:57:20 [INFO] HTTP proxy listening on :2302
2018/04/20 10:57:20 [INFO] Access logging disabled
2018/04/20 10:57:20 [INFO] Using routing strategy "rnd"
2018/04/20 10:57:20 [INFO] Using route matching "prefix"
2018/04/20 10:57:20 [INFO] consul: Registered fabio as "fabio"
2018/04/20 10:57:20 [INFO] consul: Registered fabio with id "fabio-9998"
2018/04/20 10:57:20 [INFO] consul: Registered fabio with address "10.203.xxx.xx"
2018/04/20 10:57:20 [INFO] consul: Registered fabio with tags ""
2018/04/20 10:57:20 [INFO] consul: Registered fabio with health check to "http://[10.203.106.62]:9998/health"
2018/04/20 10:57:20 [INFO] Config updates
+ route add ServiceCheck1:2302 tcp://10.208.x.xx:11111

Now when I access 10.203.xxx.xx:2302 from my client application, I'm getting the following error No route for 10.203.xxx.xx:2302/v1/kv/orleans/Cluster1?recurse

magiconair commented 6 years ago

This is still starting the HTTP listener instead of the TCP.

2018/04/20 10:57:20 [INFO] HTTP proxy listening on :2302

This is most likely an issue with semicolon in the proxy.addr parameter. Unfortunate choice of separators :(

Try this:

fabio -proxy.addr ':2302;proto=tcp'

and you should see

2018/04/20 20:30:52 [INFO] TCP proxy listening on :2302
magiconair commented 6 years ago

@satishviswanathan Thanks for being patient and persistent!

satishviswanathan commented 6 years ago

I'm using the following command where I've mentioned the proto as tcp -registry.consul.addr 10.203.xxx.xx:8500 -proxy.addr :2302;proto=tcp

But still the log shows [INFO] TCP proxy listening on :2302

Not sure what I'm missing

satishviswanathan commented 6 years ago

Got it, my mistake I was missing the quotes 10.203.xxx.xx:8500 -proxy.addr : '2302;proto=tcp'

Now trying to get the client connected via fabio

satishviswanathan commented 6 years ago

Now when my client application try to connect to fabio @ port 2302, I'm getting the following error.

tcp: read tcp 10.xxx.x.xx:50690->10.xxx.x.xx:11111: wsarecv: An existing connection was forcibly closed by the remote host.

One of my service is running @ 10.xxx.x.xx:11111 and it is also listed in fabio routing table.

Please advice what can be done to resolve this issue.