DEV Community

Mike Faraponov for ScaleChamp

Posted on • Updated on

Failover Proxy

In case you ever think about failover proxy solution to migrate database from one server to another, consider failover proxy script, no need for HA Proxy at least for TCP based services:

#!/bin/bash

iptables -t nat -A PREROUTING -p tcp --dport $PORT -j DNAT --to-destination $TARGET:$PORT
iptables -t nat -A POSTROUTING -j MASQUERADE
Enter fullscreen mode Exit fullscreen mode

We at ScaleChamp utilising Failover Proxy to reduce downtime until DNS propagates to new master server.

While this solution do not provide session support and may require some retries for transactions on application level, it's still a simple and universal solution for many use cases.

P.S.
Do not forget to enable ip forwarding via sysctl. Also in order to archive atomical iptables update consider ip namespaces (netns).

Top comments (0)