DNS update for domain name in AJAX request

We have a DNS recovery setup with TTL 180 seconds. When the server fails, it updates the IP address in the A-host entries on the production server server. Our site is currently being updated using AJAX requests at intervals. When one of the servers fails, DNS is updated and fails, so if you are pinging a domain, it has the correct IP address. For some reason, although the browser and a long time after the TTL expires, the AJAX request still retains the old IP address assigned to the domain name (note that the page cannot be reloaded in the browser). I know that you are reading other questions that cannot force the DNS cache on the client. My question is: do any of you know another way or trick to accomplish this using javascript or AJAX? Thanks.

+6
source share
3 answers

Use two (or more) subdomains. eg. data1.example.com and data2.example.com, which correspond to physical servers.

However, for the cross-domain to work, you need to set document.domain , which allows you to communicate between domains:

 document.domain = "example.com"; 

Then you will need a script to crash between different servers manually. This is the only way I know and has been successful in many installations.

+2
source

I would not try to use this client side, I would use a network network balancer or some other virtual IP address on the server side.

Client-side requests require that your AJAX calls be made in such a way as to avoid browser protection or fully comply with cross-domain requests. If you are happy to make these changes, that is, some DNS JavaScript libraries, they can be used to resolve the DNS name to an IP address or CName, use the returned IP address or CName to configure your AJAX URL, and update the AJAX url using New DNS lookup when AJAX call fails.

I wouldn’t want to do it myself

+4
source

I would like to:

  • enter the ajax code to get to the primary.mycompany.com server, if this fails, go to secondary.mycompany.com, if this fails, return to the main one.
  • it is advisable to configure fault tolerance using the "service ip" from the failed node. There are good solutions for this.

For linux google, things like heartbeat and virtual ip and much more.

+1
source

Source: https://habr.com/ru/post/970341/


All Articles