app loadbalancing

Hello,
i have two servers, server a 192.168.1.1 , server 192.168.1.2
i want the client when request port 80 on ip 192.168.1.3 (Mikrotik Interface) connected to eth1 forward the request to server a if it’s down forward it to server b.
so how i can do it ?
thanks.

Hello,
Any replay ?

Not sure of anything in Router OS that will do it. It appears some scripting may make it happen. You may want to look at a product like HAProxy or Nginx that have significantly better support for the various features required to do load balancing correctly.

You can cluster HAProxy or Nginx, you assign a floating IP to the load balancer and it manages which of the 2 are active. Alternatively you can deploy 2 instances of whichever you select and use DNS load balancing (2 DNS entries) to manage the fail-over on the Internet side should 1 of the proxies fail. The DNS method may cause a delay when accessing a load balanced resource for some clients.

An advantage is the load balances can stay at 1 or 2 instances while you add as many web servers as needed to handle the load.

http://www.haproxy.org
https://nginx.org/

LE: Disregard the text below. Bad idea/it won’t work.

You can put your servers on a separate link with different subnet and assign 2 IPs to each, so you will need to reach e.g.
192.168.2.1 via 10.0.0.1.
192.168.3.1 via 10.0.0.2.
In this case you would need to add a static route, which has the option to check the gateway via ping.
This will also mean that all rules, including dst-nat will go down if the route is down (no ping received from the GW).
Then add 2 dst-nat rules to your router for dest 192.168.1.3, one to 192.168.2.1, one to 192.168.3.1.
These will be evaluated in order, so as long as 10.0.0.1 is up, the first rule will be used.
If it will be down, the second rule will kick in, forwarding to the second server.

Didn’t know DSTNAT rules would go down if you a static route goes down by check-gateway.

Hmmm, you are right, since there is no outgoing interface matching.

I think I just had a bad idea :confused:

but something like this could work:

if1 (10.0.0.1) ------- server1 (10.0.0.2) - virtual (192.168.2.1)
if2 (10.0.1.1) ------- server2 (10.0.1.2) - virtual (192.168.2.1)

Check gateway by ping on 10.0.0.2 and 10.0.1.2.
route 192.168.2.1 via 10.0.0.2 metric 10
route 192.168.2.1 via 10.0.1.2 metric 20
dst-nat dst-addr=192.168.1.3 to=192.168.2.1

hello,
I didn’t understand coccrectly what I have to do… could u please show me the idea as commands ?
thanks.